Skip to content

Allow to hide information about pages in the menu #471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions addons/source-python/packages/source-python/menus/radio.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def __init__(
self, data=None, select_callback=None,
build_callback=None, close_callback=None, description=None,
title=None, top_separator='-' * 30, bottom_separator='-' * 30,
fill=True, parent_menu=None):
fill=True, parent_menu=None, show_pages=True):
"""Initialize the object.

:param iterable|None data: See :meth:`menus.base._BaseMenu.__init__`.
Expand Down Expand Up @@ -172,6 +172,7 @@ def __init__(
self.bottom_separator = bottom_separator
self.fill = fill
self.parent_menu = parent_menu
self.show_pages = show_pages

@staticmethod
def _get_max_item_count():
Expand All @@ -186,11 +187,20 @@ def _format_header(self, player_index, page, slots):
:param slots: A set to which slots can be added.
:type slots: :class:`set`
"""
# Create the page info string
info = '[{0}/{1}]\n'.format(page.index + 1, self.page_count)

buffer = '{0} {1}'.format(_translate_text(
self.title, player_index), info) if self.title else info
translated_title = _translate_text(self.title, player_index) if self.title else ''
page_info = '[{0}/{1}]'.format(page.index + 1, self.page_count) if self.show_pages else ''

if translated_title and page_info:
buffer = '{0} {1}'.format(translated_title, page_info)
elif translated_title:
buffer = translated_title
elif page_info:
buffer = page_info
else:
buffer = ''

buffer += '\n'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That whole block looks quite logically redundant to me. Couldn't we just extend buffer as we go? For example (untested):

buffer = ''
if self.title:
    buffer += _translate_text(self.title, player_index)
if self.show_pages:
    buffer += f' [{page.index + 1}/{self.page_count}]'
buffer = buffer.strip() + '\n'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree. Changed and tested the code, everything works fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to suggest the following changes:

buffer = ''
if self.title:
    buffer += _translate_text(self.title, player_index)
if self.show_pages:
    if buffer:
        buffer += ' '
    buffer += f'[{page.index + 1}/{self.page_count}]'
if buffer:
    buffer += '\n'

For 2 reasons:

  • We don't want to add a leading space if there is no title.
  • We don't want to add a new line if there is no title and no pagination.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great, thank you! Ideally, we should also add the same features to ESC menus for consistency.

Copy link
Contributor Author

@dronelektron dronelektron May 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added support for "ListESCMenu" and "PagedESCMenu"

P.S. This type of menu works in "dod" as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I noticed a bug that the "ESC" menu does not close if you click the "Close" button (bottom right) or the cross (top right). Is it normal?

Copy link
Contributor Author

@dronelektron dronelektron May 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am planning to add translation for the "Back", "Next" and "Close" buttons. Or make them language-neutral (at least), such as "<", ">" and "X", but this will be in a separate pull request.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I noticed a bug that the "ESC" menu does not close if you click the "Close" button (bottom right) or the cross (top right). Is it normal?

I'm not entirely sure, but I think the client does not tell the server when the menu is closed via these buttons, so it is getting resent until a selection is actually made.

Copy link
Contributor Author

@dronelektron dronelektron May 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe consider these two buttons as selection "0" (Close)?


# Set description if present
if self.description is not None:
Expand Down Expand Up @@ -325,7 +335,7 @@ def __init__(
self, data=None, select_callback=None, build_callback=None, close_callback=None,
description=None, title=None, top_separator='-' * 30,
bottom_separator='-' * 30, fill=True, parent_menu=None,
items_per_page=10):
items_per_page=10, show_pages=True):
"""Initialize the object.

:param iterable|None data: See :meth:`menus.base._BaseMenu.__init__`.
Expand All @@ -345,7 +355,7 @@ def __init__(
on a single page.
"""
super().__init__(data, select_callback, build_callback, close_callback, description,
title, top_separator, bottom_separator, fill, parent_menu)
title, top_separator, bottom_separator, fill, parent_menu, show_pages)
self.items_per_page = items_per_page

def _get_max_item_count(self):
Expand Down