Skip to content

Commit 47d15d1

Browse files
committed
Added parent_menu to PagedESCMenu and PagedRadioMenu
1 parent 7350053 commit 47d15d1

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

addons/source-python/packages/source-python/menus/esc.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ class PagedESCMenu(SimpleESCMenu, _PagedMenuBase):
164164

165165
def __init__(
166166
self, data=None, select_callback=None, build_callback=None,
167-
description=None, title=None, title_color=WHITE, fill=True):
167+
description=None, title=None, title_color=WHITE, fill=True,
168+
parent_menu=None):
168169
"""Initialize the object.
169170
170171
:param iterable|None data: See :meth:`menus.base._BaseMenu.__init__`.
@@ -182,6 +183,7 @@ def __init__(
182183
data, select_callback, build_callback,
183184
description, title, title_color)
184185
self.fill = fill
186+
self.parent = parent
185187

186188
@staticmethod
187189
def _get_max_item_count():
@@ -284,6 +286,10 @@ def _select(self, player_index, choice_index):
284286

285287
# Display previous page?
286288
if choice_index == 6:
289+
# Is the player on the first page, and do we have a parent menu?
290+
if not page_index and self.parent_menu is not None:
291+
return self.parent_menu
292+
287293
self.set_player_page(player_index, page_index - 1)
288294
return self
289295

addons/source-python/packages/source-python/menus/radio.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def __init__(
139139
self, data=None, select_callback=None,
140140
build_callback=None, description=None,
141141
title=None, top_separator='-' * 30, bottom_separator='-' * 30,
142-
fill=True):
142+
fill=True, parent_menu=None):
143143
"""Initialize the object.
144144
145145
:param iterable|None data: See :meth:`menus.base._BaseMenu.__init__`.
@@ -165,6 +165,7 @@ def __init__(
165165
self.top_separator = top_separator
166166
self.bottom_separator = bottom_separator
167167
self.fill = fill
168+
self.parent = parent
168169

169170
@staticmethod
170171
def _get_max_item_count():
@@ -242,7 +243,7 @@ def _format_footer(self, player_index, page, slots):
242243

243244
# TODO: Add translations
244245
# Add "Back" option
245-
back_selectable = page.index > 0
246+
back_selectable = page.index > 0 or self.back_option is not None
246247
buffer += PagedRadioOption(
247248
'Back', highlight=back_selectable)._render(
248249
player_index, BUTTON_BACK)
@@ -295,6 +296,10 @@ def _select(self, player_index, choice_index):
295296

296297
# Display previous page?
297298
if choice_index == BUTTON_BACK:
299+
# Is the player on the first page, and do we have a parent menu?
300+
if not page.index and self.parent_menu is not None:
301+
return self.parent_menu
302+
298303
self.set_player_page(player_index, page.index - 1)
299304
return self
300305

0 commit comments

Comments
 (0)