From 47d15d1d207685ee60445a01cf3e79437eb4b6f7 Mon Sep 17 00:00:00 2001 From: ThaPwned Date: Tue, 26 Jan 2016 20:03:44 +0100 Subject: [PATCH 1/3] Added parent_menu to PagedESCMenu and PagedRadioMenu --- addons/source-python/packages/source-python/menus/esc.py | 8 +++++++- .../source-python/packages/source-python/menus/radio.py | 9 +++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/addons/source-python/packages/source-python/menus/esc.py b/addons/source-python/packages/source-python/menus/esc.py index 3090bef04..169b8a20c 100644 --- a/addons/source-python/packages/source-python/menus/esc.py +++ b/addons/source-python/packages/source-python/menus/esc.py @@ -164,7 +164,8 @@ class PagedESCMenu(SimpleESCMenu, _PagedMenuBase): def __init__( self, data=None, select_callback=None, build_callback=None, - description=None, title=None, title_color=WHITE, fill=True): + description=None, title=None, title_color=WHITE, fill=True, + parent_menu=None): """Initialize the object. :param iterable|None data: See :meth:`menus.base._BaseMenu.__init__`. @@ -182,6 +183,7 @@ def __init__( data, select_callback, build_callback, description, title, title_color) self.fill = fill + self.parent = parent @staticmethod def _get_max_item_count(): @@ -284,6 +286,10 @@ def _select(self, player_index, choice_index): # Display previous page? if choice_index == 6: + # Is the player on the first page, and do we have a parent menu? + if not page_index and self.parent_menu is not None: + return self.parent_menu + self.set_player_page(player_index, page_index - 1) return self diff --git a/addons/source-python/packages/source-python/menus/radio.py b/addons/source-python/packages/source-python/menus/radio.py index e977ef0f4..b63dac957 100644 --- a/addons/source-python/packages/source-python/menus/radio.py +++ b/addons/source-python/packages/source-python/menus/radio.py @@ -139,7 +139,7 @@ def __init__( self, data=None, select_callback=None, build_callback=None, description=None, title=None, top_separator='-' * 30, bottom_separator='-' * 30, - fill=True): + fill=True, parent_menu=None): """Initialize the object. :param iterable|None data: See :meth:`menus.base._BaseMenu.__init__`. @@ -165,6 +165,7 @@ def __init__( self.top_separator = top_separator self.bottom_separator = bottom_separator self.fill = fill + self.parent = parent @staticmethod def _get_max_item_count(): @@ -242,7 +243,7 @@ def _format_footer(self, player_index, page, slots): # TODO: Add translations # Add "Back" option - back_selectable = page.index > 0 + back_selectable = page.index > 0 or self.back_option is not None buffer += PagedRadioOption( 'Back', highlight=back_selectable)._render( player_index, BUTTON_BACK) @@ -295,6 +296,10 @@ def _select(self, player_index, choice_index): # Display previous page? if choice_index == BUTTON_BACK: + # Is the player on the first page, and do we have a parent menu? + if not page.index and self.parent_menu is not None: + return self.parent_menu + self.set_player_page(player_index, page.index - 1) return self From 3e5e9c615c6e7ecd996b72212040b7f969032676 Mon Sep 17 00:00:00 2001 From: ThaPwned Date: Tue, 26 Jan 2016 20:39:28 +0100 Subject: [PATCH 2/3] Fixed typo --- addons/source-python/packages/source-python/menus/radio.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/source-python/packages/source-python/menus/radio.py b/addons/source-python/packages/source-python/menus/radio.py index b63dac957..60c3e0033 100644 --- a/addons/source-python/packages/source-python/menus/radio.py +++ b/addons/source-python/packages/source-python/menus/radio.py @@ -243,7 +243,7 @@ def _format_footer(self, player_index, page, slots): # TODO: Add translations # Add "Back" option - back_selectable = page.index > 0 or self.back_option is not None + back_selectable = page.index > 0 or self.parent_menu is not None buffer += PagedRadioOption( 'Back', highlight=back_selectable)._render( player_index, BUTTON_BACK) From 4f10e864ef0f13383bf2e31041cb4e8dd1c8def1 Mon Sep 17 00:00:00 2001 From: ThaPwned Date: Tue, 26 Jan 2016 20:54:13 +0100 Subject: [PATCH 3/3] Fixed some more... It works, they said... who'd have thought testing was a thing, huh --- addons/source-python/packages/source-python/menus/esc.py | 2 +- addons/source-python/packages/source-python/menus/radio.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/source-python/packages/source-python/menus/esc.py b/addons/source-python/packages/source-python/menus/esc.py index 169b8a20c..90dfd77e0 100644 --- a/addons/source-python/packages/source-python/menus/esc.py +++ b/addons/source-python/packages/source-python/menus/esc.py @@ -183,7 +183,7 @@ def __init__( data, select_callback, build_callback, description, title, title_color) self.fill = fill - self.parent = parent + self.parent_menu = parent_menu @staticmethod def _get_max_item_count(): diff --git a/addons/source-python/packages/source-python/menus/radio.py b/addons/source-python/packages/source-python/menus/radio.py index 60c3e0033..1026a9a0f 100644 --- a/addons/source-python/packages/source-python/menus/radio.py +++ b/addons/source-python/packages/source-python/menus/radio.py @@ -165,7 +165,7 @@ def __init__( self.top_separator = top_separator self.bottom_separator = bottom_separator self.fill = fill - self.parent = parent + self.parent_menu = parent_menu @staticmethod def _get_max_item_count():