@@ -178,6 +178,8 @@ def __init__(
178178 :param Color title_color: See :meth:`SimpleESCMenu.__init__`.
179179 :param bool fill: If True the menu will always have the same size by
180180 filling unused options.
181+ :param _BaseMenu parent_menu: A menu that will be displayed when
182+ hitting 'Back' on the first page.
181183 """
182184 super ().__init__ (
183185 data , select_callback , build_callback ,
@@ -227,7 +229,7 @@ def _format_body(self, player_index, page, data):
227229 # Fill the rest of the menu with empty options
228230 if self .fill :
229231 option_num = len (page .options )
230- for index in range (5 - option_num ):
232+ for index in range (self . _get_max_item_count () - option_num ):
231233 index += option_num + 1
232234 button = data .find_key (str (index ), True )
233235 button .set_string ('msg' , '' )
@@ -301,6 +303,38 @@ def _select(self, player_index, choice_index):
301303 return super ()._select (player_index , choice_index )
302304
303305
306+ class ListESCMenu (PagedESCMenu ):
307+ """Creates a list-like ESC menu.
308+
309+ Navigation options are added automatically."""
310+
311+ def __init__ (
312+ self , data = None , select_callback = None , build_callback = None ,
313+ description = None , title = None , title_color = WHITE , fill = True ,
314+ parent_menu = None , items_per_page = 5 ):
315+ """Initialize the object.
316+
317+ :param iterable|None data: See :meth:`menus.base._BaseMenu.__init__`.
318+ :param callable|None select_callback: See
319+ :meth:`menus.base._BaseMenu.__init__`.
320+ :param callable|None build_callback: See
321+ :meth:`menus.base._BaseMenu.__init__`.
322+ :param str|None description: See :meth:`SimpleESCMenu.__init__`.
323+ :param str|None title: See :meth:`SimpleESCMenu.__init__`.
324+ :param Color title_color: See :meth:`SimpleESCMenu.__init__`.
325+ :param bool fill: See :meth:`PagedESCMenu.__init__`.
326+ :param _BaseMenu parent_menu: See :meth:`PagedESCMenu.__init__`.
327+ :param int items_per_page: Number of options that should be displayed
328+ on a single page (5 is the maximum).
329+ """
330+ super ().__init__ (data , select_callback , build_callback , description ,
331+ title , title_color , fill , parent_menu )
332+ self .items_per_page = items_per_page
333+
334+ def _get_max_item_count (self ):
335+ return self .items_per_page
336+
337+
304338class SimpleESCOption (_BaseOption ):
305339 """Provides options for :class:`SimpleESCMenu` objects."""
306340
@@ -332,3 +366,25 @@ def _render(self, player_index, choice_index=None):
332366 """See :meth:`menus.base._MenuData._render`."""
333367 return '{0}. {1}' .format (
334368 choice_index , _translate_text (self .text , player_index ))
369+
370+
371+ class ListESCOption (PagedESCOption ):
372+ """Provides options for :class:`ListESCMenu` objects."""
373+
374+ def __init__ (self , text , highlight = True , enumerated = True ):
375+ """Initialize the option.
376+
377+ :param str text: See :meth:`menus.base._BaseOption.__init__`.
378+ :param bool hightlight: See :meth:`SimpleESCMenu.__init__`.
379+ :param bool enumerated: If True the number of the option will be added
380+ in front of the text.
381+ """
382+ super ().__init__ (text , None , highlight , False )
383+ self .enumerated = enumerated
384+
385+ def _render (self , player_index , choice_index = None ):
386+ """See :meth:`menus.base._MenuData._render`."""
387+ if self .enumerated :
388+ return super ()._render (player_index , choice_index )
389+
390+ return _translate_text (self .text , player_index )
0 commit comments