44using CS2MenuManager . API . Class ;
55using CS2MenuManager . API . Enum ;
66using CS2MenuManager . API . Interface ;
7+ using System . Drawing ;
78using System . Text ;
89using static CounterStrikeSharp . API . Core . Listeners ;
910using static CS2MenuManager . API . Class . Buttons ;
@@ -28,7 +29,12 @@ static ScreenMenu()
2829 /// <summary>
2930 /// Gets or sets the color of the text.
3031 /// </summary>
31- public string TextColor { get ; set ; } = Config . ScreenMenu . TextColor ;
32+ public Color TextColor { get ; set ; } = Config . ScreenMenu . TextColor ;
33+
34+ /// <summary>
35+ /// Gets or sets the color of the disabled text.
36+ /// </summary>
37+ public Color DisabledTextColor { get ; set ; } = Config . ScreenMenu . DisabledTextColor ;
3238
3339 /// <summary>
3440 /// Gets or sets a value indicating whether the menu has a background.
@@ -119,17 +125,10 @@ public class ScreenMenuInstance : BaseMenuInstance
119125 /// </summary>
120126 public override int NumPerPage => ( ( ScreenMenu ) Menu ) . ShowResolutionsOption ? 6 : 7 ;
121127
122- /// <summary>
123- /// Gets or sets the previous button state.
124- /// </summary>
125- public PlayerButtons OldButton ;
126-
127- /// <summary>
128- /// Gets or sets the world text entity used to display the menu.
129- /// </summary>
130- public CPointWorldText ? WorldText ;
131-
132- internal CCSGOViewModel ? OldViewModel ;
128+ private PlayerButtons OldButton ;
129+ private CPointWorldText ? WorldText ;
130+ private CPointWorldText ? WorldTextDisabled ;
131+ private CCSGOViewModel ? OldViewModel ;
133132
134133 /// <summary>
135134 /// Initializes a new instance of the <see cref="ScreenMenuInstance"/> class.
@@ -165,31 +164,17 @@ public override void Display()
165164 if ( Menu is not ScreenMenu screenMenu )
166165 return ;
167166
168- StringBuilder builder = new ( ) ;
169- int totalPages = ( int ) Math . Ceiling ( ( double ) Menu . ItemOptions . Count / MenuItemsPerPage ) ;
170- int currentPage = Page + 1 ;
167+ StringBuilder noneOptions = new ( ) ;
168+ StringBuilder disabledOptions = new ( ) ;
171169
172- builder . AppendLine ( " " ) ;
173- builder . AppendLine ( $ "{ Menu . Title } ({ currentPage } /{ totalPages } )") ;
174- builder . AppendLine ( " " ) ;
170+ disabledOptions . AppendLine ( Menu . Title ) ;
171+ noneOptions . AppendLine ( ) ;
175172
176- List < ( string Text , int GlobalIndex ) > visibleOptions = GetVisibleOptions ( ) ;
173+ List < ( string Text , int GlobalIndex , bool disabled ) > visibleOptions = GetVisibleOptions ( ) ;
177174
178- int dynamicStartIndex = - 1 ;
179175 for ( int i = 0 ; i < visibleOptions . Count ; i ++ )
180176 {
181- ( _ , int globalIndex ) = visibleOptions [ i ] ;
182-
183- if ( globalIndex < 0 && dynamicStartIndex == - 1 )
184- dynamicStartIndex = i ;
185- }
186-
187- for ( int i = 0 ; i < visibleOptions . Count ; i ++ )
188- {
189- if ( i == dynamicStartIndex )
190- builder . AppendLine ( " " ) ;
191-
192- ( string text , int _ ) = visibleOptions [ i ] ;
177+ ( string text , int _ , bool disabled ) = visibleOptions [ i ] ;
193178
194179 string displayLine = screenMenu . MenuType switch
195180 {
@@ -198,23 +183,43 @@ public override void Display()
198183 _ => string . Empty
199184 } ;
200185
201- builder . AppendLine ( displayLine ) ;
186+ if ( disabled )
187+ {
188+ noneOptions . AppendLine ( ) ;
189+ disabledOptions . AppendLine ( displayLine ) ;
190+ }
191+ else
192+ {
193+ noneOptions . AppendLine ( displayLine ) ;
194+ disabledOptions . AppendLine ( ) ;
195+ }
202196 }
203197
198+ noneOptions . AppendLine ( ) ;
199+ disabledOptions . AppendLine ( ) ;
200+
204201 if ( screenMenu . MenuType != MenuType . KeyPress )
205202 {
206- builder . AppendLine ( " " ) ;
207- builder . AppendLine ( Player . Localizer ( "ScrollKey" , screenMenu . ScrollUpKey , screenMenu . ScrollDownKey ) ) ;
208- builder . AppendLine ( Player . Localizer ( "SelectKey " , screenMenu . SelectKey ) ) ;
209- builder . AppendLine ( " " ) ;
203+ disabledOptions . AppendLine ( ) ;
204+ disabledOptions . AppendLine ( ) ;
205+ noneOptions . AppendLine ( Player . Localizer ( "ScrollKey " , screenMenu . ScrollUpKey , screenMenu . ScrollDownKey ) ) ;
206+ noneOptions . AppendLine ( Player . Localizer ( "SelectKey" , screenMenu . SelectKey ) ) ;
210207 }
211208
212- if ( WorldText == null || ! WorldText . IsValid )
213- WorldText = CreateWorldText ( builder . ToString ( ) , screenMenu . Size , screenMenu . TextColor , screenMenu . Font , screenMenu . Background , screenMenu . BackgroundHeight , screenMenu . BackgroundWidth ) ;
209+ UpdateWorldText ( ref WorldText , noneOptions . ToString ( ) , screenMenu , screenMenu . TextColor ) ;
210+ UpdateWorldText ( ref WorldTextDisabled , disabledOptions . ToString ( ) , screenMenu , screenMenu . DisabledTextColor ) ;
211+ }
212+
213+ private static void UpdateWorldText ( ref CPointWorldText ? worldText , string message , ScreenMenu screenMenu , Color color )
214+ {
215+ if ( worldText == null || ! worldText . IsValid )
216+ {
217+ worldText = CreateWorldText ( message , screenMenu . Size , color , screenMenu . Font , false , screenMenu . BackgroundHeight , screenMenu . BackgroundWidth ) ;
218+ }
214219 else
215220 {
216- WorldText . MessageText = builder . ToString ( ) ;
217- Utilities . SetStateChanged ( WorldText , "CPointWorldText" , "m_messageText" ) ;
221+ worldText . MessageText = message ;
222+ Utilities . SetStateChanged ( worldText , "CPointWorldText" , "m_messageText" ) ;
218223 }
219224 }
220225
@@ -229,6 +234,7 @@ public override void Close()
229234 Menu . Plugin . RemoveListener < OnEntityDeleted > ( OnEntityDeleted ) ;
230235
231236 if ( WorldText != null && WorldText . IsValid ) WorldText . Remove ( ) ;
237+ if ( WorldTextDisabled != null && WorldTextDisabled . IsValid ) WorldTextDisabled . Remove ( ) ;
232238 if ( ( ( ScreenMenu ) Menu ) . FreezePlayer ) Player . Unfreeze ( ) ;
233239
234240 if ( ! string . IsNullOrEmpty ( Config . Sound . Exit ) )
@@ -256,24 +262,31 @@ private void OnTick()
256262 OldButton = button ;
257263 }
258264
259- if ( WorldText != null )
260- {
261- CCSGOViewModel ? viewModel = Player . EnsureCustomView ( ) ;
262- if ( viewModel == null ) { Close ( ) ; return ; }
263- if ( OldViewModel == viewModel ) return ;
265+ CCSGOViewModel ? viewModel = Player . EnsureCustomView ( ) ;
266+ if ( viewModel == null ) { Close ( ) ; return ; }
267+ if ( OldViewModel == viewModel ) return ;
268+
269+ VectorData ? vectorData = Player . FindVectorData ( ) ;
270+ if ( vectorData == null ) { Close ( ) ; return ; }
264271
265- VectorData ? vectorData = Player . FindVectorData ( ) ;
266- if ( vectorData == null ) { Close ( ) ; return ; }
272+ OldViewModel = viewModel ;
267273
268- OldViewModel = viewModel ;
274+ if ( WorldText != null )
275+ {
269276 WorldText . Teleport ( vectorData . Value . Position , vectorData . Value . Angle , null ) ;
270277 WorldText . AcceptInput ( "SetParent" , viewModel , null , "!activator" ) ;
271278 }
279+
280+ if ( WorldTextDisabled != null )
281+ {
282+ WorldTextDisabled . Teleport ( vectorData . Value . Position , vectorData . Value . Angle , null ) ;
283+ WorldTextDisabled . AcceptInput ( "SetParent" , viewModel , null , "!activator" ) ;
284+ }
272285 }
273286
274287 private void ScrollDown ( )
275288 {
276- List < ( string Text , int GlobalIndex ) > visibleOptions = GetVisibleOptions ( ) ;
289+ List < ( string Text , int GlobalIndex , bool disabled ) > visibleOptions = GetVisibleOptions ( ) ;
277290 if ( visibleOptions . Count == 0 )
278291 return ;
279292
@@ -286,7 +299,7 @@ private void ScrollDown()
286299
287300 private void ScrollUp ( )
288301 {
289- List < ( string Text , int GlobalIndex ) > visibleOptions = GetVisibleOptions ( ) ;
302+ List < ( string Text , int GlobalIndex , bool disabled ) > visibleOptions = GetVisibleOptions ( ) ;
290303 if ( visibleOptions . Count == 0 )
291304 return ;
292305
@@ -328,11 +341,11 @@ public override void OnKeyPress(CCSPlayerController player, int key)
328341
329342 private void Choose ( )
330343 {
331- List < ( string Text , int GlobalIndex ) > visibleOptions = GetVisibleOptions ( ) ;
344+ List < ( string Text , int GlobalIndex , bool disabled ) > visibleOptions = GetVisibleOptions ( ) ;
332345 if ( CurrentChoiceIndex < 0 || CurrentChoiceIndex >= visibleOptions . Count )
333346 return ;
334347
335- ( string _ , int globalIndex ) = visibleOptions [ CurrentChoiceIndex ] ;
348+ ( string _ , int globalIndex , _ ) = visibleOptions [ CurrentChoiceIndex ] ;
336349 switch ( globalIndex )
337350 {
338351 case - 1 : NextPage ( ) ; return ;
@@ -366,9 +379,9 @@ private void HandleOption(int globalIndex)
366379 Close ( ) ;
367380 }
368381
369- private List < ( string Text , int GlobalIndex ) > GetVisibleOptions ( )
382+ private List < ( string Text , int GlobalIndex , bool disabled ) > GetVisibleOptions ( )
370383 {
371- List < ( string Text , int GlobalIndex ) > visible = [ ] ;
384+ List < ( string Text , int GlobalIndex , bool disabled ) > visible = [ ] ;
372385 int totalItems = Menu . ItemOptions . Count ;
373386 int start = CurrentOffset ;
374387 int end = Math . Min ( start + NumPerPage , totalItems ) ;
@@ -377,36 +390,47 @@ private void HandleOption(int globalIndex)
377390 for ( int i = start ; i < end ; i ++ )
378391 {
379392 ItemOption option = Menu . ItemOptions [ i ] ;
393+
380394 string text = option . DisableOption switch
381395 {
382396 DisableOption . None or DisableOption . DisableShowNumber =>
383397 $ "{ displayNumber } . { option . Text } ",
384- DisableOption . DisableHideNumber => $ " { option . Text } " ,
398+ DisableOption . DisableHideNumber => option . Text ,
385399 _ => string . Empty
386400 } ;
387401
402+ visible . Add ( ( text , i , option . DisableOption != DisableOption . None ) ) ;
388403 displayNumber ++ ;
389- visible . Add ( ( text , i ) ) ;
390404 }
391405
392- if ( ( ( ScreenMenu ) Menu ) . ShowResolutionsOption ) visible . Add ( ( $ "{ displayNumber ++ } . { Player . Localizer ( "SelectResolution" ) } \n ", - 4 ) ) ;
393- if ( HasPrevButton ) visible . Add ( ( $ "8. { Player . Localizer ( "Prev" ) } ", - 2 ) ) ;
394- if ( HasNextButton ) visible . Add ( ( $ "9. { Player . Localizer ( "Next" ) } ", - 1 ) ) ;
395- if ( HasExitButton ) visible . Add ( ( $ "0. { Player . Localizer ( "Exit" ) } ", - 3 ) ) ;
406+ if ( visible . Count > 0 )
407+ {
408+ visible . Add ( ( "" , - 99 , true ) ) ;
409+ }
410+
411+ if ( ( ( ScreenMenu ) Menu ) . ShowResolutionsOption )
412+ visible . Add ( ( $ "7. { Player . Localizer ( "SelectResolution" ) } ", - 4 , false ) ) ;
413+ if ( HasPrevButton )
414+ visible . Add ( ( $ "8. { Player . Localizer ( "Prev" ) } ", - 2 , false ) ) ;
415+ if ( HasNextButton )
416+ visible . Add ( ( $ "9. { Player . Localizer ( "Next" ) } ", - 1 , false ) ) ;
417+ if ( HasExitButton )
418+ visible . Add ( ( $ "0. { Player . Localizer ( "Exit" ) } ", - 3 , false ) ) ;
396419
397420 return visible ;
398421 }
399422
400423 private void OnCheckTransmit ( CCheckTransmitInfoList infoList )
401424 {
402- if ( WorldText == null ) return ;
425+ if ( WorldText == null || WorldTextDisabled == null ) return ;
403426
404427 foreach ( ( CCheckTransmitInfo info , CCSPlayerController ? player ) in infoList )
405428 {
406429 if ( player == null || player == Player )
407430 continue ;
408431
409432 info . TransmitEntities . Remove ( WorldText ) ;
433+ info . TransmitEntities . Remove ( WorldTextDisabled ) ;
410434 }
411435 }
412436
0 commit comments