@@ -116,9 +116,16 @@ void writeLine(string line = "", bool background = false)
116116 }
117117
118118 bool showExitButton = focusedMenu . Parents . Where ( x => ! x . PlayerCanClose ) . Any ( ) == false ;
119- bool showBackButton = showExitButton
120- ? itemsStart == 0 && focusedMenu . PlayerCanClose && focusedMenu . Parent is not null
121- : itemsStart == 0 && focusedMenu . PlayerCanClose ;
119+ bool showBackButton = focusedMenu switch
120+ {
121+ { CurrentPage : not 0 } => false ,
122+ { NavigateBack : not null } => true ,
123+ _ => showExitButton switch
124+ {
125+ true => focusedMenu . PlayerCanClose && focusedMenu . Parent is not null ,
126+ false => focusedMenu . PlayerCanClose ,
127+ } ,
128+ } ;
122129 bool showPrevButton = itemsStart > 0 ;
123130 bool showNextButton = itemsStart + itemsInPage < focusedMenu . Items . Count ;
124131 bool showNavigation = showBackButton || showPrevButton || showNextButton ;
@@ -169,11 +176,20 @@ void ISampleMenu.HandleKey(CCSPlayerController player, ConsoleKeyInfo key)
169176 var itemsStart = focusedMenu . CurrentPage * ItemsPerPage ;
170177 var itemsInPage = Math . Min ( focusedMenu . Items . Count , itemsStart + ItemsPerPage ) - itemsStart ;
171178
172- bool showBackButton = itemsStart == 0 && focusedMenu . PlayerCanClose ;
179+ bool showExitButton = focusedMenu . Parents . Where ( x => ! x . PlayerCanClose ) . Any ( ) == false ;
180+ bool showBackButton = focusedMenu switch
181+ {
182+ { CurrentPage : not 0 } => false ,
183+ { NavigateBack : not null } => true ,
184+ _ => showExitButton switch
185+ {
186+ true => focusedMenu . PlayerCanClose && focusedMenu . Parent is not null ,
187+ false => focusedMenu . PlayerCanClose ,
188+ } ,
189+ } ;
173190 bool showPrevButton = itemsStart > 0 ;
174191 bool showNextButton = itemsStart + itemsInPage < focusedMenu . Items . Count ;
175192 bool showNavigation = showBackButton || showPrevButton || showNextButton ;
176- bool showExitButton = focusedMenu . Parents . Where ( x => ! x . PlayerCanClose ) . Any ( ) == false ;
177193
178194 switch ( key . Key )
179195 {
@@ -186,7 +202,12 @@ void ISampleMenu.HandleKey(CCSPlayerController player, ConsoleKeyInfo key)
186202 if ( showPrevButton )
187203 focusedMenu . CurrentPage -- ;
188204 else if ( showBackButton )
189- focusedMenu . Close ( ) ;
205+ {
206+ if ( focusedMenu . NavigateBack is not null )
207+ focusedMenu . NavigateBack ( focusedMenu ) ;
208+ else
209+ focusedMenu . Close ( ) ;
210+ }
190211 break ;
191212 case ConsoleKey . D9 :
192213 if ( showNextButton )
@@ -229,7 +250,7 @@ public void SortPriorities()
229250 }
230251}
231252
232- internal class NumberKeysMenu : IMenu , IMenuPriorityExtension
253+ internal class NumberKeysMenu : IMenu , IMenuPriorityExtension , INavigateBackMenuExtension
233254{
234255 public required NumbersPlayerMenuState MenuState { get ; init ; }
235256 public required List < NumberKeysMenu > Parents { get ; init ; }
@@ -284,6 +305,9 @@ public double Priority
284305 }
285306 }
286307 public bool IsFocused => MenuState . FocusStack . Count > 0 && MenuState . FocusStack [ 0 ] == this ;
308+
309+ // INavigateBackMenuExtension
310+ public Action < IMenu > ? NavigateBack { get ; set ; }
287311}
288312
289313internal class NumbersMenuItem : IMenuItem , IMenuItemSubtitleExtension
0 commit comments