def select_adventure(self, adventure_template): self.selected_adventure = adventure_template creatures = [ creature for creature in ObjectManager.game.creatures if creature.activity.activity_type == ACTIVITY_TYPE.ADVENTURE and creature.activity.template == adventure_template ] if (creatures and (self.selected_creature is None or self.selected_creature not in [creature.id for creature in creatures])): self.selected_creature = creatures[0].id tab = ObjectManager.ui.central_panel.get_tabs()[0] tab.clear() buttons = [] for creature in creatures: name = creature.name button = Button(name) button.register_handler(partial(self.select_creature, creature.id)) buttons.append(button) button.pressed = (creature.id == self.selected_creature) ObjectManager.ui.central_panel.add_buttons(tab, buttons) self.select_creature(self.selected_creature)
def enter(self): super().enter() # Left panel tab = ObjectManager.ui.left_panel.add_tab(True, 'Adventures', 1) buttons = [] for adventure_template in ObjectManager.game.adventure_templates: count = len([ creature for creature in ObjectManager.game.creatures if creature.busy and creature.activity.activity_type == ACTIVITY_TYPE.ADVENTURE and creature.activity.template == adventure_template ]) if count == 0: continue button = Button('{} ({})'.format(adventure_template.title, count)) button.register_handler( partial(self.select_adventure, adventure_template)) buttons.append(button) button.pressed = (adventure_template == self.selected_adventure) ObjectManager.ui.left_panel.add_buttons(tab, buttons) # Central panel ObjectManager.ui.central_panel.add_tab(True, 'Creatures', 1) # Right panel ObjectManager.ui.right_panel.add_tab(True, 'Description', 1) if self.selected_adventure: self.select_adventure(self.selected_adventure)
def select_creature(self, creature): self.selected_creature = creature tab = ObjectManager.ui.central_panel.get_tabs()[0] tab.clear() # TODO: Put weapons and armors in different tabs # TODO: Instead of filtering out equiped item, show them greyed out # and ask the user if they want to unequip it for the original creature # to equip it to the selected one weapons = [ item for item in ObjectManager.game.inventory.get_items( ITEM_CATEGORY.WEAPON) if not item.equiped ] if self.selected_item is None and weapons: self.selected_item = weapons[0] buttons = [] for item in weapons: name = item.name button = Button(name) button.register_handler(partial(self.select_item, item)) buttons.append(button) button.pressed = (item == self.selected_item) armors = [ item for item in ObjectManager.game.inventory.get_items( ITEM_CATEGORY.ARMOR) if not item.equiped ] for item in armors: name = item.name button = Button(name) button.register_handler(partial(self.select_item, item)) buttons.append(button) button.pressed = (item == self.selected_item) ObjectManager.ui.central_panel.add_buttons(tab, buttons) if self.selected_item is not None: self.select_item(self.selected_item)
def enter(self): super().enter() tab = ObjectManager.ui.left_panel.add_tab(True, 'Categories', 1) ObjectManager.ui.central_panel.add_tab(True, 'Items', 1) ObjectManager.ui.right_panel.add_tab(True, 'Description', 1) if self.selected_category is None: self.selected_category = ITEM_CATEGORY.FOOD for category in ITEM_CATEGORY: button = Button(category.value) button.register_handler(partial(self.select_category, category)) ObjectManager.ui.left_panel.add_button(tab, button) button.pressed = (self.selected_category == category) self.select_category(self.selected_category)
def enter(self): super().enter() self.selected_creature = None self.selected_adventure = None ObjectManager.ui.central_panel.add_tab(True, 'Adventures', 1) ObjectManager.ui.right_panel.add_tab(True, 'Description', 1) # Left panel tab = ObjectManager.ui.left_panel.add_tab(True, 'Creatures', 1) buttons = [] for creature in ObjectManager.game.creatures: name = creature.name button = Button(name) button.register_handler(partial(self.select_creature, creature)) buttons.append(button) button.pressed = (creature == self.selected_creature) ObjectManager.ui.left_panel.add_buttons(tab, buttons)
def select_creature(self, creature): self.selected_creature = creature tab = ObjectManager.ui.central_panel.get_tabs()[0] tab.clear() buttons = [] for adventure_template in ObjectManager.game.adventure_templates: count = len([ creature for creature in ObjectManager.game.creatures if creature.busy and creature.activity.activity_type == ACTIVITY_TYPE.ADVENTURE and creature.activity.template == adventure_template ]) button = Button('{} ({})'.format(adventure_template.title, count)) button.register_handler( partial(self.select_adventure, adventure_template)) buttons.append(button) button.pressed = (adventure_template == self.selected_adventure) ObjectManager.ui.central_panel.add_buttons(tab, buttons)
def select_creature(self, creature): self.selected_creature = creature food = ObjectManager.game.inventory.get_items(ITEM_CATEGORY.FOOD) if self.selected_item is None and food: self.selected_item = food[0] tab = ObjectManager.ui.central_panel.get_tabs()[0] tab.clear() buttons = [] for item in food: name = item.name button = Button(name) button.register_handler(partial(self.select_item, item)) buttons.append(button) button.pressed = (item == self.selected_item) ObjectManager.ui.central_panel.add_buttons(tab, buttons) if self.selected_item is not None: self.select_item(self.selected_item)
def enter(self): super().enter() ObjectManager.ui.central_panel.add_tab(True, "Items", 1) ObjectManager.ui.right_panel.add_tab(True, "Compare", 1) if self.selected_creature is None and ObjectManager.game.creatures: self.selected_creature = ObjectManager.game.creatures[0] tab = ObjectManager.ui.left_panel.add_tab(True, 'Creatures', 1) buttons = [] for creature in ObjectManager.game.creatures: name = creature.name button = Button(name) button.register_handler(partial(self.select_creature, creature)) buttons.append(button) button.pressed = (creature == self.selected_creature) ObjectManager.ui.left_panel.add_buttons(tab, buttons) if self.selected_creature is not None: self.select_creature(self.selected_creature)
def select_creature(self, creature): self.selected_creature = creature recipes = ObjectManager.game.inventory.get_recipes() if self.selected_recipe is None and recipes: self.selected_recipe = recipes[0] tab = ObjectManager.ui.central_panel.get_tabs()[0] tab.clear() buttons = [] # TODO: Display available recipes first then rest greyed out # recipe may not be available due to muissing ingredients or low # creature cooking skills for recipe in ObjectManager.game.inventory.get_recipes(): name = recipe.name button = Button(name) button.register_handler(partial(self.select_recipe, recipe)) buttons.append(button) button.pressed = (recipe == self.selected_recipe) ObjectManager.ui.central_panel.add_buttons(tab, buttons) self.select_recipe(self.selected_recipe)
def select_category(self, category): self.selected_category = category items = ObjectManager.game.inventory.get_items(self.selected_category) items = sorted(items, key=lambda item: item.name) if (items and (self.selected_item is None or self.selected_item not in [item.name for item in items])): self.selected_item = items[0].name elif not items: self.selected_item = None tab = ObjectManager.ui.central_panel.get_tabs()[0] tab.clear() buttons = [] for item in items: button = Button(item.name) button.register_handler(partial(self.select_item, item.name)) button.pressed = (item.name == self.selected_item) buttons.append(button) ObjectManager.ui.central_panel.add_buttons(tab, buttons) self.select_item(self.selected_item)