Return to repo list

heart-of-gold

Tactical RPG written in python, using pygame.
Return to HMagellan.com

commit 5760aecfb53d23e86bd73b85db4dcb2ae934d21b
parent dbe089ac97b13d3d19293d64fcff813a19822366
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Sat, 21 Nov 2020 12:35:48 -0600

Added name to stat display, plus can double click turn icon

Diffstat:
Msrc/bus.py | 4++--
Msrc/interface.py | 4+++-
Msrc/piece.py | 7++++++-
Msrc/status.py | 18++++++++++++++++--
Msrc/turn.py | 15+++++++++++----
5 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/src/bus.py b/src/bus.py @@ -126,8 +126,8 @@ class ManagerBus(subsystem.GameSubsystem): self.game.board_manager.display_as_attack_range(piece) def perform_shift_turns(self): self.game.turn_manager.shift_turns() - def perform_trigger_turn_manager_buttons_at_pos(self, pos): - self.game.turn_manager.trigger_button_at_pos(pos) + def perform_trigger_turn_manager_buttons_at_pos(self, pos, double_clicking): + self.game.turn_manager.trigger_button_at_pos(pos, double_clicking) def perform_toggle_action_button_activation(self, index): self.game.turn_manager.action_buttons(index).toggle_activation() def perform_turn_manager_kill_piece(self, piece): diff --git a/src/interface.py b/src/interface.py @@ -111,7 +111,7 @@ class GameInterface(subsystem.GameSubsystem): # Normal in-battle turn control # See if we clicked a UI button if self.game.control_mode == CTRL_MODES.Turn_Normal: - self.bus.perform_trigger_turn_manager_buttons_at_pos(mouseraw) + self.bus.perform_trigger_turn_manager_buttons_at_pos(mouseraw, self.double_clicking) self.bus.perform_select_piece_with_tile_cursor() sp = self.bus.fetch("piece_manager", "selected_piece") if sp != None: @@ -182,6 +182,8 @@ class GameInterface(subsystem.GameSubsystem): # Doubleclick countdown if self.double_click_timer > 0: self.double_click_timer -= 1 + else: + self.double_clicking = False # BATTLE MODE ONLY UPDATES # Update mouse position diff --git a/src/piece.py b/src/piece.py @@ -416,7 +416,12 @@ class Piece(entity.Entity): display, or None if no stats are found. """ if self.active_stats != None and self.normal_stats != None: - return { "normal_stats" : self.normal_stats, "active_stats" : self.active_stats } + return { + "name" : self.name, + "normal_stats" : self.normal_stats, + "active_stats" : self.active_stats, + "equipment" : self.equipment + } else: return None diff --git a/src/status.py b/src/status.py @@ -30,10 +30,20 @@ class StatusDisplay(entity.Entity): # Other important values self.stat_def = stat_def # Consists of a piece's active stats and normal stats, in a dict self.font = pygame.font.Font(os.path.join(FONT_PATH, UI_FONT), SCREEN_HEIGHT // 34) - # TODO: hardcoded - self.stat_surfaces_position = (140, 216) + self.name_surface = None + self.name_surface_rect = None self.stat_surfaces = { i: None for i in self.stat_def["normal_stats"].keys() } self.stat_surface_rects = { i: None for i in self.stat_def["normal_stats"].keys() } + self.equipment_surfaces = { i: None for i in self.stat_def["equipment"].keys() } + self.equipment_surface_rects = { i: None for i in self.stat_def["equipment"].keys() } + + # Surface base positions + # TODO: hardcoded + self.name_surface_position = (94, 96) + self.stat_surfaces_position = (140, 216) + self.equipment_surface_position = (300, 216) + + # Load up self.load_text() def load_text(self): @@ -41,6 +51,9 @@ class StatusDisplay(entity.Entity): Load all the various text fields and their rects. """ + self.name_surface = self.font.render(self.stat_def["name"], False, (0, 0, 0)).convert() + self.name_surface_rect = self.name_surface.get_rect() + self.name_surface_rect.topleft = self.name_surface_position self.stat_surfaces["ATK"] = self.font.render(str(self.stat_def["active_stats"]["ATK"]), False, (0, 0, 0)).convert() self.stat_surface_rects["ATK"] = self.stat_surfaces["ATK"].get_rect() self.stat_surface_rects["ATK"].topleft = (self.stat_surfaces_position[0] + (0), self.stat_surfaces_position[1]) @@ -68,6 +81,7 @@ class StatusDisplay(entity.Entity): Update overwrite to handle drawing subsurfaces. """ super().update(surface) + surface.blit(self.name_surface, self.name_surface_rect) for s in self.stat_surfaces: if self.stat_surfaces[s] != None: surface.blit(self.stat_surfaces[s], self.stat_surface_rects[s]) diff --git a/src/turn.py b/src/turn.py @@ -181,11 +181,12 @@ class TurnManager(manager.Manager): else: self.stat_screen = None - def trigger_button_at_pos(self, pos): + def trigger_button_at_pos(self, pos, double_clicking = False): """ Trigger a button at the given pos, if any. The TurnManager buttons do not use the effect - interface. + interface. Also handles double-clicking which + has the same effect as double-clicking the piece. """ # TODO: Should this use the effect interface??? if self.turn_tray_more_button != None: @@ -195,8 +196,14 @@ class TurnManager(manager.Manager): self.turn_tray_more_button.set_position((3 * (SCREEN_WIDTH // 4), self.turn_tray.rect.bottom + 2)) for i in self.turn_icons: if i.rect.collidepoint(pos) and i.clickable: - self.camera.snap_to_position(i.piece.rect.center) - break + if not double_clicking: + self.camera.snap_to_position(i.piece.rect.center) + break + else: + self.create_stat_screen(i.piece) + self.game.control_mode = CTRL_MODES.Turn_Display_Stats + break + # Do action buttons. They are ordered so we know which is which by index if self.action_buttons[0].rect.collidepoint(pos) and self.action_buttons[0].clickable: self.bus.perform_display_move_range_of_piece(self.current_active_piece)