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(T.translate('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 ask_confirmation(): # open menu to confirm the save menu = self.client.push_state("Menu") menu.shrink_to_items = True # add choices yes = MenuItem(self.shadow_text(T.translate('save_overwrite')), None, None, positive_answer) no = MenuItem(self.shadow_text(T.translate('save_keep')), None, None, negative_answer) menu.add(yes) menu.add(no)
def initialize_items(self): empty_image = None rect = self.client.screen.get_rect() slot_rect = 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) item = MenuItem(image, T.translate('menu_save'), None, None) self.add(item) else: if not empty_image: empty_image = self.render_empty_slot(slot_rect) item = MenuItem(empty_image, "SAVE", None, None) self.add(item)
def initialize_items(self): """ Get all player inventory items and add them to menu :return: """ inventory = [ item for item in self.seller.inventory.values() if not (self.seller.isplayer and item['item'].sort == "quest") ] # 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_1 = "{:<{name_len}} x {:>{count_len}}".format label_format_2 = "{:<{name_len}}".format for properties in self.sort_inventory(inventory): obj = properties['item'] if properties.get('infinite'): label = label_format_2 else: label = label_format_1 formatted_name = label(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 = local_session.player.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.animations.empty() self.animate_monster_down() width = prepare.SCREEN_SIZE[0] // 2 height = prepare.SCREEN_SIZE[1] // (local_session.player.party_limit * 1.5) # make 6 slots for i in range(local_session.player.party_limit): rect = Rect(0, 0, width, height) surface = pygame.Surface(rect.size, pygame.SRCALPHA) item = MenuItem(surface, None, None, None) yield item self.refresh_menu_items()
def initialize_items(self): # TODO: move this and other format strings to a locale or config file label_format = "x {:>{count_len}}".format count_len = 3 formatted_name = label_format(self.quantity, count_len=count_len) image = self.shadow_text(formatted_name, bg=(128, 128, 128)) yield MenuItem(image, formatted_name, None, None)
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 = T.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.client.get_state_by_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.client.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 = T.translate(key).upper() image = self.shadow_text(label) item = MenuItem(image, label, None, callback) menu.add(item)
def startup(self, *args, **kwargs): # If there is a save, then move the cursor to "Load game" first index = get_index_of_latest_save() kwargs['selected_index'] = 0 if index is None else 1 super(StartState, self).startup(*args, **kwargs) def change_state(state, **change_state_kwargs): return partial(self.client.push_state, state, **change_state_kwargs) def set_player_name(text): local_session.player.name = text def new_game(): # load the starting map state = self.client.replace_state("WorldState") map_name = prepare.fetch("maps", prepare.CONFIG.starting_map) state.change_map(map_name) self.client.push_state( state_name="InputMenu", prompt=T.translate("input_name"), callback=set_player_name, escape_key_exits=False, ) self.client.push_state("FadeInTransition") def options(): pass def exit_game(): self.client.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 = T.translate(key).upper() image = self.shadow_text(label) item = MenuItem(image, label, None, callback) self.add(item)
def choose_technique(): # open menu to choose technique menu = self.client.push_state("Menu") menu.shrink_to_items = True # add techniques to the menu for tech in self.monster.moves: if tech.next_use <= 0: image = self.shadow_text(tech.name) else: image = self.shadow_text("%s %d" % (tech.name, abs(tech.next_use)), fg=self.unavailable_color) item = MenuItem(image, None, None, tech) menu.add(item) # position the new menu menu.anchor("bottom", self.rect.top) menu.anchor("right", self.client.screen.get_rect().right) # set next menu after after selection is made menu.on_menu_selection = choose_target
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 = T.translate(key).upper() image = state.shadow_text(label) item = MenuItem(image, label, None, callback) state.add(item)