def initialize_items(self): servers = self.game.client.server_list if servers: for server in servers: label = self.shadow_text(server) yield MenuItem(label, None, None, None) else: label = self.shadow_text(trans('multiplayer_no_servers')) item = MenuItem(label, None, None, None) item.enabled = False yield item
def initialize_items(self): self.menu_items.columns = self.alphabet_length // 2 # add the keys for char in self.chars: yield MenuItem(self.shadow_text(char), None, None, partial(self.add_input_char, char)) # backspace key yield MenuItem(self.shadow_text("<="), None, None, self.backspace) # button to confirm the input and close the dialog yield MenuItem(self.shadow_text("END"), None, None, self.confirm)
def initialize_items(self): empty_image = None rect = self.game.screen.get_rect() slot_rect = pygame.Rect(0, 0, rect.width * 0.80, rect.height // 6) for i in range(self.number_of_slots): # Check to see if a save exists for the current slot if os.path.exists(prepare.SAVE_PATH + str(i + 1) + ".save"): image = self.render_slot(slot_rect, i + 1) yield MenuItem(image, "SAVE", None, None) else: if not empty_image: empty_image = self.render_empty_slot(slot_rect) yield MenuItem(empty_image, "SAVE", None, None)
def startup(self, *args, **kwargs): super(StartState, self).startup(*args, **kwargs) def change_state(state, **kwargs): return partial(self.game.push_state, state, **kwargs) def new_game(): self.game.player1 = prepare.player1 self.game.replace_state("WorldState") self.game.push_state("InputMenu", prompt=translator.translate("input_name")) self.game.push_state("FadeInTransition") def options(): pass def exit_game(): self.game.exit = True menu_items_map = ( ('menu_new_game', new_game), ('menu_load', change_state("LoadMenuState")), ('menu_options', options), ('exit', exit_game), ) for key, callback in menu_items_map: label = translator.translate(key).upper() image = self.shadow_text(label) item = MenuItem(image, label, None, callback) self.add(item)
def initialize_items(self): """ Get all player inventory items and add them to menu :return: """ inventory = self.game.player1.inventory.values() # required because the max() below will fail if inv empty if not inventory: return name_len = 17 # TODO: dynamically get this value, maybe? count_len = max(len(str(p['quantity'])) for p in inventory) # TODO: move this and other format strings to a locale or config file label_format = "{:<{name_len}} x {:>{count_len}}".format for properties in self.sort_inventory(inventory): obj = properties['item'] formatted_name = label_format(obj.name, properties['quantity'], name_len=name_len, count_len=count_len) image = self.shadow_text(formatted_name, bg=(128, 128, 128)) yield MenuItem(image, obj.name, obj.description, obj)
def initialize_items(self): # position the monster portrait try: monster = self.game.player1.monsters[self.selected_index] image = monster.sprites["front"] except IndexError: image = pygame.Surface((1, 1), pygame.SRCALPHA) # position and animate the monster portrait width, height = prepare.SCREEN_SIZE self.monster_portrait.rect = image.get_rect(centerx=width // 4, top=height // 12) self.sprites.add(self.monster_portrait) self.animate_monster_down() width = prepare.SCREEN_SIZE[0] // 2 height = prepare.SCREEN_SIZE[1] // (self.game.player1.party_limit * 1.5) # make 6 slots for i in range(self.game.player1.party_limit): rect = pygame.Rect(0, 0, width, height) surface = pygame.Surface(rect.size, pygame.SRCALPHA) try: monster = self.game.player1.monsters[i] except IndexError: monster = None item = MenuItem(surface, None, None, monster) self.render_monster_slot(surface, rect, monster, item.in_focus) yield item
def initialize_items(self): def change_state(state, **kwargs): return partial(self.game.replace_state, state, **kwargs) def exit_game(): # TODO: API self.game.done = True self.game.exit = True def battle(): self.game.pop_state(self) from core.components.event.actions.combat import Combat start_battle = partial(adapter("start_battle")) Combat().start_battle(self.game, start_battle(1)) def not_implemented_dialog(): open_dialog(self.game, ["This feature is not implemented."]) # Main Menu - Allows users to open the main menu in game. self.menu_items_map = OrderedDict( (('JOURNAL', battle), ('TUXEMON', change_state("MonsterMenuState")), ('BAG', change_state("ItemMenuState")), ('PLAYER', not_implemented_dialog), ('SAVE', change_state("SaveMenuState")), ('LOAD', change_state("LoadMenuState")), ('OPTIONS', not_implemented_dialog), ('EXIT', exit_game))) for label in self.menu_items_map.keys(): image = self.shadow_text(label) yield MenuItem(image, label, None, None)
def initialize_items(self): """ get all player items and update the items in the list """ for name, properties in self.game.player1.inventory.items(): obj = properties['item'] image = self.shadow_text(obj.name, bg=(128, 128, 128)) yield MenuItem(image, obj.name, obj.description, obj)
def initialize_items(self): def change_state(state, **kwargs): return partial(self.game.push_state, state, **kwargs) def new_game(): self.game.player1 = prepare.player1 state = self.game.replace_state("WorldState") self.game.push_state("FadeInTransition") def options(): pass def exit_game(): self.game.exit = True menu_items_map = ( ('NEW GAME', new_game), ('LOAD', change_state("LoadMenuState")), ('OPTIONS', options), ('EXIT', exit_game), ) for label, callback in menu_items_map: image = self.shadow_text(label) yield MenuItem(image, label, None, callback)
def initialize_items(self): menu_items_map = ( ('ACCEPT', self.accept), ('DECLINE', self.decline), ) for label, callback in menu_items_map: image = self.shadow_text(label) yield MenuItem(image, label, None, None, callback)
def initialize_items(self): menu_items_map = (('menu_fight', self.open_technique_menu), ('menu_monster', self.open_swap_menu), ('menu_item', self.open_item_menu), ('menu_run', self.run)) for key, callback in menu_items_map: label = translator.translate(key).upper() image = self.shadow_text(label) yield MenuItem(image, label, None, callback)
def build_item(self, label, callback, icon=None): """ Create a menu item and add it to the menu :param label: Some text :param icon: pygame surface (not used yet) :param callback: callback to use when selected :return: Menu Item """ image = self.shadow_text(label) item = MenuItem(image, label, None, callback) self.add(item)
def initialize_items(self): # get a ref to the combat state combat_state = self.game.get_state_name("CombatState") # TODO: trainer targeting # TODO: cleanup how monster sprites and whatnot are managed # TODO: This is going to work fine for simple matches, but controls will be wonky for parties # TODO: (cont.) Need better handling of cursor keys for 2d layouts of menu items # get all the monster positions # this is used to determine who owns what monsters and what not # TODO: make less duplication of game data in memory, let combat state have more registers, etc self.targeting_map = defaultdict(list) for player, monsters in combat_state.monsters_in_play.items(): for monster in monsters: # TODO: more targeting classes if player == self.player: targeting_class = "own monster" else: targeting_class = "enemy monster" self.targeting_map[targeting_class].append(monster) # TODO: handle odd cases where a situation creates no valid targets # if this target type is not handled by this action, then skip it if targeting_class not in self.action.target: continue # inspect the monster sprite and make a border image for it sprite = combat_state._monster_sprite_map[monster] item = MenuItem(None, None, None, monster) item.rect = sprite.rect.copy() center = item.rect.center item.rect.inflate_ip(tools.scale(16), tools.scale(16)) item.rect.center = center yield item
def initialize_items(self): # get a ref to the combat state combat_state = self.game.get_state_name("CombatState") # TODO: trainer targeting # TODO: cleanup how monster sprites and whatnot are managed # TODO: This is going to work fine for simple matches, but controls will be wonky for parties # TODO: (cont.) Need better handling of cursor keys for 2d layouts of menu items # get all the monster positions # this is used to determine who owns what monsters and what not # TODO: make less duplication of game data in memory, let combat state have more registers, etc self.targeting_map = defaultdict(list) for player, monsters in combat_state.monsters_in_play.items(): for monster in monsters: # TODO: more targeting classes if player == self.player: targeting_class = "own monster" else: targeting_class = "enemy monster" self.targeting_map[targeting_class].append(monster) # TODO: handle odd cases where a situation creates no valid targets # if this target type is not handled by this action, then skip it if targeting_class not in self.action.target: continue # inspect the monster sprite and make a border image for it sprite = combat_state._monster_sprite_map[monster] item = MenuItem(None, None, None, monster) item.rect = sprite.rect.copy() center = item.rect.center item.rect.inflate_ip(tools.scale(16), tools.scale(16)) item.rect.center = center yield item
def open_choice_menu(): # open the menu for use/cancel menu = self.game.push_state("Menu") menu.shrink_to_items = True menu_items_map = (('item_confirm_use', confirm), ('item_confirm_cancel', cancel)) # add our options to the menu for key, callback in menu_items_map: label = translator.translate(key).upper() image = self.shadow_text(label) item = MenuItem(image, label, None, callback) menu.add(item)
def choose_technique(): # open menu to choose technique menu = self.game.push_state("Menu") menu.shrink_to_items = True # add techniques to the menu for tech in self.monster.moves: image = self.shadow_text(tech.name) item = MenuItem(image, None, None, tech) menu.add(item) # position the new menu menu.anchor("bottom", self.rect.top) menu.anchor("right", self.game.screen.get_rect().right) # set next menu after after selection is made menu.on_menu_selection = choose_target
def initialize_items(self): """ Get all player inventory items and add them to menu :return: """ for name, properties in self.game.player1.inventory.items(): obj = properties['item'] quantity = properties['quantity'] # temporarily add the quantity to the name old_name = obj.name obj.name += " x " + str(quantity) image = self.shadow_text(obj.name, bg=(128, 128, 128)) yield MenuItem(image, obj.name, obj.description, obj) # restore the original name obj.name = old_name
def initialize_items(self): def change_state(state, **kwargs): return partial(self.game.replace_state, state, **kwargs) def multiplayer_menu(): # self.game.replace_state("MultiplayerMenu") open_dialog(self.game, ["Multiplayer not supported."]) self.menu_items_map = OrderedDict(( ('MONSTERS', change_state("MonsterMenuState")), ('ITEMS', change_state("ItemMenuState")), ('MULTIPLAYER', multiplayer_menu), ('LOG OFF', self.game.pop_state), )) for label in self.menu_items_map.keys(): image = self.shadow_text(label) yield MenuItem(image, label, None, None)
def choose_target(menu_item): # open menu to choose target of technique technique = menu_item.game_object combat_state = self.game.get_state_name("CombatState") state = self.game.push_state("CombatTargetMenuState", player=combat_state.players[0], user=self.monster, action=technique) #state.on_menu_selection = partial(enqueue_technique, technique) #state.change_selection(0); target = None for player, monsters in combat_state.monsters_in_play.items(): for monster in monsters: # TODO: more targeting classes if player != combat_state.players[0]: item = MenuItem(None, None, None, monster) target = item print(target) Timer(0.1, enqueue_technique, args=(technique, target)).start()
def initialize_items(self): self.monster = self.monster # hack: to quiet pycharm warnings def change_state(state, **kwargs): return partial(self.game.push_state, state, **kwargs) def run(): self.game.pop_state(self) combat_state.remove_player(combat_state.players[0]) # hack for now combat_state = self.game.get_state_name("CombatState") self.menu_items_map = OrderedDict(( ('FIGHT', self.open_technique_menu), ('TUXEMON', self.open_swap_menu), ('ITEM', change_state("ItemMenuState")), ('RUN', run) )) for label in self.menu_items_map.keys(): image = self.shadow_text(label) yield MenuItem(image, label, None, None)
def initialize_items(self): menu_items = ('USE', 'CANCEL') for label in menu_items: image = self.shadow_text(label) yield MenuItem(image, label, None, None)
def make_item(label): image = self.shadow_text(label) return MenuItem(image, label, None, None)
def initialize_items(self): for tech in self.monster.moves: image = self.shadow_text(tech.name) yield MenuItem(image, tech.name, None, tech)
def initialize_items(self): for key, label, callback in self.menu: image = self.shadow_text(label) item = MenuItem(image, label, None, callback) self.add(item)
def add_menu_items(state, items): for key, callback in items: label = translator.translate(key).upper() image = state.shadow_text(label) item = MenuItem(image, label, None, callback) state.add(item)