Exemple #1
0
def get_winners_menu(player):
    """Return a sorted menu of all winners."""
    menu = PagedMenu(title=menu_strings['Winners:Title'])
    if not winners_database:
        menu.description = menu_strings['Winners:None']
        return menu

    winners = sorted(
        winners_database,
        key=lambda key: (
            winners_database[key].wins,
            -winners_database[key].time_stamp,
        ),
        reverse=True,
    )
    for rank, unique_id in enumerate(winners, 1):
        instance = winners_database[unique_id]
        menu.append(
            ListOption(
                choice_index=rank,
                text='{name} [{wins}]'.format(
                    name=instance.name,
                    wins=instance.wins
                ),
                value=unique_id,
                highlight=player.uniqueid == unique_id,
                selectable=False,
            )
        )
    return menu
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)
Exemple #3
0
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'])
Exemple #4
0
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)
Exemple #5
0
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)
Exemple #6
0
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')
Exemple #7
0
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!")
Exemple #8
0
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)
Exemple #9
0
    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
Exemple #10
0
 def menu(cls):
     """Return the menu object"""
     return PagedMenu(
         title=cls.caption,
         build_callback=cls.build,
         select_callback=cls.select
     )
Exemple #11
0
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'])
Exemple #12
0
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)
Exemple #13
0
    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__()
Exemple #14
0
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)
Exemple #15
0
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_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)
Exemple #17
0
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)
Exemple #19
0
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)
Exemple #20
0
def send_score_menu(index):
    """Send the score menu to the player."""
    menu = PagedMenu(title=menu_strings['Score:Title'])
    player = Player(index)
    if 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,
                    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)
Exemple #21
0
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, 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__()
Exemple #23
0
    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)
Exemple #24
0
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)
Exemple #25
0
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 _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)
Exemple #27
0
 def menu(cls):
     """Returns a menu with durations"""
     return PagedMenu(title=menus['Ban Duration'],
                      build_callback=cls.build,
                      select_callback=cls.select)
Exemple #28
0
    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."""
Exemple #29
0
        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)

Exemple #30
0
 def menu(cls):
     return PagedMenu(title=menus['Ban Reasons'],
                      build_callback=cls.build,
                      select_callback=cls.select)
Exemple #31
0

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,
)
Exemple #32
0
    wire_menu.close()


# =============================================================================
# >> MENU CALLBACKS
# =============================================================================
def bomb_choice(menu, index, option):
    """Cut the chosen wire."""
    cut_chosen_wire(option.value, PlayerEntity(index))


# =============================================================================
# >> MENU CREATION
# =============================================================================
# Create the wire cut menu
wire_menu = PagedMenu(
    description=wire_strings['Title'], select_callback=bomb_choice)

# Loop through all choices of wire colors
for _color in _colors:

    # Add the color to the menu
    wire_menu.append(PagedOption(wire_strings[_color], _color))


# =============================================================================
# >> HELPER FUNCTIONS
# =============================================================================
def get_bomb_entity():
    """Return the bomb's BaseEntity instance."""
    for entity in EntityIter('planted_c4', return_types='entity'):
        return entity
Exemple #33
0
        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))

Exemple #34
0
)

## __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),
    ]
)
class _SettingsDictionary(OrderedDict):
    """Class used to store user settings."""

    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 __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 add_int_setting(
            self, name, default, text=None, min_value=None, max_value=None):
        """Add a new integer setting to the dictionary."""
        self[name] = IntegerSetting(name, default, text, min_value, max_value)
        return self[name]

    def add_bool_setting(self, name, default, text=None):
        """Add a new boolean setting to the dictionary."""
        self[name] = BoolSetting(name, default, text)
        return self[name]

    def add_string_setting(self, name, default, text=None):
        """Add a new string setting to the dictionary."""
        self[name] = StringSetting(name, default, text)
        return self[name]

    def add_section(self, name, text=None):
        """Add a new section to the dictionary."""
        self[name] = _SettingsDictionary(name, text)
        return self[name]

    @staticmethod
    def _chosen_item(menu, index, option):
        """Called when an item is chosen from the instance's menu."""
        # Is the chosen value another branch of settings?
        if isinstance(option.value, _SettingsDictionary):

            # Send the new menu
            option.value.menu.send(index)

            # No need to go further
            return

        # TODO: Placeholder for sending setting specific menus
        option.value.menu.send(index)
 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'])
Exemple #37
0
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)
Exemple #38
0
    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,
Exemple #39
0
		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):
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)
Exemple #41
0
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)
Exemple #42
0
def _on_admin_players_choose(menu, index, choice):
    player, amount = choice.value
    if amount > 0:
        player.race.level_up(amount)
    else:
        player.race.level_down(amount * -1)
    return menu


def _on_admin_menu_select(menu, index, choice):
    return _admin_menu_options[choice.value]


## menu declarations

admin_menu = PagedMenu(title=admin_menu_strings['header'],
                       select_callback=_on_admin_menu_select,
                       data=[PagedOption(admin_menu_strings['players'], 0)])

admin_player_menu = PagedMenu(
    title=admin_menu_strings['players'],
    build_callback=_on_admin_players_build,
    select_callback=_on_admin_players_select,
    parent_menu=admin_menu,
)

player_menu = PagedMenu(select_callback=_on_admin_players_choose,
                        parent_menu=admin_player_menu)

_admin_menu_options = [admin_player_menu]
                )
            )
        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,
)