コード例 #1
0
    def select_creature(self, creature_id):
        self.selected_creature = creature_id

        tab = ObjectManager.ui.right_panel.get_tabs()[0]
        tab.clear()

        creature = [
            creature for creature in ObjectManager.game.creatures
            if creature.id == self.selected_creature
        ]
        if not creature:
            return

        creature = creature[0]
        # TODO: Display how many turns passed (and maybe other info) as
        # description label

        # Only recal if creature current activity is adventure (not in a fight
        # or other sub-activity)
        if (creature.activity
                and creature.activity.activity == self.selected_adventure):
            button = Button('Recall', False)
            button.register_handler(creature.free)
            ObjectManager.ui.right_panel.add_button(tab, button)
        else:
            label = DescriptionLabel('Cannot recall', tab.rect.width)
            ObjectManager.ui.right_panel.add_label(tab, label)
コード例 #2
0
    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)
コード例 #3
0
    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)
コード例 #4
0
    def enter(self):
        super().enter()

        tab = ObjectManager.ui.left_panel.add_tab(True, 'Files', 1)
        buttons = []
        for save_file in os.listdir(os.path.abspath(Settings.SAVE_FOLDER)):
            button = Button(save_file, False)
            button.register_handler(partial(self.select_file, save_file))
            buttons.append(button)
        ObjectManager.ui.left_panel.add_buttons(tab, buttons)
コード例 #5
0
    def select_item(self, item):
        self.selected_item = item

        tab = ObjectManager.ui.right_panel.get_tabs()[0]
        tab.clear()
        label = DescriptionLabel(item.get_description(), tab.rect.width)
        ObjectManager.ui.right_panel.add_label(tab, label)

        button = Button('Eat', False)
        button.register_handler(ObjectManager.game.start_feeding)
        ObjectManager.ui.right_panel.add_button(tab, button)
コード例 #6
0
    def select_recipe(self, recipe):
        self.selected_recipe = recipe

        tab = ObjectManager.ui.right_panel.get_tabs()[0]
        tab.clear()
        label = DescriptionLabel(recipe.get_description(), tab.rect.width)
        ObjectManager.ui.right_panel.add_label(tab, label)
        if recipe.is_available(self.selected_creature):
            button = Button('Cook', False)
            button.register_handler(ObjectManager.game.start_cooking)
            ObjectManager.ui.right_panel.add_button(tab, button)
コード例 #7
0
    def select_adventure(self, adventure_template):
        self.selected_adventure = adventure_template

        tab = ObjectManager.ui.right_panel.get_tabs()[0]
        tab.clear()
        label = DescriptionLabel(self.selected_adventure.get_description(),
                                 tab.rect.width)
        ObjectManager.ui.right_panel.add_label(tab, label)
        if self.selected_adventure.is_available(self.selected_creature):
            button = Button('Start', False)
            button.register_handler(ObjectManager.game.start_adventure)
            ObjectManager.ui.right_panel.add_button(tab, button)
コード例 #8
0
    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)
コード例 #9
0
    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)
コード例 #10
0
    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)
コード例 #11
0
    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)
コード例 #12
0
    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)
コード例 #13
0
    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)
コード例 #14
0
    def select_item(self, item):
        self.selected_item = item

        tab = ObjectManager.ui.right_panel.get_tabs()[0]
        tab.clear()

        body_part = self.selected_item.body_part

        equiped = self.selected_creature.equipment[body_part]
        description = 'Equiped :\n\n'
        if equiped:
            description += equiped.get_description()
        else:
            description += 'Nothing'
        description += '\n\nSelected :\n\n{}'.format(
            self.selected_item.get_description())
        label = DescriptionLabel(description, tab.rect.width)
        ObjectManager.ui.right_panel.add_label(tab, label)

        button = Button('Equip', False)
        button.register_handler(ObjectManager.game.equip_item)
        ObjectManager.ui.right_panel.add_button(tab, button)
コード例 #15
0
    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)
コード例 #16
0
    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)
コード例 #17
0
class Dialog(object):
    border_margin = 3
    content_margin = 10

    def __init__(self, text, callback=None):
        self.displayed = True
        self.callback = callback

        document = pyglet.text.decode_text(text)
        document.set_style(0, len(text), dict(color=(255, 255, 255, 255)))
        self.text = pyglet.text.layout.TextLayout(document,
                                                  multiline=True,
                                                  wrap_lines=False)

        self.button = Button('Ok')

        width = self.text.content_width + self.content_margin * 2
        height = (self.text.content_height + self.button.rect.height +
                  self.content_margin * 4)
        x = Settings.WIDTH // 2 - width // 2
        y = Settings.HEIGHT // 2 - height // 2

        self.rect = ui.Rect(x - self.border_margin * 2,
                            y - self.border_margin * 2,
                            width + self.border_margin * 4,
                            height + self.border_margin * 4)
        self.border_rect = ui.Rect(x - self.border_margin,
                                   y - self.border_margin,
                                   width + self.border_margin * 2,
                                   height + self.border_margin * 2)
        self.border_rect.update_color((200, 200, 200))
        self.inner_rect = ui.Rect(x, y, width, height)

        self.text.x = x + self.content_margin
        self.text.y = y + self.button.rect.height + self.content_margin * 3

        self.button.set_pos(
            x + width - self.button.rect.width - self.content_margin,
            y + self.content_margin)
        self.button.register_handler(self.accepted)

    def mouse_motion(self, x, y):
        self.button.hover(x, y)

    def click(self, x, y):
        # Steal the mouse click focus from other panel by not checking rect
        # containning click
        if self.displayed:
            self.button.click(x, y)
            return True
        return False

    def accepted(self):
        self.displayed = False
        if callable(self.callback):
            self.callback()

    def draw(self):
        if self.displayed:
            self.rect.draw()
            self.border_rect.draw()
            self.inner_rect.draw()
            self.text.draw()
            self.button.draw()
コード例 #18
0
    def build_bottom_ui(self):
        tab = self.bottom_panel.add_tab(True, content_wrap=True)

        creature_button = Button('(c) Creatures')
        self.bottom_panel.add_button(tab, creature_button)

        inventory_button = Button('(i) Inventory')
        self.bottom_panel.add_button(tab, inventory_button)

        cook_button = Button('(o) Cook')
        self.bottom_panel.add_button(tab, cook_button)

        build_button = Button('(b) Build')
        self.bottom_panel.add_button(tab, build_button)

        feed_button = Button('(f) Feed')
        self.bottom_panel.add_button(tab, feed_button)

        equip_button = Button('(e) Equip')
        self.bottom_panel.add_button(tab, equip_button)

        mutate_button = Button('(m) Mutate')
        self.bottom_panel.add_button(tab, mutate_button)

        start_adventure_button = Button('(s) Start Adventure')
        self.bottom_panel.add_button(tab, start_adventure_button)

        current_adventures_button = Button('(u) Current Adventures')
        self.bottom_panel.add_button(tab, current_adventures_button)

        finish_turn_button = Button('(t) Finish Turn', False)
        self.bottom_panel.add_button(tab, finish_turn_button)

        load_button = Button('(l) Load', False)
        self.bottom_panel.add_button(tab, load_button)

        save_button = Button('(v) Save', False)
        self.bottom_panel.add_button(tab, save_button)

        # Callbacks
        creature_button.register_handler(
            partial(self.callback, UI_BUTTON.CREATURE))
        start_adventure_button.register_handler(
            partial(self.callback, UI_BUTTON.START_ADVENTURE))
        current_adventures_button.register_handler(
            partial(self.callback, UI_BUTTON.CURRENT_ADVENTURE))
        finish_turn_button.register_handler(
            partial(self.callback, UI_BUTTON.FINISH_TURN))
        inventory_button.register_handler(
            partial(self.callback, UI_BUTTON.INVENTORY))
        cook_button.register_handler(partial(self.callback, UI_BUTTON.COOK))
        feed_button.register_handler(partial(self.callback, UI_BUTTON.FEED))
        equip_button.register_handler(partial(self.callback, UI_BUTTON.EQUIP))
        load_button.register_handler(partial(self.callback, UI_BUTTON.LOAD))
        save_button.register_handler(partial(self.callback, UI_BUTTON.SAVE))