Return to repo list

heart-of-gold

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

commit dbe089ac97b13d3d19293d64fcff813a19822366
parent ea8a52ebff43120016da19922fe778e6448d519e
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Fri, 20 Nov 2020 23:54:41 -0600

Can now doubleclick to bring up status

Diffstat:
Msrc/interface.py | 44++++++++++++++++++++++++++++++++++++--------
Msrc/status.py | 28+++++++++++++++++++++-------
2 files changed, 57 insertions(+), 15 deletions(-)

diff --git a/src/interface.py b/src/interface.py @@ -33,6 +33,10 @@ class GameInterface(subsystem.GameSubsystem): self.camera = camera self.drag_piece = False self.drag_from_pos = (0, 0) + self.double_clicking = False + self.double_click_timer = 0 + self.double_click_mousepos = None + self.old_mousepos = None def handle_events(self, events): """ @@ -84,6 +88,14 @@ class GameInterface(subsystem.GameSubsystem): # First, get important mouse positional info, namely unoffset mouse position and camera-offset mouse position mouseraw = pygame.mouse.get_pos() mousepos = (mouseraw[0] - self.camera.camera_surface_offset[0], mouseraw[1] - self.camera.camera_surface_offset[1]) + + # Next, set up for double click + if self.double_click_timer == 0 and not self.double_clicking: + self.double_click_timer = 15 + self.double_click_mousepos = mousepos + elif not self.double_clicking and mousepos == self.double_click_mousepos: + self.double_clicking = True + self.double_click_timer = 0 # State checker # Main menu mode behavior @@ -102,9 +114,16 @@ class GameInterface(subsystem.GameSubsystem): self.bus.perform_trigger_turn_manager_buttons_at_pos(mouseraw) self.bus.perform_select_piece_with_tile_cursor() sp = self.bus.fetch("piece_manager", "selected_piece") - if sp != None and self.bus.fetch("turn_manager", "active_piece") == sp: - self.drag_piece = True - self.drag_from_pos = mouseraw + if sp != None: + # Drag a piece for facing + if not self.double_clicking and self.bus.fetch("turn_manager", "active_piece") == sp: + self.drag_piece = True + self.drag_from_pos = mouseraw + # Double-click a piece for accessing status + elif self.double_clicking: + self.double_clicking = False + self.bus.perform_turn_manager_display_stats(sp) + self.game.control_mode = CTRL_MODES.Turn_Display_Stats # Selecting a move for the active piece control elif self.game.control_mode == CTRL_MODES.Turn_Select_Move: @@ -135,6 +154,9 @@ class GameInterface(subsystem.GameSubsystem): if self.game.control_mode == CTRL_MODES.Still_Scene_Normal: self.bus.perform_continue_current_scene_script() + # Keepover + self.old_mousepos = mousepos + def handle_mouse_release(self, event): """ React to a mousebutton being released. @@ -156,7 +178,13 @@ class GameInterface(subsystem.GameSubsystem): per frame. This is not the same as a drawing update for e.g. an Entity, and is logic-only. """ - # Update cursor position + # UNIVERSAL UPDATES + # Doubleclick countdown + if self.double_click_timer > 0: + self.double_click_timer -= 1 + + # BATTLE MODE ONLY UPDATES + # Update mouse position if self.game.state_mode == STATE_MODES.Battle_Mode: mouseraw = pygame.mouse.get_pos() mousepos = (mouseraw[0] - self.camera.camera_surface_offset[0], mouseraw[1] - self.camera.camera_surface_offset[1]) @@ -179,16 +207,16 @@ class GameInterface(subsystem.GameSubsystem): ap.facing = FACE_DIR.D ap.set_animation(self.bus.fetch("sheet_manager", "animations")[ap.sheet.name]["stand_" + ap.facing.name], True) - # Position cursor - if tilepos != None: - self.bus.perform_position_tile_cursor((tilepos[0], tilepos[1])) - # Scroll camera if self.game.control_mode in (CTRL_MODES.Turn_Normal, CTRL_MODES.Turn_Select_Move, CTRL_MODES.Turn_Select_Attack): for r in self.camera.scroll_rects: if self.camera.scroll_rects[r].collidepoint(mouseraw) and pygame.mouse.get_focused(): self.camera.move_offset(r, SCROLL_SPEED) + # Position cursor + if tilepos != None: + self.bus.perform_position_tile_cursor((tilepos[0], tilepos[1])) + # Watching a move complete elif self.game.control_mode == CTRL_MODES.Turn_Watch_Move: ap = self.bus.fetch("turn_manager", "active_piece") diff --git a/src/status.py b/src/status.py @@ -41,13 +41,27 @@ class StatusDisplay(entity.Entity): Load all the various text fields and their rects. """ - modifier = 0 - for i in self.stat_surfaces: - if i in BASIC_STATS: - self.stat_surfaces[i] = self.font.render(str(self.stat_def["active_stats"][i]), False, (0, 0, 0)).convert() - self.stat_surface_rects[i] = self.stat_surfaces[i].get_rect() - self.stat_surface_rects[i].topleft = (self.stat_surfaces_position[0] + (150 * (modifier % 2)), self.stat_surfaces_position[1] + (21 * (modifier // 2)) + (modifier // 2)) - modifier += 1 + 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]) + self.stat_surfaces["INT"] = self.font.render(str(self.stat_def["active_stats"]["INT"]), False, (0, 0, 0)).convert() + self.stat_surface_rects["INT"] = self.stat_surfaces["INT"].get_rect() + self.stat_surface_rects["INT"].topleft = (self.stat_surfaces_position[0] + (150), self.stat_surfaces_position[1]) + self.stat_surfaces["DEF"] = self.font.render(str(self.stat_def["active_stats"]["DEF"]), False, (0, 0, 0)).convert() + self.stat_surface_rects["DEF"] = self.stat_surfaces["DEF"].get_rect() + self.stat_surface_rects["DEF"].topleft = (self.stat_surfaces_position[0] + (0), self.stat_surfaces_position[1] + 22) + self.stat_surfaces["WIS"] = self.font.render(str(self.stat_def["active_stats"]["WIS"]), False, (0, 0, 0)).convert() + self.stat_surface_rects["WIS"] = self.stat_surfaces["WIS"].get_rect() + self.stat_surface_rects["WIS"].topleft = (self.stat_surfaces_position[0] + (150), self.stat_surfaces_position[1] + 22) + self.stat_surfaces["ACC"] = self.font.render(str(self.stat_def["active_stats"]["ACC"]), False, (0, 0, 0)).convert() + self.stat_surface_rects["ACC"] = self.stat_surfaces["ACC"].get_rect() + self.stat_surface_rects["ACC"].topleft = (self.stat_surfaces_position[0] + (0), self.stat_surfaces_position[1] + 45) + self.stat_surfaces["SPD"] = self.font.render(str(self.stat_def["active_stats"]["SPD"]), False, (0, 0, 0)).convert() + self.stat_surface_rects["SPD"] = self.stat_surfaces["SPD"].get_rect() + self.stat_surface_rects["SPD"].topleft = (self.stat_surfaces_position[0] + (150), self.stat_surfaces_position[1] + 45) + self.stat_surfaces["LUK"] = self.font.render(str(self.stat_def["active_stats"]["LUK"]), False, (0, 0, 0)).convert() + self.stat_surface_rects["LUK"] = self.stat_surfaces["LUK"].get_rect() + self.stat_surface_rects["LUK"].topleft = (self.stat_surfaces_position[0] + (0), self.stat_surfaces_position[1] + 69) def update(self, surface = None): """