Overlap menu's

Please post any questions about developing your plugin here. Please use the search function before posting!
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Overlap menu's

Postby decompile » Fri Feb 05, 2021 3:00 am

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
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Overlap menu's

Postby Ayuto » Sat Feb 06, 2021 12:11 pm

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.
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Re: Overlap menu's

Postby decompile » Sat Feb 06, 2021 5:11 pm

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

Return to “Plugin Development Support”

Who is online

Users browsing this forum: Bing [Bot] and 18 guests