def __init__(self, screen, resolution, game, name="Dialog Menu"): # Initialize the parent menu class's default shit Menu.__init__(self, screen, resolution, game, name) self.delay = 0.5 self.elapsed_time = self.delay self.dialog_stack = []
def __init__(self, screen, resolution, game, name="Main Menu"): # Initialize the parent menu class's default shit Menu.__init__(self, screen, resolution, game, name) self.first_run = True self.save = False self.state = "closed" self.visible = False #self.menu_icons_paths = ['resources/gfx/ui/menu/journal.png', # 'resources/gfx/ui/menu/tuxemon.png', # 'resources/gfx/ui/menu/backpack.png', # 'resources/gfx/ui/menu/player.png', # 'resources/gfx/ui/menu/save.png', # 'resources/gfx/ui/menu/load.png', # 'resources/gfx/ui/menu/settings.png', # 'resources/gfx/ui/menu/exit.png',] # Load all the menu icon images #for path in self.menu_icons_paths: # icon_surface = pygame.image.load(path).convert_alpha() # icon_surface = pygame.transform.scale(icon_surface, (icon_surface.get_width() * prepare.SCALE, icon_surface.get_height() * prepare.SCALE)) # self.menu_icons.append(icon_surface) self.menu_select_sound = mixer.Sound( "resources/sounds/interface/50561__broumbroum__sf3-sfx-menu-select.ogg")
def __init__(self, screen, resolution, game, name="SUCCESS"): # Initialize the parent menu class's default shit Menu.__init__(self, screen, resolution, game, name) self.delay = 0.5 self.elapsed_time = self.delay self.text = ["Joining. Please wait..."]
def __init__(self, screen, resolution, game, name="Main Menu"): # Initialize the parent menu class's default shit Menu.__init__(self, screen, resolution, game, name) self.first_run = True self.save = False self.state = "closed" self.visible = False #self.menu_icons_paths = ['resources/gfx/ui/menu/journal.png', # 'resources/gfx/ui/menu/tuxemon.png', # 'resources/gfx/ui/menu/backpack.png', # 'resources/gfx/ui/menu/player.png', # 'resources/gfx/ui/menu/save.png', # 'resources/gfx/ui/menu/load.png', # 'resources/gfx/ui/menu/settings.png', # 'resources/gfx/ui/menu/exit.png',] # Load all the menu icon images #for path in self.menu_icons_paths: # icon_surface = pygame.image.load(path).convert_alpha() # icon_surface = pygame.transform.scale(icon_surface, (icon_surface.get_width() * prepare.SCALE, icon_surface.get_height() * prepare.SCALE)) # self.menu_icons.append(icon_surface) self.menu_select_sound = mixer.Sound( prepare.BASEDIR + "resources/sounds/interface/50561__broumbroum__sf3-sfx-menu-select.ogg" )
def __init__(self, screen, resolution, game, name="Save Menu"): Menu.__init__(self, screen, resolution, game, name) self.slots = 3 self.selected_menu_item = 0 self.slot_surfaces = {} self.save_data = {} self.first_run = True
def __init__(self, screen, resolution, game, name="HOSTING"): # Initialize the parent menu class's default shit Menu.__init__(self, screen, resolution, game, name) self.delay = 0.5 self.elapsed_time = self.delay self.text = ["Server started:"] for ip in self.game.server.ips: self.text.append(ip)
def __init__(self, screen, resolution, game, name="Interaction Menu"): # Initialize the parent menu class's default shit Menu.__init__(self, screen, resolution, game, name) self.first_run = True self.save = False self.state = "closed" self.visible = False self.menu_select_sound = mixer.Sound( prepare.BASEDIR + "resources/sounds/interface/50561__broumbroum__sf3-sfx-menu-select.ogg")
def draw(self, draw_borders=True, fill_background=False): # We can call the draw function from our parent "Menu" class, and also draw # some additional stuff specifically for the Item Menu. Menu.draw(self, draw_borders, fill_background) # Draw our background image. self.screen.blit(self.background_surface, (0,0)) # Draw the backpage icon. self.screen.blit(self.backpack['surface'], (self.backpack['pos_x'], self.backpack['pos_y'])) # If the item list submenu is visible, draw it and its menu items. if self.item_list.visible: self.item_list.draw(draw_borders=False, fill_background=False) items = [] for item_name, item_details in self.game.player1.inventory.items(): items.append(item_name) #self.item_list.line_spacing = 250 self.item_list.draw_textItem(items, pos_y=prepare.SCREEN_SIZE[1]/10, paging=True) # If the info submenu is visible, draw it and its menu items. if self.info_menu.visible: self.info_menu.draw(draw_borders=False, fill_background=True) # Draw the image of the currently selected item. if len(self.item_list.menu_items) > 0: # Get the selected item's description text and draw it on the info menu. selected_item_name = self.item_list.menu_items[self.item_list.selected_menu_item] info_text = self.game.player1.inventory[selected_item_name]['item'].description self.info_menu.draw_text(info_text, justify="center", align="middle") current_item_surface = self.game.player1.inventory[selected_item_name]['item'].surface # Scale the item's sprite if it hasn't been scaled already. if (prepare.SCALE != 1 and current_item_surface.get_size() == self.game.player1.inventory[selected_item_name]['item'].surface_size_original): self.game.player1.inventory[selected_item_name]['item'].surface = pygame.transform.scale( current_item_surface, (current_item_surface.get_width() * prepare.SCALE, current_item_surface.get_height() * prepare.SCALE)) # Position the item's sprite in the middle of the left-hand part of the item list. item_pos_x = (self.item_list.pos_x / 2) - (current_item_surface.get_width() / 2) self.screen.blit(current_item_surface, (item_pos_x,0)) # If the decision submenu is visible, draw it and its menu items. if self.decision_menu.visible: self.decision_menu.draw() self.decision_menu.draw_textItem(["Use", "Cancel"], 1, autoline_spacing=True)
def draw(self, draw_borders=False, fill_background=False): # We can call the draw function from our parent "Menu" class, and also draw # some additional stuff specifically for the Monster Menu. Menu.draw(self, draw_borders, fill_background) # Draw our background image. self.screen.blit(self.background_surface, (0,0)) # Draw our empty monster slots. monster_index = 0 for monster_slot in self.monster_slots: # If a monster exists in this slot, populate information about it. if monster_index < len(self.game.player1.monsters): hp_bar = self.monster_hp_bars[monster_index] if monster_index == self.selected_menu_item: monster_slot.border = self.monster_slot_border["active"] monster_slot.background = self.monster_slot_border["active"]["bg"] else: monster_slot.border = self.monster_slot_border["filled"] monster_slot.background = self.monster_slot_border["filled"]["bg"] monster_slot.draw(fill_background=True) monster = self.game.player1.monsters[monster_index] # Draw the HP bar hp_bar.monster = monster hp_bar.x = monster_slot.pos_x + (monster_slot.size_x - hp_bar.surface.get_width()) hp_bar.y = monster_slot.pos_y + int((hp_bar.height / 2)) hp_bar.draw() # Draw the text on the monster slot line_spacing = (monster_slot.font_size * prepare.SCALE) + monster_slot.line_spacing monster_slot.draw_text(monster.name) monster_slot.draw_text(" Lv " + str(monster.level), pos_y=line_spacing) else: monster_slot.border = self.monster_slot_border["empty"] monster_slot.draw(fill_background=False) monster_index += 1 # Draw the currently active monster if len(self.game.player1.monsters) > 0: active_monster = self.game.player1.monsters[self.selected_menu_item] active_monster.load_sprites(prepare.SCALE) active_monster_x = int(prepare.SCREEN_SIZE[0] / 4) - \ (active_monster.sprites["front"].get_width() / 2) active_monster_y = int(prepare.SCREEN_SIZE[1] / 12) active_monster_pos = (active_monster_x, active_monster_y) self.screen.blit(active_monster.sprites["front"], active_monster_pos)
def __init__(self, screen, resolution, game, name="Bottom Menu"): # Initialize the parent menu class's default shit Menu.__init__(self, screen, resolution, game, name) # Adding static variables for menus for the bottom 1/2 of the screen # (mainly for states.combat) self.difference_x = ((resolution[0]/4)) self.difference_y = ((resolution[1]/4)) # Native resolution is similar to the old gameboy resolution. This is used for scaling. self.native_resolution = [240, 160] # Scaling the shit outa those menus! self.scale = int( (resolution[0] / self.native_resolution[0]) ) for picture, border in self.border.items(): self.border[picture] = pygame.transform.scale(border, (border.get_width() * self.scale, border.get_height() * self.scale) ) self.difference = self.border["left-top"].get_width()
def __init__(self, screen, resolution, game, name="Bottom Menu"): # Initialize the parent menu class's default shit Menu.__init__(self, screen, resolution, game, name) # Adding static variables for menus for the bottom 1/2 of the screen # (mainly for states.combat) self.difference_x = ((resolution[0] / 4)) self.difference_y = ((resolution[1] / 4)) # Native resolution is similar to the old gameboy resolution. This is used for scaling. self.native_resolution = [240, 160] # Scaling the shit outa those menus! self.scale = int((resolution[0] / self.native_resolution[0])) for picture, border in self.border.items(): self.border[picture] = pygame.transform.scale( border, (border.get_width() * self.scale, border.get_height() * self.scale)) self.difference = self.border["left-top"].get_width()
def __init__(self, screen, resolution, game, name="JOIN_ENTER_IP"): # Stuff from the parent menu Menu.__init__(self, screen, resolution, game, name) self.delay = 0.5 self.elapsed_time = self.delay
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)
class ItemMenu(Menu): """A class to create item menu objects. The item menu allows you to view and use items in your inventory. :param screen: The pygame.display surface to draw the menu to. :param resolution: A tuple of the display's resolution in (x, y) format. TODO: We should be able to get this from pygame.display :param game: The main tuxemon game object that contains all the game's variables. :type screen: pygame.display :type resolution: Tuple :type game: core.tools.Control To create a new menu, simply create a new menu instance and then set the size and coordinates of the menu like this: Example: >>> item_menu = ItemMenu(screen, resolution, self) >>> item_menu.size_x = 200 >>> item_menu.size_y = 100 >>> item_menu.pos_x = 500 >>> item_menu.pos_y = 500 >>> item_menu.draw() """ 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) def draw(self, draw_borders=True, fill_background=False): # We can call the draw function from our parent "Menu" class, and also draw # some additional stuff specifically for the Item Menu. Menu.draw(self, draw_borders, fill_background) # Draw our background image. self.screen.blit(self.background_surface, (0,0)) # Draw the backpage icon. self.screen.blit(self.backpack['surface'], (self.backpack['pos_x'], self.backpack['pos_y'])) # If the item list submenu is visible, draw it and its menu items. if self.item_list.visible: self.item_list.draw(draw_borders=False, fill_background=False) items = [] for item_name, item_details in self.game.player1.inventory.items(): items.append(item_name) #self.item_list.line_spacing = 250 self.item_list.draw_textItem(items, pos_y=prepare.SCREEN_SIZE[1]/10, paging=True) # If the info submenu is visible, draw it and its menu items. if self.info_menu.visible: self.info_menu.draw(draw_borders=False, fill_background=True) # Draw the image of the currently selected item. if len(self.item_list.menu_items) > 0: # Get the selected item's description text and draw it on the info menu. selected_item_name = self.item_list.menu_items[self.item_list.selected_menu_item] info_text = self.game.player1.inventory[selected_item_name]['item'].description self.info_menu.draw_text(info_text, justify="center", align="middle") current_item_surface = self.game.player1.inventory[selected_item_name]['item'].surface # Scale the item's sprite if it hasn't been scaled already. if (prepare.SCALE != 1 and current_item_surface.get_size() == self.game.player1.inventory[selected_item_name]['item'].surface_size_original): self.game.player1.inventory[selected_item_name]['item'].surface = pygame.transform.scale( current_item_surface, (current_item_surface.get_width() * prepare.SCALE, current_item_surface.get_height() * prepare.SCALE)) # Position the item's sprite in the middle of the left-hand part of the item list. item_pos_x = (self.item_list.pos_x / 2) - (current_item_surface.get_width() / 2) self.screen.blit(current_item_surface, (item_pos_x,0)) # If the decision submenu is visible, draw it and its menu items. if self.decision_menu.visible: self.decision_menu.draw() self.decision_menu.draw_textItem(["Use", "Cancel"], 1, autoline_spacing=True) def get_event(self, event, game): # Handle when the player presses "ESC". if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: # If the "ESC" key was pressed while the decision menu was up, close it. if self.decision_menu.visible: self.decision_menu.visible = False self.decision_menu.interactable = False self.decision_menu.selected_menu_item = 0 self.item_list.interactable = True # If no other submenus were up when we pressed "ESC", close the item menu. else: self.visible = False self.interactable = False # If the item menu was opened from combat, open up the action menu. if game.state_name == "COMBAT": game.state.action_menu.visible = True game.state.action_menu.interactable = True # Handle when the player presses "ENTER" elif event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN: #and len(self.menu_items) > 0: # Decision Menu if self.decision_menu.interactable: if self.decision_menu.menu_items[self.decision_menu.selected_menu_item] == "Cancel": self.decision_menu.visible = False self.decision_menu.interactable = False self.decision_menu.selected_menu_item = 0 self.item_list.interactable = True # Use the selected item. elif self.decision_menu.menu_items[self.decision_menu.selected_menu_item] == "Use": # Get the name of the item from our menu list. item_name = self.item_list.menu_items[self.item_list.selected_menu_item] # For now, just use the item on the currently active monster. print "Using " + item_name item_to_use = game.player1.inventory[item_name]['item'] # Check to see if the item can be used in the current state. if game.state_name.lower() in item_to_use.usable_in: print "%s can be used here!" % item_name if game.state_name == "COMBAT": if item_to_use.target == "opponent": item_target = game.state.current_players['opponent']['monster'] elif item_to_use.target == "player": item_target = game.state.current_players['player']['monster'] # Set the player's decided action for this turn to "item" and give the name # and target of the item. game.state.current_players['player']['action'] = {'item': {'name': item_name, 'target': item_target}} else: game.player1.inventory[item_name]['item'].use(game.player1.monsters[0], game) else: print "%s cannot be used here!" % item_name # Item List Menu else: if self.item_list.interactable: print self.item_list.menu_items[self.item_list.selected_menu_item] self.decision_menu.visible = True self.decision_menu.interactable = True self.item_list.interactable = False # Handle when the player presses "Up" elif event.type == pygame.KEYDOWN and event.key == pygame.K_UP: # Handle the decision submenu. if self.decision_menu.interactable: # If by pressing up our selected item number is less than zero, select the last # item in the list. if self.decision_menu.selected_menu_item - 1 < 0: self.decision_menu.selected_menu_item = len(self.decision_menu.menu_items) - 1 else: self.decision_menu.selected_menu_item -= 1 # If the decision menu isn't open, allow item selection. else: if self.item_list.selected_menu_item -1 < 0: self.item_list.selected_menu_item = len(self.item_list.menu_items) - 1 else: self.item_list.selected_menu_item -= 1 # Handle when the player presses "Down" elif event.type == pygame.KEYDOWN and event.key == pygame.K_DOWN: # Handle the decision submenu. if self.decision_menu.interactable: # If by pressing up our selected item number is less than zero, select the last # item in the list. if self.decision_menu.selected_menu_item + 1 > len(self.decision_menu.menu_items) - 1: self.decision_menu.selected_menu_item = 0 else: self.decision_menu.selected_menu_item += 1 # If the devision menu isn't open, allow item selection. else: if self.item_list.selected_menu_item + 1 > len(self.item_list.menu_items) - 1: self.item_list.selected_menu_item = 0 else: self.item_list.selected_menu_item += 1
def __init__(self, screen, resolution, game, name="Dialog Menu"): # Initialize the parent menu class's default shit Menu.__init__(self, screen, resolution, game, name) self.delay = 0.5 self.elapsed_time = self.delay
def __init__(self, screen, resolution, game, name="MULTIPLAYER"): # Initialize the parent menu class's default shit Menu.__init__(self, screen, resolution, game, name) self.delay = 0.5 self.elapsed_time = self.delay
def draw(self): # We can call the draw function from our parent "Menu" class, and also draw # some additional stuff specifically for the Save Menu. Menu.draw(self) self.slot_size = (self.size_y / self.slots) self.padding = (self.font_size * self.scale) / 3 # Set the initial slot's position slot_pos_x = 0 slot_pos_y = 0 # Draw the different save slots for slot in range(self.slots): slot_num = slot + 1 slot_name = "slot" + str(slot_num) # Check to see if a save exists for the current slot if os.path.exists("saves/slot" + str(slot_num) + ".png"): if not slot_name in self.slot_surfaces: # Scale the slot image n shit self.slot_surfaces[slot_name] = pygame.image.load( "saves/" + slot_name + ".png").convert() scale = float(self.slot_size) / float(self.slot_surfaces[slot_name].get_width()) width = self.slot_surfaces[slot_name].get_width() height = self.slot_surfaces[slot_name].get_height() thumb_width = self.slot_size thumb_height = int(height * scale) scale = int(width / self.slot_size) self.slot_surfaces[slot_name] = pygame.transform.scale( self.slot_surfaces[slot_name], (thumb_width, thumb_height)) else: thumb_width = self.slot_surfaces[slot_name].get_width() thumb_height = self.slot_surfaces[slot_name].get_height() # Draw the screenshot thumb_x = self.pos_x thumb_y = self.pos_y + slot_pos_y + int(self.font_size * 1.5) self.screen.blit(self.slot_surfaces[slot_name], (thumb_x, thumb_y)) # Try and load the save game and draw details about the save try: save_data = save.load(slot_num) except Exception as e: logger.error(e) save_data = {} save_data["error"] = "Save file corrupted" logger.error("Failed loading save file.") if not "error" in save_data: self.draw_text(save_data['player_name'], thumb_width + self.padding, slot_pos_y + int(self.font_size * 1.5)) self.draw_text(save_data['time'], thumb_width + self.padding, slot_pos_y + (self.font_size * 3.5) + self.padding ) # If a save game does not exist, show empty slot else: self.draw_text("empty slot", self.size_x /3, slot_pos_y + (self.slot_size /2)) # Draw the slot text self.draw_text("Slot " + str(slot_num), slot_pos_x, slot_pos_y) # If the slot is selected, draw a rectangle around it if slot == self.selected_menu_item: pygame.draw.rect(self.screen, (147, 112, 219), (self.pos_x - self.padding, self.pos_y + slot_pos_y - self.padding, self.size_x + (self.padding*2), self.slot_size), 2) slot_pos_y += self.slot_size
def draw(self, draw_borders=True, fill_background=False): # We can call the draw function from our parent "Menu" class, and also draw # some additional stuff specifically for the Item Menu. Menu.draw(self, draw_borders, fill_background) # Draw our background image. self.screen.blit(self.background_surface, (0, 0)) # Draw the backpage icon. self.screen.blit(self.backpack['surface'], (self.backpack['pos_x'], self.backpack['pos_y'])) # If the item list submenu is visible, draw it and its menu items. if self.item_list.visible: self.item_list.draw(draw_borders=False, fill_background=False) items = [] for item_name, item_details in self.game.player1.inventory.items(): items.append(item_name) #self.item_list.line_spacing = 250 self.item_list.draw_textItem(items, pos_y=prepare.SCREEN_SIZE[1] / 10, paging=True) # If the info submenu is visible, draw it and its menu items. if self.info_menu.visible: self.info_menu.draw(draw_borders=False, fill_background=True) # Draw the image of the currently selected item. if len(self.item_list.menu_items) > 0: # Get the selected item's description text and draw it on the info menu. selected_item_name = self.item_list.menu_items[ self.item_list.selected_menu_item] info_text = self.game.player1.inventory[selected_item_name][ 'item'].description self.info_menu.draw_text(info_text, justify="center", align="middle") current_item_surface = self.game.player1.inventory[ selected_item_name]['item'].surface # Scale the item's sprite if it hasn't been scaled already. if (prepare.SCALE != 1 and current_item_surface.get_size() == self.game.player1.inventory[selected_item_name] ['item'].surface_size_original): self.game.player1.inventory[selected_item_name][ 'item'].surface = pygame.transform.scale( current_item_surface, (current_item_surface.get_width() * prepare.SCALE, current_item_surface.get_height() * prepare.SCALE)) # Position the item's sprite in the middle of the left-hand part of the item list. item_pos_x = (self.item_list.pos_x / 2) - (current_item_surface.get_width() / 2) self.screen.blit(current_item_surface, (item_pos_x, 0)) # If the decision submenu is visible, draw it and its menu items. if self.decision_menu.visible: self.decision_menu.draw() self.decision_menu.draw_textItem(["Use", "Cancel"], 1, autoline_spacing=True)
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)
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
class ItemMenu(Menu): """A class to create item menu objects. The item menu allows you to view and use items in your inventory. :param screen: The pygame.display surface to draw the menu to. :param resolution: A tuple of the display's resolution in (x, y) format. TODO: We should be able to get this from pygame.display :param game: The main tuxemon game object that contains all the game's variables. :type screen: pygame.display :type resolution: Tuple :type game: core.tools.Control To create a new menu, simply create a new menu instance and then set the size and coordinates of the menu like this: Example: >>> item_menu = ItemMenu(screen, resolution, self) >>> item_menu.size_x = 200 >>> item_menu.size_y = 100 >>> item_menu.pos_x = 500 >>> item_menu.pos_y = 500 >>> item_menu.draw() """ 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) def draw(self, draw_borders=True, fill_background=False): # We can call the draw function from our parent "Menu" class, and also draw # some additional stuff specifically for the Item Menu. Menu.draw(self, draw_borders, fill_background) # Draw our background image. self.screen.blit(self.background_surface, (0, 0)) # Draw the backpage icon. self.screen.blit(self.backpack['surface'], (self.backpack['pos_x'], self.backpack['pos_y'])) # If the item list submenu is visible, draw it and its menu items. if self.item_list.visible: self.item_list.draw(draw_borders=False, fill_background=False) items = [] for item_name, item_details in self.game.player1.inventory.items(): items.append(item_name) #self.item_list.line_spacing = 250 self.item_list.draw_textItem(items, pos_y=prepare.SCREEN_SIZE[1] / 10, paging=True) # If the info submenu is visible, draw it and its menu items. if self.info_menu.visible: self.info_menu.draw(draw_borders=False, fill_background=True) # Draw the image of the currently selected item. if len(self.item_list.menu_items) > 0: # Get the selected item's description text and draw it on the info menu. selected_item_name = self.item_list.menu_items[ self.item_list.selected_menu_item] info_text = self.game.player1.inventory[selected_item_name][ 'item'].description self.info_menu.draw_text(info_text, justify="center", align="middle") current_item_surface = self.game.player1.inventory[ selected_item_name]['item'].surface # Scale the item's sprite if it hasn't been scaled already. if (prepare.SCALE != 1 and current_item_surface.get_size() == self.game.player1.inventory[selected_item_name] ['item'].surface_size_original): self.game.player1.inventory[selected_item_name][ 'item'].surface = pygame.transform.scale( current_item_surface, (current_item_surface.get_width() * prepare.SCALE, current_item_surface.get_height() * prepare.SCALE)) # Position the item's sprite in the middle of the left-hand part of the item list. item_pos_x = (self.item_list.pos_x / 2) - (current_item_surface.get_width() / 2) self.screen.blit(current_item_surface, (item_pos_x, 0)) # If the decision submenu is visible, draw it and its menu items. if self.decision_menu.visible: self.decision_menu.draw() self.decision_menu.draw_textItem(["Use", "Cancel"], 1, autoline_spacing=True) def get_event(self, event, game): # Handle when the player presses "ESC". if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: # If the "ESC" key was pressed while the decision menu was up, close it. if self.decision_menu.visible: self.decision_menu.visible = False self.decision_menu.interactable = False self.decision_menu.selected_menu_item = 0 self.item_list.interactable = True # If no other submenus were up when we pressed "ESC", close the item menu. else: self.visible = False self.interactable = False # If the item menu was opened from combat, open up the action menu. if game.state_name == "COMBAT": game.state.action_menu.visible = True game.state.action_menu.interactable = True # Handle when the player presses "ENTER" elif event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN: #and len(self.menu_items) > 0: # Decision Menu if self.decision_menu.interactable: if self.decision_menu.menu_items[ self.decision_menu.selected_menu_item] == "Cancel": self.decision_menu.visible = False self.decision_menu.interactable = False self.decision_menu.selected_menu_item = 0 self.item_list.interactable = True # Use the selected item. elif self.decision_menu.menu_items[ self.decision_menu.selected_menu_item] == "Use": # Get the name of the item from our menu list. item_name = self.item_list.menu_items[ self.item_list.selected_menu_item] # For now, just use the item on the currently active monster. print "Using " + item_name item_to_use = game.player1.inventory[item_name]['item'] # Check to see if the item can be used in the current state. if game.state_name.lower() in item_to_use.usable_in: print "%s can be used here!" % item_name if game.state_name == "COMBAT": if item_to_use.target == "opponent": item_target = game.state.current_players[ 'opponent']['monster'] elif item_to_use.target == "player": item_target = game.state.current_players[ 'player']['monster'] # Set the player's decided action for this turn to "item" and give the name # and target of the item. game.state.current_players['player']['action'] = { 'item': { 'name': item_name, 'target': item_target } } else: game.player1.inventory[item_name]['item'].use( game.player1.monsters[0], game) else: print "%s cannot be used here!" % item_name # Item List Menu else: if self.item_list.interactable: print self.item_list.menu_items[ self.item_list.selected_menu_item] self.decision_menu.visible = True self.decision_menu.interactable = True self.item_list.interactable = False # Handle when the player presses "Up" elif event.type == pygame.KEYDOWN and event.key == pygame.K_UP: # Handle the decision submenu. if self.decision_menu.interactable: # If by pressing up our selected item number is less than zero, select the last # item in the list. if self.decision_menu.selected_menu_item - 1 < 0: self.decision_menu.selected_menu_item = len( self.decision_menu.menu_items) - 1 else: self.decision_menu.selected_menu_item -= 1 # If the decision menu isn't open, allow item selection. else: if self.item_list.selected_menu_item - 1 < 0: self.item_list.selected_menu_item = len( self.item_list.menu_items) - 1 else: self.item_list.selected_menu_item -= 1 # Handle when the player presses "Down" elif event.type == pygame.KEYDOWN and event.key == pygame.K_DOWN: # Handle the decision submenu. if self.decision_menu.interactable: # If by pressing up our selected item number is less than zero, select the last # item in the list. if self.decision_menu.selected_menu_item + 1 > len( self.decision_menu.menu_items) - 1: self.decision_menu.selected_menu_item = 0 else: self.decision_menu.selected_menu_item += 1 # If the devision menu isn't open, allow item selection. else: if self.item_list.selected_menu_item + 1 > len( self.item_list.menu_items) - 1: self.item_list.selected_menu_item = 0 else: self.item_list.selected_menu_item += 1