@@ -75,6 +75,16 @@ public class ScreenMenu(string title, BasePlugin plugin) : BaseMenu(title, plugi
7575 /// </summary>
7676 public string SelectKey { get ; set ; } = Config . Buttons . Select ;
7777
78+ /// <summary>
79+ /// Defines the types of menus.
80+ /// </summary>
81+ public MenuType MenuType { get ; set ; } = Config . ScreenMenu . MenuType switch
82+ {
83+ string text when text . Length > 0 && char . ToLower ( text [ 0 ] ) == 's' => MenuType . Scrollable ,
84+ string text when text . Length > 0 && char . ToLower ( text [ 0 ] ) == 'k' => MenuType . KeyPress ,
85+ _ => MenuType . Both
86+ } ;
87+
7888 /// <summary>
7989 /// Displays the menu to the specified player for a specified duration.
8090 /// </summary>
@@ -126,17 +136,20 @@ public ScreenMenuInstance(CCSPlayerController player, IMenu menu) : base(player,
126136 if ( Menu is not ScreenMenu screenMenu )
127137 return ;
128138
139+ if ( screenMenu . MenuType != MenuType . KeyPress )
140+ {
141+ Buttons = new Dictionary < string , Action > ( )
142+ {
143+ { screenMenu . ScrollUpKey , ScrollUp } ,
144+ { screenMenu . ScrollDownKey , ScrollDown } ,
145+ { screenMenu . SelectKey , Choose } ,
146+ } ;
147+ }
148+
129149 Menu . Plugin . RegisterListener < OnTick > ( OnTick ) ;
130150 Menu . Plugin . RegisterListener < CheckTransmit > ( OnCheckTransmit ) ;
131151 Menu . Plugin . RegisterListener < OnEntityDeleted > ( OnEntityDeleted ) ;
132152 if ( screenMenu . FreezePlayer ) Player . Freeze ( ) ;
133-
134- Buttons = new Dictionary < string , Action > ( )
135- {
136- { screenMenu . ScrollUpKey , ScrollUp } ,
137- { screenMenu . ScrollDownKey , ScrollDown } ,
138- { screenMenu . SelectKey , Choose } ,
139- } ;
140153 }
141154
142155 /// <summary>
@@ -172,14 +185,24 @@ public override void Display()
172185 builder . AppendLine ( " " ) ;
173186
174187 ( string text , int _ ) = visibleOptions [ i ] ;
175- string displayLine = ( i == CurrentChoiceIndex ) ? $ "> { text } " : $ " { text } ";
188+
189+ string displayLine = screenMenu . MenuType switch
190+ {
191+ MenuType . KeyPress => text ,
192+ MenuType . Scrollable or MenuType . Both => ( i == CurrentChoiceIndex ) ? $ "> { text } " : $ " { text } ",
193+ _ => string . Empty
194+ } ;
195+
176196 builder . AppendLine ( displayLine ) ;
177197 }
178198
179- builder . AppendLine ( " " ) ;
180- builder . AppendLine ( Player . Localizer ( "ScrollKey" , screenMenu . ScrollUpKey , screenMenu . ScrollDownKey ) ) ;
181- builder . AppendLine ( Player . Localizer ( "SelectKey" , screenMenu . SelectKey ) ) ;
182- builder . AppendLine ( " " ) ;
199+ if ( screenMenu . MenuType != MenuType . KeyPress )
200+ {
201+ builder . AppendLine ( " " ) ;
202+ builder . AppendLine ( Player . Localizer ( "ScrollKey" , screenMenu . ScrollUpKey , screenMenu . ScrollDownKey ) ) ;
203+ builder . AppendLine ( Player . Localizer ( "SelectKey" , screenMenu . SelectKey ) ) ;
204+ builder . AppendLine ( " " ) ;
205+ }
183206
184207 if ( WorldText == null || ! WorldText . IsValid )
185208 WorldText = CreateWorldText ( builder . ToString ( ) , screenMenu . Size , screenMenu . TextColor , screenMenu . Font , screenMenu . Background , screenMenu . BackgroundHeight , screenMenu . BackgroundWidth ) ;
@@ -201,29 +224,32 @@ public override void Close()
201224 Menu . Plugin . RemoveListener < OnEntityDeleted > ( OnEntityDeleted ) ;
202225
203226 if ( WorldText != null && WorldText . IsValid ) WorldText . Remove ( ) ;
204- if ( ( ( ScreenMenu ) Menu ) . FreezePlayer ) Player . Freeze ( ) ;
227+ if ( ( ( ScreenMenu ) Menu ) . FreezePlayer ) Player . Unfreeze ( ) ;
205228
206229 if ( ! string . IsNullOrEmpty ( Config . Sound . Exit ) )
207230 Player . ExecuteClientCommand ( $ "play { Config . Sound . Exit } ") ;
208231 }
209232
210233 private void OnTick ( )
211234 {
212- PlayerButtons button = Player . Buttons ;
213-
214- foreach ( KeyValuePair < string , Action > kvp in Buttons )
235+ if ( ( ( ScreenMenu ) Menu ) . MenuType != MenuType . KeyPress )
215236 {
216- if ( ButtonMapping . TryGetValue ( kvp . Key , out PlayerButtons buttonMappingButton ) )
237+ PlayerButtons button = Player . Buttons ;
238+
239+ foreach ( KeyValuePair < string , Action > kvp in Buttons )
217240 {
218- if ( ( button & buttonMappingButton ) == 0 && ( OldButton & buttonMappingButton ) != 0 )
241+ if ( ButtonMapping . TryGetValue ( kvp . Key , out PlayerButtons buttonMappingButton ) )
219242 {
220- kvp . Value . Invoke ( ) ;
221- break ;
243+ if ( ( button & buttonMappingButton ) == 0 && ( OldButton & buttonMappingButton ) != 0 )
244+ {
245+ kvp . Value . Invoke ( ) ;
246+ break ;
247+ }
222248 }
223249 }
224- }
225250
226- OldButton = button ;
251+ OldButton = button ;
252+ }
227253
228254 if ( WorldText != null )
229255 {
@@ -266,6 +292,35 @@ private void ScrollUp()
266292 Player . ExecuteClientCommand ( $ "play { Config . Sound . ScrollUp } ") ;
267293 }
268294
295+ /// <summary>
296+ /// Handles key press events for the menu.
297+ /// </summary>
298+ /// <param name="player">The player who pressed the key.</param>
299+ /// <param name="key">The key that was pressed.</param>
300+ public override void OnKeyPress ( CCSPlayerController player , int key )
301+ {
302+ switch ( key )
303+ {
304+ case 7 when ( ( ScreenMenu ) Menu ) . ShowResolutionsOption :
305+ Close ( ) ;
306+ ResolutionMenu ( Player , Menu . Plugin , Menu ) . Display ( Player , 0 ) ;
307+ break ;
308+ case 8 when HasPrevButton :
309+ if ( Page > 0 ) PrevPage ( ) ;
310+ else PrevSubMenu ( ) ;
311+ break ;
312+ case 9 when HasNextButton :
313+ NextPage ( ) ;
314+ break ;
315+ case 0 when HasExitButton :
316+ Close ( ) ;
317+ break ;
318+ default :
319+ HandleMenuItemSelection ( key ) ;
320+ break ;
321+ }
322+ }
323+
269324 private void Choose ( )
270325 {
271326 List < ( string Text , int GlobalIndex ) > visibleOptions = GetVisibleOptions ( ) ;
@@ -283,22 +338,27 @@ private void Choose()
283338 case - 3 : Close ( ) ; return ;
284339 case - 4 : Close ( ) ; ResolutionMenu ( Player , Menu . Plugin , Menu ) . Display ( Player , 0 ) ; return ;
285340 default :
286- ItemOption option = Menu . ItemOptions [ globalIndex ] ;
341+ HandleOption ( globalIndex ) ;
342+ break ;
343+ }
344+ }
287345
288- if ( option . DisableOption != DisableOption . None )
289- {
290- Player . PrintToChat ( Player . Localizer ( "WarnDisabledItem" ) . ReplaceColorTags ( ) ) ;
291- return ;
292- }
346+ private void HandleOption ( int globalIndex )
347+ {
348+ ItemOption option = Menu . ItemOptions [ globalIndex ] ;
293349
294- option . OnSelect ? . Invoke ( Player , option ) ;
350+ if ( option . DisableOption != DisableOption . None )
351+ {
352+ Player . PrintToChat ( Player . Localizer ( "WarnDisabledItem" ) . ReplaceColorTags ( ) ) ;
353+ return ;
354+ }
295355
296- if ( ! string . IsNullOrEmpty ( Config . Sound . Select ) )
297- Player . ExecuteClientCommand ( $ "play { Config . Sound . Select } ") ;
356+ option . OnSelect ? . Invoke ( Player , option ) ;
298357
299- Close ( ) ;
300- break ;
301- }
358+ if ( ! string . IsNullOrEmpty ( Config . Sound . Select ) )
359+ Player . ExecuteClientCommand ( $ "play { Config . Sound . Select } ") ;
360+
361+ Close ( ) ;
302362 }
303363
304364 private List < ( string Text , int GlobalIndex ) > GetVisibleOptions ( )
@@ -324,7 +384,7 @@ private void Choose()
324384 visible . Add ( ( text , i ) ) ;
325385 }
326386
327- if ( ( ( ScreenMenu ) Menu ) . ShowResolutionsOption ) visible . Add ( ( $ "! { displayNumber ++ } . { Player . Localizer ( "SelectResolution" ) } \n ", - 4 ) ) ;
387+ if ( ( ( ScreenMenu ) Menu ) . ShowResolutionsOption ) visible . Add ( ( $ "{ displayNumber ++ } . { Player . Localizer ( "SelectResolution" ) } \n ", - 4 ) ) ;
328388 if ( HasPrevButton ) visible . Add ( ( $ "8. { Player . Localizer ( "Prev" ) } ", - 2 ) ) ;
329389 if ( HasNextButton ) visible . Add ( ( $ "9. { Player . Localizer ( "Next" ) } ", - 1 ) ) ;
330390 if ( HasExitButton ) visible . Add ( ( $ "0. { Player . Localizer ( "Exit" ) } ", - 3 ) ) ;
@@ -351,11 +411,12 @@ private void OnEntityDeleted(CEntityInstance entity)
351411 Close ( ) ;
352412 }
353413
354- private static ScreenMenu ResolutionMenu ( CCSPlayerController player , BasePlugin plugin , IMenu prevMenu )
414+ private ScreenMenu ResolutionMenu ( CCSPlayerController player , BasePlugin plugin , IMenu prevMenu )
355415 {
356416 ScreenMenu menu = new ( player . Localizer ( "SelectResolution" ) , plugin )
357417 {
358418 ShowResolutionsOption = false ,
419+ MenuType = ( ( ScreenMenu ) Menu ) . MenuType
359420 } ;
360421
361422 foreach ( KeyValuePair < string , Resolution > resolution in Config . Resolutions )
0 commit comments