Skip to content
Merged
Changes from all commits
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
31 changes: 31 additions & 0 deletions addons/source-python/packages/source-python/menus/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,37 @@ def _close(self, player_index):
"""
raise NotImplementedError

def register_select_callback(self, callback):
"""Register a select callback for the menu.

Can and should be used as a decorator.

:param callable callback: A function that gets called
whenever a selection was made.

The callback will recieve 3 parameters:
1. The instance of this menu.
2. The player's index who made the selection.
3. The player's choice.
"""
self.select_callback = callback
return callback

def register_build_callback(self, callback):
"""Register a build callback for the menu.

Can and should be used as a decorator.

:param callable callback: A function that gets called
before a menu is displayed.

The callback will recieve 2 parameters:
1. The instance of this menu.
2. The index of the player who will recieve this menu.
"""
self.build_callback = callback
return callback


class _MenuData(object):
"""Base class for menu data.
Expand Down