class _AvailableSettings(dict): """Holds all settings.player.PlayerSettings instance menus.""" def __init__(self): """Create the main settings menu on instantiation.""" super().__init__() self.menu = PagedMenu( select_callback=self._chosen_item, title=_settings_strings['Main Title']) def _private_send_menu(self, *args): """Called when a private say command is used for sending the menu.""" # Send the menu self._send_menu(*args) # Make the command private return False def _send_menu(self, command, index, team_only=None): """Send the main settings menu to the player who requested it.""" self.menu.send(index) @staticmethod def _chosen_item(menu, index, option): """Send a PlayerSettings menu when one is chosen from the main menu.""" option.value.menu.send(index)
def shopinfo_menu_subcats_select(menu, index, choice): userid = userid_from_index(index) item = choice.value iteminfo = wcs.wcs.itemdb.getItem(item) desc = iteminfo['desc'] cost = int(iteminfo['cost']) required = int(iteminfo['level']) required_status = int(iteminfo['dab']) if required_status == 1: required_status = '<alive>' if required_status == 0: required_status = '<dead>' if required_status == 2: required_status = '<always>' duration = int(iteminfo['duration']) if duration == 1: duration = '<Until death>' if duration == 0: duration = '<One round>' maximum = int(iteminfo['max']) shopinfo_race_menu = PagedMenu(title='%s' % iteminfo['name'], parent_menu=menu) shopinfo_race_menu.append(Text('o %s' % desc)) shopinfo_race_menu.append(Text('Required level: %s' % required)) shopinfo_race_menu.append(Text('Cost: %s' % cost)) shopinfo_race_menu.append(Text('Buyable when: %s' % required_status)) shopinfo_race_menu.append(Text('Duration: %s' % duration)) shopinfo_race_menu.send(index)
def send_popup(player): if get_status() == GameStatus.BUSY: tell(player, strings_module['fail game_busy']) return arcjail_user = arcjail_user_manager[player.index] popup = PagedMenu(select_callback=popup_select_callback, title=strings_module['popup title']) for item in arcjail_user.iter_all_items(): if player.team not in item.class_.use_team_restriction: continue if not item.class_.manual_activation: continue popup.append( PagedOption( text=strings_module['popup entry'].tokenize( caption=item.class_.caption, amount=item.amount), value=item, )) if not popup: popup.title = strings_module['popup empty_message'] popup.send(player.index)
def send_popup(player): if get_status() == GameStatus.BUSY: tell(player, strings_module['fail game_busy']) return arcjail_user = arcjail_user_manager[player.index] popup = PagedMenu(select_callback=popup_select_callback, title=strings_module['popup title']) for item in arcjail_user.iter_all_items(): if player.team not in item.class_.use_team_restriction: continue if not item.class_.manual_activation: continue popup.append(PagedOption( text=strings_module['popup entry'].tokenize( caption=item.class_.caption, amount=item.amount), value=item, )) if not popup: popup.title = strings_module['popup empty_message'] popup.send(player.index)
def raceinfo_menu_select(menu, index, choice): race = choice.value raceinfo = wcs.wcs.racedb.getRace(race) required = raceinfo['required'] maximum = raceinfo['maximum'] allowonly = raceinfo['allowonly'] desc = raceinfo['desc'] skillnames = raceinfo['skillnames'].split('|') skilldesc = raceinfo['skilldescr'].split('|') numberofskills = int(raceinfo['numberofskills']) - 1 raceinfo_race_menu = PagedMenu(title='Raceinfo - %s' % race, parent_menu=menu) raceinfo_race_menu.append(Text('Required level: %s' % required)) raceinfo_race_menu.append(Text('Maximum level: %s' % maximum)) if allowonly: raceinfo_race_menu.append(Text('<Private Race>')) if desc: raceinfo_race_menu.append(Text('Description: %s' % desc)) raceinfo_race_menu.append(Text('Skills:')) x = 0 while x <= numberofskills: raceinfo_race_menu.append( PagedOption('%s' % skillnames[x], value=None, highlight=True, selectable=False)) #raceinfo_race_menu.append(Text('o %s' % skillnames[x])) v = str(skilldesc[x]).split('+') raceinfo_race_menu.append(Text('%s' % v[0])) for y in v[1:]: raceinfo_race_menu.append(Text('%s' % y)) x += 1 raceinfo_race_menu.send(index)
def takeGolddoCommand(userid): index = index_from_userid(userid) goldadmin_takegold_menu = PagedMenu( title='GiveGold Menu', build_callback=goldadmin_takegold_menu_build, select_callback=goldadmin_takegold_menu_select) goldadmin_takegold_menu.send(index)
def doCommand1(userid, value): index = index_from_userid(userid) itemkeys = wcs.wcs.ini.getItems shopmenu_menu_subcats = PagedMenu( build_callback=shopmenu_menu_subcats_build, select_callback=shopmenu_menu_subcats_select) shopmenu_menu_subcats.title = value shopmenu_menu_subcats.send(index)
def send_leaders_menu(index): """Send the leaders menu to the player.""" menu = PagedMenu(title=menu_strings['Leader:Current']) language = Player(index).language if GunGameStatus.MATCH is GunGameMatchStatus.WARMUP: menu.append(menu_strings['Warmup']) elif GunGameStatus.MATCH is not GunGameMatchStatus.ACTIVE: menu.append(menu_strings['Inactive']) elif gg_plugin_manager.is_team_game: menu.append(menu_strings['Leader:Team']) leader_level = max(team_levels.values()) teams = [ team_names[num] for num, level in team_levels.items() if level == leader_level ] weapon = weapon_order_manager.active[leader_level].weapon if len(teams) == len(team_levels): if len(teams) > 2: message = menu_strings['Leader:Team:All'].get_string( language=language, level=leader_level, weapon=weapon, ) else: message = menu_strings['Leader:Team:Tied'].get_string( language=language, level=leader_level, weapon=weapon, ) elif len(teams) > 1: message = menu_strings['Leader:Team:Multiple'].get_string( language=language, level=leader_level, weapon=weapon, ) message += f'\n\t* {", ".join(teams)}' else: message = menu_strings['Leader:Team:Current'].get_string( language=language, team=teams[0], level=leader_level, weapon=weapon, ) menu.append(StarOption(message)) elif leader_manager.current_leaders is None: menu.append(menu_strings['Leader:None']) else: level = leader_manager.leader_level menu.description = menu_strings['Leader:Level'].get_string( language=language, level=level, weapon=weapon_order_manager.active[level].weapon, ) for userid in leader_manager.current_leaders: menu.append(StarOption(player_dictionary[userid].name)) menu.send(index)
def wcs_bank_admin_command(command, index, team=None): userid = userid_from_index(index) if wcs.admin.is_admin(userid): if wcs.admin.has_flag(userid, 'wcsadmin_bank'): wcsadmin_bank_menu = PagedMenu( title='WCSBank Menu', build_callback=wcsadmin_bank_menu_build, select_callback=wcsadmin_bank_menu_select) wcsadmin_bank_menu.send(index) else: wcs.wcs.tell(userid, '\x04[WCS] \x05You\'re \x04not \x05an WCS-Bank admin')
def _showitems_command(command, index, team=None): player = Player(index) items = shopmenu.items count = 0 for x in items[player.userid]: for y in items[player.userid][x]: if items[player.userid][x][y] > 0: count += 1 if count > 0: showitem_menu = PagedMenu(title='Inventory', build_callback=showitems_menu_build, select_callback=showitems_menu_select) showitem_menu.send(index) else: wcs.wcs.tell(player.userid, "\x04[WCS] \x05You don't have any items!")
def send_rules(index): """Send the rules menu to the player.""" menu = PagedMenu( title=rules_translations['Rules:Header'], select_callback=_send_plugin_rules, ) loaded_plugins = [ plugin_name for plugin_name in all_gungame_rules if plugin_name in gg_plugin_manager ] if not loaded_plugins: menu.append(rules_translations['Rules:Empty']) menu.send(index) return for plugin_name in sorted(loaded_plugins): menu.append(PagedOption(rules_translations[plugin_name], plugin_name)) menu.send(index)
def _send_plugin_rules(parent_menu, index, choice): plugin_name = choice.value menu = PagedMenu(title=rules_translations[plugin_name]) menu.parent_menu = parent_menu rules = all_gungame_rules[plugin_name] tokens = { key: getattr(value['convar'], 'get_' + value['type'])() for key, value in rules.convar_tokens.items() } for rule in rules: menu.append( StarOption( rules[rule].get_string( language=Player(index).language, **tokens ) ) ) menu.send(index)
def doCommandChangerace(userid,value=0): global cat_to_change_to if value == 0: cat_to_change_to = 0 index = index_from_userid(userid) races = wcs.wcs.racedb.getAll() allraces = races.keys() if len(allraces): changerace_menu = PagedMenu(title='Choose a race',build_callback=changerace_menu_build, select_callback=changerace_menu_select) if categories_on.get_int() == 1: changerace_menu.parent_menu = changerace_menu_cats changerace_menu.send(index) else: cat_to_change_to = value index = index_from_userid(userid) races = wcs.wcs.racedb.getAll() allraces = races.keys() if len(allraces): changerace_menu = PagedMenu(title='Choose a race',build_callback=changerace_menu_build, select_callback=changerace_menu_select,parent_menu=changerace_menu_cats) changerace_menu.send(index)
def send_weapons_menu(index): """Send the weapon menu to the player.""" menu = PagedMenu(title=menu_strings['Weapons:Title']) if GunGameStatus.MATCH is GunGameMatchStatus.WARMUP: menu.append(menu_strings['Warmup']) elif GunGameStatus.MATCH is not GunGameMatchStatus.ACTIVE: menu.append(menu_strings['Inactive']) else: player = player_dictionary.from_index(index) for level, instance in weapon_order_manager.active.items(): menu.append( ListOption( choice_index=level, text=f'{instance.weapon} [{instance.multi_kill}]', value=level, highlight=level == player.level, selectable=False, ) ) menu.send(index)
def send_score_menu(index): """Send the score menu to the player.""" menu = PagedMenu(title=menu_strings['Score:Title']) player = player_dictionary.from_index(index) if GunGameStatus.MATCH is GunGameMatchStatus.WARMUP: menu.append(menu_strings['Warmup']) elif GunGameStatus.MATCH is not GunGameMatchStatus.ACTIVE: menu.append(menu_strings['Inactive']) elif gg_plugin_manager.is_team_game: for team in sorted( team_levels, key=lambda x: team_levels[x], reverse=True, ): menu.append( ListOption( choice_index=team_levels[team], text=team_names[team], value=team, highlight=team == player.team_index, selectable=False, ) ) else: for userid in sorted( player_dictionary, key=lambda key: player_dictionary[key].level, reverse=True, ): current_player = player_dictionary[userid] menu.append( ListOption( choice_index=current_player.level, text=current_player.name, value=current_player.unique_id, highlight=current_player.unique_id == player.unique_id, selectable=False, ) ) menu.send(index)
class _AvailableSettings(dict): """Holds all settings.player.PlayerSettings instance menus.""" def __init__(self): """Create the main settings menu on instantiation.""" super().__init__() self.menu = PagedMenu(select_callback=self._chosen_item, title=_settings_strings['Main Title']) def _private_send_menu(self, *args): """Called when a private say command is used for sending the menu.""" # Send the menu self._send_menu(*args) # Make the command private return False def _send_menu(self, command, index, team_only=None): """Send the main settings menu to the player who requested it.""" self.menu.send(index) @staticmethod def _chosen_item(menu, index, option): """Send a PlayerSettings menu when one is chosen from the main menu.""" option.value.menu.send(index)
def player_gold(command, index, team=None): gold_player_menu = PagedMenu(title='Player Gold Menu', build_callback=gold_player_menu_build, select_callback=gold_player_menu_select) gold_player_menu.send(index)
def doCommand(userid): wcstop_menu = PagedMenu(title='WCS Top Menu', build_callback=wcstop_menu_build, select_callback=wcstop_menu_select) wcstop_menu.send(index_from_userid(userid))