def _close(self, player_index): """See :meth:`menus.base._BaseMenu._close`.""" queue = self.get_user_queue(player_index) queue.priority -= 1 # Unfortunately, this doesn't hide the menu :( data = KeyValues('menu') data.set_string('title', '') data.set_int('level', queue.priority) data.set_int('time', 10) data.set_string('msg', '') create_message(edict_from_index(player_index), DialogType.MENU, data)
def _close(self, player_index): """Close a menu by overriding it with an empty menu. @param <player_index>: A player index. """ queue = self.get_user_queue(player_index) queue.priority -= 1 # Unfortunately, this doesn't hide the menu :( data = KeyValues('menu') data.set_string('title', '') data.set_int('level', queue.priority) data.set_int('time', 10) data.set_string('msg', '') create_message(edict_from_index(player_index), DialogType.MENU, data)
def _get_menu_data(self, player_index): """See :meth:`menus.base._BaseMenu._get_menu_data`.""" data = KeyValues('menu') data.set_string( 'msg', _translate_text(self.description or '', player_index)) # Get the player's current page page = self._player_pages[player_index] page.options = {} # Format the menu self._format_header(player_index, page, data) self._format_body(player_index, page, data) self._format_footer(player_index, page, data) # Return the menu data return data
def send(self, *player_indexes, **tokens): """Send the Dialog message to the appropriate recipients. :param player_indexes: Values can be a player index, multiple player indexes (star args), a :class:`filters.players.PlayerIter` instance, or a :class:`filters.recipients.RecipientFilter` instance. :param tokens: Keyword arguments used to replace values in messages. """ # Get a recipient filter of the given users recipients = RecipientFilter(*player_indexes) # Get the KeyValues instance keyvalues = KeyValues(self.message_type.name.lower()) # Set the time for the message to display keyvalues.set_int('time', self.time) # Loop through all recipients for index in recipients: # Get a Player instance for the current player player = Player(index) # Is the player not human? if player.is_fake_client(): continue # Get the level for the message level = self._get_player_level(player.userid) # Set the level for the player keyvalues.set_int('level', level) # Set the title (value should be server IP address) keyvalues.set_string( 'title', self._get_text(self.title, player, **tokens)) # Set any remaining keyvalues self._set_keyvalues(keyvalues, player, **tokens) # Send the message create_message(player.edict, self.message_type, keyvalues)
def _get_menu_data(self, player_index): """Return all relevant menu data as a KeyValues instance. @param <player_index>: A player index. """ data = KeyValues('menu') data.set_string( 'msg', _translate_text(self.description or '', player_index)) # Get the player's current page page = self._player_pages[player_index] page.options = {} # Format the menu self._format_header(player_index, page, data) self._format_body(player_index, page, data) self._format_footer(player_index, page, data) # Return the menu data return data
def _get_menu_data(self, player_index): """Return all menu data as a :class:`keyvalues.KeyValues` object. :param int player_index: See :meth:`menus.base._BaseMenu._get_menu_data`. """ data = KeyValues('menu') data.set_string( 'msg', _translate_text(self.description or '', player_index)) if self.title is not None: data.set_string( 'title', _translate_text(self.title, player_index)) data.set_color('color', self.title_color) page = self._player_pages[player_index] page.options = {} # Loop through all options of the current page for raw_data in self: if isinstance(raw_data, SimpleESCOption): page.options[raw_data.choice_index] = raw_data button = data.find_key(str(raw_data.choice_index), True) button.set_string('msg', raw_data._render(player_index)) button.set_string('command', '{0} {1}'.format( ESC_SELECTION_CMD, raw_data.choice_index)) close = SimpleESCOption(0, 'Close') button = data.find_key(str(close.choice_index), True) button.set_string('msg', close._render(player_index)) button.set_string('command', '{0} {1}'.format( ESC_SELECTION_CMD, close.choice_index)) # Return the menu data return data
def _get_menu_data(self, player_index): """Return all relevant menu data as a KeyValues instance. @param <player_index>: A player index. """ data = KeyValues('menu') data.set_string( 'msg', _translate_text(self.description or '', player_index)) if self.title is not None: data.set_string( 'title', _translate_text(self.title, player_index)) data.set_color('color', self.title_color) page = self._player_pages[player_index] page.options = {} # Loop through all options of the current page for raw_data in self: if isinstance(raw_data, SimpleESCOption): page.options[raw_data.choice_index] = raw_data button = data.find_key(str(raw_data.choice_index), True) button.set_string('msg', raw_data._render(player_index)) button.set_string('command', '{0} {1}'.format( ESC_SELECTION_CMD, raw_data.choice_index)) close = SimpleESCOption(0, 'Close') button = data.find_key(str(close.choice_index), True) button.set_string('msg', close._render(player_index)) button.set_string('command', '{0} {1}'.format( ESC_SELECTION_CMD, close.choice_index)) # Return the menu data return data