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 send_popup(player): options = [] for available_option in _available_options: if available_option.handler_visible(player): text = available_option.caption selectable = available_option.handler_active(player) option = PagedOption(text=text, value=available_option.callback, highlight=selectable, selectable=selectable) options.append(option) if options: if player.index in _popups: _popups[player.index].close() def select_callback(popup, player_index, option): callback = option.value callback(player) menu = _popups[player.index] = PagedMenu( select_callback=select_callback, title=strings_module['title']) for option in options: menu.append(option) menu.send(player.index) else: tell(player, strings_module['empty'])
def __new__(cls, name, default, text=None, *args): """Verify the name and default value before getting the new object.""" # Was a valid value passed as the name? if not name.replace('_', '').replace(' ', '').isalpha(): # Raise an error raise ValueError( 'Given name "{0}" is not valid'.format(name)) # Is the given default value of the correct type? if not isinstance(default, cls._type): # Raise an error raise ValueError( 'Given value must be of "{0}" type, not "{1}"'.format( cls._type.__name__, type(default).__name__)) # Get the new object instance self = object.__new__(cls) # Store the base attributes self._name = name self._default = default self._text = text # Store a menu for the object self._menu = PagedMenu( select_callback=self._chosen_value, build_callback=self._menu_build, title=name if text is None else text, description=_settings_strings['Description']) # Return the instance return self
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 menu(cls): """Return the menu object""" return PagedMenu( title=cls.caption, build_callback=cls.build, select_callback=cls.select )
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 launch_voting(player, wont_play_option=False): reason = get_game_denial_reason(player) if reason is not None: tell(player, reason) return global _last_voting if _last_voting is not None: _last_voting.finish() _last_voting = GameVoting() popup = PagedMenu(select_callback=_last_voting.select_callback, title=strings_module['popup title']) if wont_play_option: popup.append( PagedOption( text=strings_module['popup option wont_play'], value="WONT_PLAY", )) players = get_players_to_play() for launcher in get_available_launchers(player, players): popup.append(PagedOption( text=launcher.caption, value=launcher, )) _last_voting.start(popup, players, config_manager['timeout'])
def send_game_popup(player): reason = get_lr_denial_reason(player) if reason: tell(player, reason) return if player.index in _rebel_delays: tell(player, strings_module['fail already_asking_guard']) return if player.index in _popups: _popups[player.index].close() def select_callback_game(popup, player_index, option): send_player_popup(player, option.value) popup = _popups[player.index] = PagedMenu( select_callback=select_callback_game, title=strings_module['popup title choose_game'] ) for launcher in get_available_launchers(): popup.append(PagedOption( text=launcher.caption, value=launcher, highlight=True, selectable=True )) popup.send(player.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 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 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 __init__(self, name, text=None): """Verify the name value and stores base attributes.""" # Is the given name a proper value for a convar? if not name.replace('_', '').replace(' ', '').isalpha(): # Raise an error raise ValueError('Given name "{0}" is not valid'.format(name)) # Set the base attributes self._name = name self._text = text # Create the instance's menu self._menu = PagedMenu(select_callback=self._chosen_item, title=name if text is None else text) # Call the super class' __init__ to initialize the OrderedDict super().__init__()
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 __init__(self, feature, parent, title, id_=None): super().__init__(feature, parent, title, id_) self.map_popup = PagedMenu( title=plugin_strings['popup_title change_level']) @self.map_popup.register_build_callback def build_callback(popup, index): popup.clear() for map_name in _map_cycle_plugin.module.external.get_map_list(): popup.append(PagedOption( text=map_name, value=map_name, )) @self.map_popup.register_select_callback def select_callback(popup, index, option): client = clients[index] self.feature.execute(client, option.value)
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 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 menu(cls): return PagedMenu(title=menus['Ban Reasons'], build_callback=cls.build, select_callback=cls.select)
if player.steamid != 'BOT': option = PagedOption('%s' % player.name, player) menu.append(option) def wcs_amount_select(menu, index, choice): userid = choice.value.userid amount = int(choice.text) player = Player(index) wcs.wcs.wcsplayers[userid].give_xp(amount) wcs.wcs.tell( userid, '\x04[WCS] \x05You got \x04%s XP \x05from admin \x04%s!' % (amount, player.name)) amount_menu = PagedMenu(title='Amount Menu', select_callback=wcs_amount_select) 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 _on_race_info_build(menu, index): menu.clear() for race_cls in Race.sort_subclasses(key=lambda x: x.requirement_sort_key): menu.append( PagedOption(raceinfo_menu_strings['race'].get_string( name=race_cls.name, requirement=race_cls.requirement_string), race_cls, selectable=True)) def _on_race_info_select(menu, index, choice): race_cls = choice.value race_info_menu = ListMenu(title=race_cls.name, description=race_cls.description, parent_menu=menu) for skill_cls in race_cls._skills: race_info_menu.append(ListOption(skill_cls.name)) race_info_menu.append(Text(skill_cls.description)) return race_info_menu ## menu declarations race_info_menu = PagedMenu( title=raceinfo_menu_strings['header'], build_callback=_on_race_info_build, select_callback=_on_race_info_select, parent_menu=main_menu, )
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)
return index = base_entity.index recording_mgr.remove_recorder(index) recording_mgr.remove_player(index) # ============================================================================== # >> TEST # ============================================================================== from commands.typed import TypedSayCommand from menus import PagedMenu from menus import PagedOption recording_menu = PagedMenu(title='Choose a recording to play:') @recording_menu.register_build_callback def on_menu_build(menu, index): menu.clear() for recording in recording_mgr: menu.append( PagedOption( '{} - {}'.format( time.strftime('%H:%M:%S', time.localtime(recording.creation_time)), round(recording.duration, 2)), recording))
def wcsadmin_resetplayer_menu_build(menu, index): menu.clear() for player in PlayerIter(): if player.steamid != 'BOT': option = PagedOption('%s' % player.name, player) menu.append(option) def wcs_amount_select(menu, index, choice): userid = choice.value.userid if choice.text == 'Yes': player_entity = Player(index) wcs.wcs.wcsplayers[player_entity.userid].delete_player() wcs.wcs.tell(userid, '\x04[WCS] \x05You have been completely reset by admin \x04%s!' % player_entity.name) if choice.text == 'No': menu.close(index) amount_menu = PagedMenu(title='Amount Menu', select_callback=wcs_amount_select) def wcsadmin_resetplayer_menu_select(menu, index, choice): player_entity = choice.value amount_menu.parent_menu = menu amount_menu.append(PagedOption('Yes', player_entity)) amount_menu.append(PagedOption('No', player_entity)) amount_menu.send(index) def doCommand(userid): index = index_from_userid(userid) wcsadmin_resetplayer_menu.send(index) wcsadmin_resetplayer_menu = PagedMenu(title='Resetplayer Menu', build_callback=wcsadmin_resetplayer_menu_build, select_callback=wcsadmin_resetplayer_menu_select)
player_rank.append(ListOption('Steam ID: {}'.format(steamid))) player_rank.append(Text(' ')) player_rank.append(ListOption('Current Hero: {}'.format(hero.name))) return player_rank def _on_main_menu_select(menu, index, choice): if choice.value in _main_menu_selections: return _main_menu_selections[choice.value] main_menu = PagedMenu(title=strings['main_menu'], select_callback=_on_main_menu_select, data=[ PagedOption(strings['change_hero'], 1), PagedOption(strings['spend_skills'], 2), PagedOption(strings['hero_info'], 3), PagedOption(strings['warcraft_rank'], 4), PagedOption(strings['player_info'], 5) ]) change_hero = PagedMenu( title=strings['change_hero'], build_callback=_on_change_hero_build, select_callback=_on_change_hero_select, parent_menu=main_menu, ) spend_skills = PagedMenu( title=strings['spend_skills'], build_callback=_on_spend_skills_build,
) ## __all__ declaration __all__ = ("main_menu", ) ## callback declarations _main_menu_selections = [] def _on_main_menu_select(menu, index, choice): if choice.value < len(_main_menu_selections): if choice.value == 3: player_dict[index].update_race_data() return _main_menu_selections[choice.value] ## menu declarations main_menu = PagedMenu( title=home_menu_strings['header'], select_callback=_on_main_menu_select, data=[ PagedOption(shop_menu_strings['header'], 0), PagedOption(shopinfo_menu_strings['header'], 1), PagedOption(spendskills_menu_strings['header'], 2), PagedOption(changerace_menu_strings['header'], 3), PagedOption(raceinfo_menu_strings['header'], 4), PagedOption(playerinfo_menu_strings['header'], 5), ] )
def menu(cls): """Returns a menu with durations""" return PagedMenu(title=menus['Ban Duration'], build_callback=cls.build, select_callback=cls.select)
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) changerace_menu_cats = PagedMenu(title='Choose a category', build_callback=changerace_menu_cats_build, select_callback=changerace_menu_cats_select) def doCommand_cats(userid): index = index_from_userid(userid) allcats = get_cats() races = wcs.wcs.racedb.getAll() if len(allcats): changerace_menu_cats.send(index) def get_cats(): cat_list = [] for category in cats: cat_list.append(category) return cat_list def doCommand(userid):
menu.clear() menu.description = _tr['Credits'].get_string(credits=player.credits) menu.extend([ PagedOption(_tr['Upgrade Skills'], upgrade_skills_menu), PagedOption(_tr['Downgrade Skills'], downgrade_skills_menu), PagedOption(_tr['Stats'], stats_menu), ]) def _on_main_menu_select(menu, player_index, choice): """React to a main menu selection.""" player = _players[player_index] return choice.value main_menu = PagedMenu( title=_tr['Main Menu'], build_callback=_on_main_menu_build, select_callback=_on_main_menu_select, ) def _on_upgrade_skills_menu_build(menu, player_index): """Build the upgrade skills menu.""" player = _players[player_index] menu.clear() menu.description = _tr['Credits'].get_string(credits=player.credits) for skill in player.skills: text = _tr['Skill Text'].get_string(skill=skill, credits=skill.upgrade_cost) menu.append(PagedOption(text, skill)) def _on_upgrade_skills_menu_select(menu, player_index, choice): """React to an upgrade skills menu selection."""
) ) else: race_data = next(filter(lambda x: x.name == race_cls.name, player._dbinstance.races), None) menu.append( PagedOption( changerace_menu_strings['race_available'].get_string( name=race_cls.name, level=race_data.level if race_data else 0, max_level=race_cls.max_level ), race_cls, selectable=True ) ) def _on_change_race_select(menu, index, choice): player = player_dict[index] race_cls = choice.value if race_cls.name != player.race.name and race_cls.is_available(player): player.change_race(race_cls) return ## menu declarations change_race_menu = PagedMenu( title=changerace_menu_strings['header'], build_callback=_on_change_race_build, select_callback=_on_change_race_select, parent_menu=main_menu, )