Page 1 of 1

Overlap menu's

Posted: Fri Feb 05, 2021 3:00 am
by decompile
Hello,

is the Menu Class defined to not overlap an active menu when a new menu gets sent to a player?

Would it be possible to change this behaviour, by making new menus overlap the active ones? (Or as an alternative close active when a new menu gets sent?)


Thanks

Re: Overlap menu's

Posted: Sat Feb 06, 2021 12:11 pm
by Ayuto
Yes (twice). If you have an active menu and you send another one, it gets added to the end of the queue here:
https://github.com/Source-Python-Dev-Te ... se.py#L173

It doesn't get shown immediately. Only if the user or a plugin closes the active menu, the next one is shown. So, the menus and the queues use the FIFO (First In First Out) concept. The queue also prevents a menu from being added twice. Thus, you don't need to check whether or not it is already present in the queue.

When I developed the menus package, I already planned to add the possibility to have priority menus, but I somehow didn't fully implement it. Thus, it's a little bit hacky to send a priority menu (untested):

Syntax: Select all

from contextlib import contextmanager
from menus.queue import _UserQueue

@contextmanager
def priority_menu():
old = _UserQueue.append
try:
_UserQueue.append = _UserQueue.appendleft
yield
finally:
_UserQueue.append = old


# Test
# Send as usual (FIFO)
my_menu.send()

# Send with highest priority (LIFO)
with property_menu():
my_menu.send()

# Send as usual again (FIFO)
my_menu.send()
Alternatively, you could also subclass the menu classes and re-implement the _send() method.

Re: Overlap menu's

Posted: Sat Feb 06, 2021 5:11 pm
by decompile
Thank you Ayuto!

Definitely useful to know. I will try to play with it.

Is there actually a limit how many items a menu can take for example in: PagedMenu