choice_index == 0

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

choice_index == 0

Postby decompile » Fri Mar 25, 2016 8:40 pm

Hey,

Is there a way to return the menu when the player trys to close it via "0"?

I tried it with choice_index == 0 but it didnt worked or more nothing happens
User avatar
Ayuto
Project Leader
Posts: 2209
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Fri Mar 25, 2016 9:05 pm

Select callbacks don't get called when the close button was pressed. This behaviour is defined here:
https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/addons/source-python/packages/source-python/menus/radio.py#L105

But you can easily extend and update the default behaviour by subclassing the menu class.

Syntax: Select all

from menus.radio import BUTTON_CLOSE
from menus.radio import SimpleRadioMenu


class SimpleMenuExtension(SimpleRadioMenu):
def __init__(self, *args, on_close_menu=None, **kwargs):
super().__init__(*args, **kwargs)
self.on_close_menu = on_close_menu

def _select(self, player_index, choice_index):
if choice_index == BUTTON_CLOSE and self.on_close_menu is not None:
return self.on_close_menu(self, player_index)

return super()._select(player_index, choice_index)


def on_close_menu(menu, player_index):
# Return your menu here
pass

menu = SimpleMenuExtension(on_close_menu=on_close_menu)

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 80 guests