def wcsadmin_players_sub_changerace_menu_build(menu, client): menu.clear() wcsplayer = Player(client) accountid = wcsplayer.data['_internal_wcsadmin_player'] wcstarget = Player.from_accountid(accountid) menu.title.tokens['name'] = wcstarget.name for name in wcsplayer.data['_internal_wcsadmin_changerace']: option = PagedOption(race_manager[name].strings['name'], name) option.highlight = option.selectable = not wcstarget.current_race == name menu.append(option)
def spendskills_menu_build(menu, client): menu.clear() wcsplayer = Player(client) active_race = wcsplayer.active_race settings = active_race.settings menu.description.tokens['unused'] = active_race.unused for skill_name, config in settings.config['skills'].items(): skill = active_race.skills[skill_name] maximum = config['maximum'] required = config['required'] if skill.level >= maximum: option = PagedOption(deepcopy( menu_strings['spendskills_menu max']), selectable=False, highlight=False) elif active_race.level < required[skill.level]: option = PagedOption(deepcopy( menu_strings['spendskills_menu required']), selectable=False, highlight=False) option.text.tokens['required'] = required[skill.level] else: option = PagedOption( deepcopy(menu_strings['spendskills_menu skill']), (active_race.name, skill_name)) option.selectable = option.highlight = active_race.unused > 0 option.text.tokens['level'] = skill.level option.text.tokens['maxlevel'] = maximum option.text.tokens['name'] = settings.strings[skill_name] menu.append(option)
def shopmenu_menu_subcats_build(menu, index): menu.clear() userid = userid_from_index(index) section = menu.title menu.parent_menu = shopmenu_menu_cats items_all = wcs.wcs.ini.getItems items_all.walk(gather_subsection) for item in item_names: item_sec = wcs.wcs.itemdb.getSectionFromItem(item) if item_sec == section: iteminfo = wcs.wcs.itemdb.getItem(item) option = PagedOption( '%s - %s$' % (str(iteminfo['name']), str(iteminfo['cost'])), item) menu.append(option)
def _player_management_build_callback(menu, player_index): """Player Management menu's build_callback function.""" menu.clear() menu.title = menu.player.name menu.description = '{0} (LEVEL: {1})'.format(menu.player.hero.name, menu.player.hero.level) menu.extend([ PagedOption(_TR['Give Gold'], (menu.player, 'gold')), PagedOption(_TR['Give Cash'], (menu.player, 'cash')), PagedOption(_TR['Give Exp'], (menu.player.hero, 'exp')), PagedOption(_TR['Give Level'], (menu.player.hero, 'level')), PagedOption(_TR['Give Item'], (menu.player, 'item')), PagedOption(_TR['Kick Player'], (menu.player, 'kick')), PagedOption(_TR['Ban Player'], (menu.player, 'ban')), PagedOption(_TR['Perm Player'], (menu.player, 'perm')) ])
def goldadmin_takegold_menu_select(menu, index, choice): player_entity = choice.value takeamount_menu.parent_menu = menu takeamount_menu.append(PagedOption('1', player_entity)) takeamount_menu.append(PagedOption('10', player_entity)) takeamount_menu.append(PagedOption('50', player_entity)) takeamount_menu.append(PagedOption('100', player_entity)) takeamount_menu.append(PagedOption('300', player_entity)) takeamount_menu.append(PagedOption('500', player_entity)) takeamount_menu.send(index)
def _buy_items_build_callback(menu, player_index): """Buy Items menu's build_callback function.""" player = Player(player_index) menu.clear() for item in menu.entities: option = PagedOption( '{name} ({cost})'.format( name=item.name, cost=_translate_text(_TR['Cost'].get_string( cost=item.cost), player_index) if not item in player.hero.restricted_items else 'RESTRICTED'), item) if item.cost > player.gold or item in player.hero.restricted_items: option.selectable = option.highlight = False menu.append(option)
def _on_items_build(menu, index): player = player_dict[index] category = shop_category_dict[index] items = Item.list_items_in_category(category) menu.clear() menu.title = category for item_cls in items: selectable = item_cls.is_available(player) menu.append( PagedOption( item_cls.name + " ({})".format(item_cls.requirement_string), item_cls, selectable=selectable, highlight=selectable ) )
def wcsadmin_management_races_editor_modify_from_selection_menu_build( menu, client): wcsplayer = Player(client) name = wcsplayer.data['_internal_wcsadmin_editor_value'] key = wcsplayer.data['_internal_wcsadmin_editor_key'] actual_name = name[1:] if name.startswith('_') else name menu.title.tokens['name'] = actual_name del menu[1:] with open(RACE_PATH / actual_name / 'config.json') as inputfile: config = load(inputfile) for value in config[key]: menu.append(PagedOption(value, value))
def wcsadmin_management_items_add_menu_build(menu, client): if (CFG_PATH / 'items.json').isfile(): with open(CFG_PATH / 'items.json') as inputfile: current_items = load(inputfile).get('items', []) else: current_items = [] menu.clear() available_items = [x.basename() for x in ITEM_PATH.listdir()] for value in [ x for x in available_items if x not in current_items and '_' + x not in current_items ]: menu.append(PagedOption(value, value))
def _add_to_category(self, container, module, category, menu_choice, menu_info): container._category_to_values[category].append(self.name) if category is None: menu_choice.append(PagedOption(self.strings['name'], self.name)) menu_info.append(PagedOption(self.strings['name'], self.name)) return self.config['categories'].append(category) if module: from ..menus.build import changerace_menu_build as menu_choice_build from ..menus.close import raceinfo_menu_close as menu_info_close from ..menus.select import changerace_menu_select as menu_choice_select from ..menus.select import raceinfo_menu_select as menu_info_select menu_choice_name = 'changerace_menu' menu_info_name = 'raceinfo_menu' else: from ..menus.build import shopmenu_menu_build as menu_choice_build from ..menus.close import shopinfo_menu_close as menu_info_close from ..menus.select import shopmenu_menu_select as menu_choice_select from ..menus.select import shopinfo_menu_select as menu_info_select menu_choice_name = 'shopmenu_menu' menu_info_name = 'shopinfo_menu' if category not in container._category_menus: menu = container._category_menus[category] = PagedPageCountMenu() menu.name = category menu.title = menu_strings[f'{menu_choice_name} title'] menu.parent_menu = menu_choice menu.build_callback = menu_choice_build menu.select_callback = menu_choice_select menu_choice.append( PagedOption(categories_strings.get(category, category), menu)) menu = container._info_category_menus[ category] = PagedPageCountMenu() menu.name = category menu.title = menu_strings[f'{menu_info_name} title'] menu.parent_menu = menu_info menu.select_callback = menu_info_select menu.close_callback = menu_info_close menu_info.append( PagedOption(categories_strings.get(category, category), menu)) container._category_menus[category].append( PagedOption(self.strings['name'], self.name)) container._info_category_menus[category].append( PagedOption(self.strings['name'], self.name))
def wcsadmin_givexp_menu_select(menu, index, choice): player_entity = choice.value amount_menu.clear() amount_menu.parent_menu = menu amount_menu.append(PagedOption('1', player_entity)) amount_menu.append(PagedOption('10', player_entity)) amount_menu.append(PagedOption('50', player_entity)) amount_menu.append(PagedOption('100', player_entity)) amount_menu.append(PagedOption('300', player_entity)) amount_menu.append(PagedOption('500', player_entity)) amount_menu.send(index)
def wcsadmin_management_items_add_menu_select(menu, client, option): with open(CFG_PATH / 'items.json') as inputfile: data = load(inputfile) data['items'].append(option.value) with open(CFG_PATH / 'items.json', 'w') as outputfile: dump(data, outputfile, indent=4) menu.remove(option) wcsadmin_management_items_menu.append(PagedOption(option.value, option.value)) if not menu: return menu.parent_menu return menu
def add_option(self, name, text=None): """Add an option to the setting's dictionary.""" # Is the given option already registered? if name in self.options: # Raise an error raise ValueError( 'Given name "{0}" is already an option'.format(name)) # Store the option option = self.options[name] = PagedOption( text=name if text is None else text, value=name, ) # Add the option to the menu self.menu.append(option)
def on_github_new_version_checked(version, commits): wcsadmin_github_info_menu._checking_cycle = None wcsadmin_github_info_menu[3] = SimpleOption( 1, menu_strings['wcsadmin_github_info_menu check']) wcsadmin_github_info_confirm_commits_menu.clear() if version is None: wcsadmin_github_info_menu[4] = Text(' ') wcsadmin_github_info_confirm_menu[2].text.tokens['version'] = '' else: wcsadmin_github_info_menu[4] = SimpleOption( 2, menu_strings['wcsadmin_github_info_menu update']) wcsadmin_github_info_menu[4].text.tokens['version'] = version wcsadmin_github_info_confirm_menu[2].text.tokens['version'] = version for commit in commits: menu = PagedMenu( title=menu_strings[ 'wcsadmin_github_info_commits_detail_menu title'], parent_menu=wcsadmin_github_info_confirm_commits_menu) menu.append( Text( deepcopy(menu_strings[ 'wcsadmin_github_info_commits_detail_menu line 1']))) menu.append( Text( deepcopy(menu_strings[ 'wcsadmin_github_info_commits_detail_menu line 2']))) menu.append( Text(menu_strings[ 'wcsadmin_github_info_commits_detail_menu line 3'])) menu[0].text.tokens['name'] = commit['author'] menu[1].text.tokens['date'] = commit['date'] for message in commit['messages'].splitlines(): for text in wrap(' ' + message, 50): menu.append(Text(text)) wcsadmin_github_info_confirm_commits_menu.append( PagedOption(commit['date'], value=menu)) for index in wcsadmin_github_info_confirm_commits_menu._player_pages: if wcsadmin_github_info_confirm_commits_menu.is_active_menu(index): wcsadmin_github_info_confirm_commits_menu._refresh(index)
def reload_map_list(): if not isinstance(mapcycle_json, list): raise CorruptJSONFile("Parsed object is not a list") # Check if vote has not started yet - useful to prevent things from # getting dirty because of 'mc reload-mapcycle' if status.vote_status != VoteStatus.NOT_STARTED: raise RuntimeError("Vote has already started or even ended, " "can't execute reload_map_list now") server_map_manager.clear() for i, json_dict in enumerate(mapcycle_json): try: filename = json_dict['filename'] except KeyError: warn("Map #{}: missing 'filename' key") continue if filename.lower() in server_map_manager: warn("Duplicate maps '{}'".format(filename)) continue if not engine_server.is_map_valid(filename): warn("Engine says that '' is not a valid map".format(filename)) continue server_map_manager.create(json_dict) logger.log_debug("Added {} valid maps".format(len(server_map_manager))) # Now rebuild nomination menu nomination_popup.clear() for server_map in sorted( server_map_manager.values(), key=lambda server_map: server_map.filename): selectable = not server_map.played_recently nomination_popup.append(PagedOption( text=server_map.name, value=server_map, highlight=selectable, selectable=selectable )) logger.log_debug("Added {} maps to the !nominate menu".format( len(server_map_manager.values())))
def _on_admin_players_select(menu, index, choice): player = choice.value player_menu.clear() player_menu.title = player.name + f" - ({player.userid})" player_menu.description = f"Playing {player.race.name} (LV {player.race.level})" player_menu.append(PagedOption("Give 1 Level", (player, 1))) player_menu.append(PagedOption("Give 5 Levels", (player, 5))) player_menu.append(PagedOption("Give 10 Levels", (player, 10))) player_menu.append(PagedOption("Take 1 Level", (player, -1))) player_menu.append(PagedOption("Take 5 Levels", (player, -5))) player_menu.append(PagedOption("Take 10 Levels", (player, -10))) return player_menu
def wcsadmin_github_items_repository_menu_build(menu, client): menu.clear() wcsplayer = Player(client) name = wcsplayer.data['_internal_wcsadmin_github_name'] menu.title.tokens['name'] = name git_option = github_manager['items'][name] for repository in git_option['repositories']: option = PagedOption(menu_strings['wcsadmin_github_items_repository_menu line'], repository) option.text.tokens['name'] = repository option.text.tokens['time'] = strftime(TIME_FORMAT, localtime(git_option['repositories'][repository]['last_modified'])) menu.append(option)
def showskills_menu_build(menu, client): menu.clear() wcsplayer = Player(client) active_race = wcsplayer.active_race settings = active_race.settings menu.title.tokens['name'] = active_race.settings.strings['name'] menu.description.tokens['unused'] = active_race.unused for skill_name in settings.config['skills']: skill = active_race.skills[skill_name] option = PagedOption(deepcopy(menu_strings['showskills_menu line']), selectable=False) option.text.tokens['name'] = settings.strings[skill_name] option.text.tokens['level'] = skill.level option.text.tokens['maximum'] = skill.config['maximum'] menu.append(option)
def _format_footer(self, player_index, page, slots): """Prepares the footer for the menu.""" buffer = '' # Set the bottom seperator if present if self.bottom_seperator is not None: buffer += '{0}\n'.format(self.bottom_seperator) # Add "Previous" option option_previous = PagedOption(_TR['Previous'], self.previous_menu, highlight=False, selectable=False) if page.index > 0 or self.previous_menu: option_previous.highlight = option_previous.selectable = True slots.add(7) buffer += option_previous._render(player_index, 7) # Add "Next" option option_next = PagedOption(_TR['Next'], self.next_menu, highlight=False, selectable=False) if page.index < self.last_page_index or self.next_menu: option_next.highlight = option_next.selectable = True slots.add(8) buffer += option_next._render(player_index, 8) # Add "Close" option option_close = PagedOption(_TR['Close'], highlight=False) buffer += option_close._render(player_index, 9) slots.add(9) # Return the buffer return buffer
def _buy_heroes_build_callback(menu, player_index): """Buy Heroes menu's build_callback function.""" player = get_player(player_index, key='index') menu.clear() for hero_cls in menu.entities: option = PagedOption( '{0} ({1})'.format( hero_cls.name, _translate_text( _TR['Cost'].get_string(cost=hero_cls.cost), player_index ) ), hero_cls ) if hero_cls.cost > player.gold: option.selectable = option.highlight = False menu.append(option)
def wcstop_menu_build(menu, index): menu.clear() allplayers = sorted(wcs.wcs.wcs_rank, key=lambda x: wcs.wcs.wcs_rank[x]['totallevel'], reverse=True) if len(allplayers): for number, steamid in enumerate(allplayers): if number < 5: name = wcs.wcs.wcs_rank[steamid]['name'] currace = wcs.wcs.wcs_rank[steamid]['currace'] totallevel = wcs.wcs.wcs_rank[steamid]['totallevel'] level = wcs.wcs.wcs_rank[steamid]['level'] option = PagedOption( '%s | Total level: %s | Playing %s | Level %s' % (str(name), totallevel, currace, level), str(name), highlight=True, selectable=False) menu.append(option)
def send_leader_popup(player): reason = get_leader_respawn_denial_reason(player) if reason: tell(player, reason) return if player.index in _popups: _popups[player.index].close() def select_callback(popup, player_index, option): reason = get_leader_respawn_denial_reason(player) if reason: tell(player, reason) return player_ = option.value if not player_.dead: tell(player, strings_module['fail_alive']) return respawn(player_) broadcast(strings_module['resurrected_by_leader'].tokenize( player=player_.name)) popup = _popups[player.index] = PagedMenu( select_callback=select_callback, title=strings_module['popup_title_resurrect']) for player_ in PlayerIter(['dead', 'jail_prisoner']): if (player_.steamid in _rebel_steamids and not config_manager['allow_respawning_rebels']): continue popup.append( PagedOption(text=player_.name, value=player_, highlight=True, selectable=True)) popup.send(player.index)
def _buy_items_build_callback(menu, player_index): """Buy Items menu's build_callback function.""" player = get_player(player_index, key='index') menu.clear() for item in menu.entities: option = PagedOption( '{name} (${cost})\n{description}'.format( name=item.name, cost=_translate_text( _TR['Cost'].get_string(cost=item.cost), player_index ), description=item.description ), item ) if item.cost > player.gold: option.selectable = option.highlight = False menu.append(option)
def wcs_bank_command(command, index, team=None): userid = userid_from_index(index) if bank_player_loaded[userid] == True: if int(bankplayer[userid].levels) > 0: amount_menu.clear() amount_menu.append( Text('You have %s Levels in your bank' % bankplayer[userid].levels)) amount_menu.append(PagedOption('1', 'spendlevels')) amount_menu.append(PagedOption('5', 'spendlevels')) amount_menu.append(PagedOption('10', 'spendlevels')) amount_menu.append(PagedOption('25', 'spendlevels')) amount_menu.append(PagedOption('100', 'spendlevels')) amount_menu.append(PagedOption('250', 'spendlevels')) amount_menu.append(PagedOption('1000', 'spendlevels')) amount_menu.append(PagedOption('2500', 'spendlevels')) amount_menu.send(index) else: wcs.wcs.tell( userid, '\x04[WCS] \x05You do not have \x04any \x05levels in your \x04Levelbank' )
def on_github_commits_refreshed(commits): wcsadmin_github_info_commits_menu._cycle = None wcsadmin_github_info_commits_menu.clear() for commit in commits: menu = PagedMenu(title=menu_strings['wcsadmin_github_info_commits_detail_menu title'], parent_menu=wcsadmin_github_info_commits_menu) menu.append(Text(deepcopy(menu_strings['wcsadmin_github_info_commits_detail_menu line 1']))) menu.append(Text(deepcopy(menu_strings['wcsadmin_github_info_commits_detail_menu line 2']))) menu.append(Text(menu_strings['wcsadmin_github_info_commits_detail_menu line 3'])) menu[0].text.tokens['name'] = commit['author'] menu[1].text.tokens['date'] = commit['date'] for message in commit['messages'].splitlines(): for text in wrap(' ' + message, 50): menu.append(Text(text)) wcsadmin_github_info_commits_menu.append(PagedOption(commit['date'], value=menu)) for index in wcsadmin_github_info_commits_menu._player_pages: if wcsadmin_github_info_commits_menu.is_active_menu(index): wcsadmin_github_info_commits_menu._refresh(index)
def send_popup(player): reason = get_game_denial_reason(player) if reason: tell(player, reason) return if player.index in _popups: _popups[player.index].close() players = get_players_to_play() def select_callback(popup, player_index, option): reason = get_game_denial_reason(player) if reason is not None: tell(player, reason) return launcher = option.value reason = launcher.get_launch_denial_reason(player, players) if reason is not None: tell(player, reason) return _launch_game(launcher, player, players) popup = _popups[player.index] = PagedMenu( select_callback=select_callback, title=strings_module['popup title_choose'] ) for launcher in get_available_launchers(player, players): popup.append(PagedOption( text=launcher.caption, value=launcher, highlight=True, selectable=True )) popup.send(player.index)
def _owned_hero_categories_build_callback(menu, player_index): player = Player(player_index) menu.entities = [] for hero_cls in player.heroes: menu.entities.append(hero_cls) menu.clear() categories = dict() for entity in menu.entities: if entity.category not in categories: categories[entity.category] = [entity] else: categories[entity.category].append(entity) for category in categories: menu.append( PagedOption( '{category} ({size})'.format(category=category, size=len(categories[category])), categories[category]))
def __setitem__(self, item, value): """Validate the given value and its type before setting the item.""" # Is the given value a proper type? if not isinstance(value, (_SettingsDictionary, SettingsType)): # Raise an error raise ValueError('Given value "{0}" is not valid'.format(value)) # Is the item already in the dictionary? if item in self: # Raise an error raise ValueError( 'Given item "{0}" is already registered'.format(item)) # Set the item in the dictionary super().__setitem__(item, value) # Get the new object value = self[item] # Set the item's prefix value.prefix = self.prefix if not value.prefix.endswith('_'): value.prefix += '_' # Does the section's name need added to the prefix? if not isinstance(self, PlayerSettings): # Add the section's name to the prefix value.prefix += self.name.lower().replace(' ', '_') + '_' # Add the option to the menu self.menu.append( PagedOption(value.name if value.text is None else value.text, value))
def send_player_popup(player, launcher): reason = get_lr_denial_reason(player) if reason is not None: tell(player, reason) return reason = launcher.get_launch_denial_reason() if reason is not None: tell(player, reason) return if player.index in _popups: _popups[player.index].close() def select_callback_player(popup, player_index, option): send_settings_popup(player, launcher, option.value) popup = _popups[player.index] = PagedMenu( select_callback=select_callback_player, title=strings_module['popup title choose_player'], ) spare_players = set(PlayerIter(['jail_guard', 'alive'])) for game_instance in _game_instances: spare_players.difference_update(game_instance.players) for player_ in spare_players: popup.append(PagedOption( text=player_.name, value=player_, highlight=True, selectable=True )) popup.send(player.index)
def _format_footer(self, player_index, page, slots): """Prepares the footer for the menu.""" buffer = '' # Set the bottom seperator if present if self.bottom_seperator is not None: buffer += '{0}\n'.format(self.bottom_seperator) # Add "Previous" option option_previous = PagedOption( _TR['Previous'], self.previous_menu, highlight=False, selectable=False ) if page.index > 0 or self.previous_menu: option_previous.highlight = option_previous.selectable = True slots.add(7) buffer += option_previous._render(player_index, 7) # Add "Next" option option_next = PagedOption( _TR['Next'], self.next_menu, highlight=False, selectable=False ) if page.index < self.last_page_index or self.next_menu: option_next.highlight = option_next.selectable = True slots.add(8) buffer += option_next._render(player_index, 8) # Add "Close" option option_close = PagedOption( _TR['Close'], highlight=False ) buffer += option_close._render(player_index, 9) slots.add(9) # Return the buffer return buffer
def build(menu, index): """List players""" menu.clear() for player in PlayerIter('human'): menu.append(PagedOption(player.name, player))