示例#1
0
    def __init__(self, screen, resolution, game, name="Monster Menu"):

        # Initialize the parent menu class's default shit
        Menu.__init__(self, screen, resolution, name)
        
        # Give this menu instance access to the main game object.
        self.game = game
        
        # Set the background color of our menu
        self.color = (32, 104, 96)

        # Load the item menu background image
        _resources = "resources/gfx/ui/monster/"
        self.background_image = _resources + "monster_menu_bg.png"
        self.background_surface = pygame.image.load(self.background_image).convert()
        self.background_surface = pygame.transform.scale(self.background_surface,
            (prepare.SCREEN_SIZE[0], prepare.SCREEN_SIZE[1]))
        

        # Create the item menu's submenus.
        self.active_monster_menu = Menu(screen, resolution, game)
        self.inactive_monsters_menu = Menu(screen, resolution, game)
        self.decision_menu = Menu(screen, resolution, game)
        self.monster_slots = []
        self.monster_hp_bars = []

        # Create a submenu for each monster slot
        from core.components import menu
        for monster_number in range(0, self.game.player1.party_limit):
            self.monster_slots.append(Menu(screen,
                                           resolution,
                                           game,
                                           background=_resources + "filled_monster_slot_bg.png"))
            self.monster_hp_bars.append(menu.interface.HpBar(screen))

        # Set up the border images used for the monster slots
        self.monster_slot_border = {}
        _border_types = ["empty", "filled", "active"]
        _borders = ["left", "right", "top", "bottom", "left-top",
                    "left-bottom", "right-top", "right-bottom", "bg"]
        for border_type in _border_types:
            self.monster_slot_border[border_type] = {}
            for item in _borders:
                img = pygame.image.load(
                    _resources + border_type + "_monster_slot_" + item + ".png").convert()
                self.monster_slot_border[border_type][item] = img

            # Scale the borders according to the game's scale.
            self.monster_slot_border[border_type] = self.scale_borders(
                self.monster_slot_border[border_type])

        # Add the submenus as this menu's children
        self.add_child(self.active_monster_menu)
        self.add_child(self.inactive_monsters_menu)
        self.add_child(self.decision_menu)

        # Set up border images for both inactive and active slots.
        for monster_slot in self.monster_slots:
            self.add_child(monster_slot)

        # Scale the sides of all the submenus
        for menu in self.children:
            # Scale the font and selection arrow to the appropriate size.
            menu.font = pygame.font.Font(
                "resources/font/PressStart2P.ttf", menu.font_size * prepare.SCALE)
            menu.arrow = pygame.transform.scale(
                menu.arrow, 
                (menu.arrow.get_width() * prepare.SCALE, menu.arrow.get_height() * prepare.SCALE))

            # Scale the window's borders based on the game's scale.
            menu.border = menu.scale_borders(menu.border)

        # Set up our submenus.
        self.decision_menu.size_x = prepare.SCREEN_SIZE[0] / 5
        self.decision_menu.size_y = prepare.SCREEN_SIZE[1] / 6
        self.decision_menu.pos_x = prepare.SCREEN_SIZE[0] - self.decision_menu.size_x - \
            (self.decision_menu.border["left-top"].get_height() * 2)
        self.decision_menu.pos_y = prepare.SCREEN_SIZE[1] - self.decision_menu.size_y - \
            (self.decision_menu.border["left-top"].get_height() * 2)
        self.decision_menu.visible = False
        self.decision_menu.interactable = False

        # Set the positions of our monster slots
        slot_x = (prepare.SCREEN_SIZE[0] / 2) - (self.monster_slots[0].border['left'].get_width() * 2)
        slot_y = (prepare.SCREEN_SIZE[1] / 10)
        for monster_slot in self.monster_slots:
            monster_slot.size_x = int(prepare.SCREEN_SIZE[0] / 2)
            monster_slot.size_y = int(prepare.SCREEN_SIZE[1] /
                (self.game.player1.party_limit * 2 + 2))
            monster_slot.pos_x = slot_x
            monster_slot.pos_y = slot_y

            spacing = int(8 * prepare.SCALE) + monster_slot.size_y
            slot_y += spacing

        self.selected_monster = None
示例#2
0
    def __init__(self, screen, resolution, game, name="Item Menu"):

        # Initialize the parent menu class's default shit
        Menu.__init__(self, screen, resolution, name)

        # Give this menu instance access to the main game object.
        self.game = game

        # Set the background color of our menu
        self.color = (32, 104, 96)

        # Load the item menu background image
        self.background_image = prepare.BASEDIR + "resources/gfx/ui/item/item_menu_bg.png"
        self.background_surface = pygame.image.load(
            self.background_image).convert()
        self.background_surface = pygame.transform.scale(
            self.background_surface,
            (prepare.SCREEN_SIZE[0], prepare.SCREEN_SIZE[1]))

        # Create the item menu's submenus.
        self.decision_menu = Menu(screen, resolution, game)
        self.item_list = Menu(screen, resolution, game)
        self.info_menu = Menu(screen, resolution, game)

        # Add the submenus as this menu's children
        self.add_child(self.decision_menu)
        self.add_child(self.item_list)
        self.add_child(self.info_menu)

        # Scale the sides of all the submenus
        for menu in self.children:

            # Scale the font and selection arrow to the appropriate size.
            menu.font = pygame.font.Font(
                prepare.BASEDIR + "resources/font/PressStart2P.ttf",
                menu.font_size * prepare.SCALE)
            menu.arrow = pygame.transform.scale(
                menu.arrow, (menu.arrow.get_width() * prepare.SCALE,
                             menu.arrow.get_height() * prepare.SCALE))

            # Scale the window's borders based on the game's scale.
            for key, border in menu.border.items():
                menu.border[key] = pygame.transform.scale(
                    border, (border.get_width() * prepare.SCALE,
                             border.get_height() * prepare.SCALE))

        # Set up our submenus.
        self.decision_menu.size_x = prepare.SCREEN_SIZE[0] / 5
        self.decision_menu.size_y = prepare.SCREEN_SIZE[1] / 6
        self.decision_menu.pos_x = prepare.SCREEN_SIZE[0] - self.decision_menu.size_x - \
            (self.decision_menu.border["left-top"].get_height() * 2)
        self.decision_menu.pos_y = prepare.SCREEN_SIZE[1] - self.decision_menu.size_y - \
            (self.decision_menu.border["left-top"].get_height() * 2)
        self.decision_menu.visible = False
        self.decision_menu.interactable = False

        self.info_menu.size_x = prepare.SCREEN_SIZE[0]
        self.info_menu.size_y = int(prepare.SCREEN_SIZE[1] / 4.2)
        self.info_menu.pos_x = 0
        self.info_menu.pos_y = prepare.SCREEN_SIZE[1] - self.info_menu.size_y
        #self.info_menu.color = (0, 120, 192)
        self.info_menu.visible = True
        self.info_menu.interactable = False

        self.item_list.size_x = int((prepare.SCREEN_SIZE[0] / 3) * 2)
        self.item_list.size_y = int(prepare.SCREEN_SIZE[1] -
                                    self.info_menu.size_y)
        self.item_list.pos_x = int(prepare.SCREEN_SIZE[0] / 3)
        self.item_list.pos_y = 0
        self.item_list.visible = True
        self.item_list.interactable = True

        # Load the backpack icon
        self.backpack = {}
        self.backpack[
            'image'] = prepare.BASEDIR + "resources/gfx/ui/item/backpack.png"
        self.backpack['surface'] = pygame.image.load(
            self.backpack['image']).convert_alpha()
        self.backpack['surface'] = pygame.transform.scale(
            self.backpack['surface'],
            (self.backpack['surface'].get_width() * prepare.SCALE,
             self.backpack['surface'].get_height() * prepare.SCALE))
        self.backpack['pos_x'] = (self.item_list.pos_x / 2) - \
            (self.backpack['surface'].get_width() / 2)
        self.backpack['pos_y'] = prepare.SCREEN_SIZE[1] - self.info_menu.size_y - \
            (self.backpack['surface'].get_height() * 1.2)