Return to repo list

heart-of-gold

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

commit 0a17ef0dfb48b663fb7fdf0bb7f0c302bb09feda
parent ebf9d1c476922e8f41d85ccec7a207a8fc4ce5a0
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Tue, 27 Apr 2021 00:30:34 -0500

added return button in exitable turn modes

Diffstat:
Adata/img/return_prompt_1.png | 0
Mdata/json/sheets.json | 7+++++++
Msrc/bus.py | 2++
Msrc/constants.py | 9+++++++++
Msrc/interface.py | 13+++++--------
Msrc/turn.py | 49+++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 72 insertions(+), 8 deletions(-)

diff --git a/data/img/return_prompt_1.png b/data/img/return_prompt_1.png Binary files differ. diff --git a/data/json/sheets.json b/data/json/sheets.json @@ -34,6 +34,13 @@ "anim_class" : "Continue_Prompt_1", "alpha" : false }, + "return_prompt_1" : { + "filename" : "return_prompt_1.png", + "dimensions" : [32, 13], + "total_sprites" : 9, + "anim_class" : "Continue_Prompt_1", + "alpha" : false + }, "test_scene_bg_1" : { "filename" : "test_scene_bg_1.png", "dimensions" : [1024, 768], diff --git a/src/bus.py b/src/bus.py @@ -147,3 +147,5 @@ class ManagerBus(subsystem.GameSubsystem): self.game.turn_manager.refresh_turn_state() def perform_turn_manager_display_stats(self, piece): self.game.turn_manager.create_stat_screen(piece) + def perform_turn_manager_check_return_button_click(self, pos): + self.game.turn_manager.check_return_button_click(pos) diff --git a/src/constants.py b/src/constants.py @@ -98,6 +98,15 @@ SCENE_EFFECTS = enum.Enum('SCENE_EFFECTS', 'ef_scene_dummy ef_scene_delay ef_sce TEAMS = enum.Enum('TEAMS', 'Player Ally Neutral Enemy Other') ATTACK_NOTATIONS = enum.Enum('ATTACK_NOTATIONS', 'backattack critical counter opposite weakness resist riposte ignoredef parry block sweep miss onetwo stun') +# Mode/Enum element collections +EXITABLE_TURN_MODES = [ + CTRL_MODES.Turn_Select_Move, + CTRL_MODES.Turn_Select_Attack, + CTRL_MODES.Turn_Select_Push, + CTRL_MODES.Turn_Choose_Skill, + CTRL_MODES.Turn_Choose_Item +] + # Save environment SAVE_ENV = { "profile_name" : "", diff --git a/src/interface.py b/src/interface.py @@ -37,13 +37,6 @@ class GameInterface(subsystem.GameSubsystem): self.double_click_timer = 0 self.double_click_mousepos = None self.old_mousepos = None - self.quitable_modes = [ - CTRL_MODES.Turn_Select_Move, - CTRL_MODES.Turn_Select_Attack, - CTRL_MODES.Turn_Select_Push, - CTRL_MODES.Turn_Choose_Skill, - CTRL_MODES.Turn_Choose_Item - ] def handle_events(self, events): """ @@ -74,7 +67,7 @@ class GameInterface(subsystem.GameSubsystem): if event.key == pygame.K_s or event.key == pygame.K_q: self.bus.perform_turn_manager_display_stats(None) self.game.control_mode = CTRL_MODES.Turn_Normal - elif self.game.control_mode in self.quitable_modes: + elif self.game.control_mode in EXITABLE_TURN_MODES: if event.key == pygame.K_q: self.game.control_mode = CTRL_MODES.Turn_Normal self.bus.perform_load_board_overlay() @@ -176,6 +169,10 @@ class GameInterface(subsystem.GameSubsystem): self.game.switch_mode(STATE_MODES.Base_Mode, "testbase1") self.bus.perform_piece_manager_reset_state() + # Exitable mode checks (not an else!) + if self.game.control_mode in EXITABLE_TURN_MODES: + self.bus.perform_turn_manager_check_return_button_click(mouseraw) + # Still-scene mode behavior elif self.game.state_mode == STATE_MODES.Still_Scene_Mode: diff --git a/src/turn.py b/src/turn.py @@ -65,6 +65,7 @@ class TurnManager(manager.Manager): self.turn_tray_more_button = None self.turn_icons = [] self.action_buttons = [] + self.return_button = None # Stat screen values self.stat_screen = None @@ -91,6 +92,7 @@ class TurnManager(manager.Manager): self.former_candidates = [] self.current_turn = 1 self.battle_resolution_timer = 120 + self.return_button = ReturnButton(sheets["return_prompt_1"], (0, 0), None, False, self) # Create action buttons self.action_buttons.append(MoveActionButton(sheets["action_buttons_1"], (0, 0), None, False, self, 0)) @@ -296,6 +298,13 @@ class TurnManager(manager.Manager): self.game.control_mode = CTRL_MODES.Battle_Dialog self.bus.perform_scene_manager_load_scene_from_file(scenefile) + def check_return_button_click(self, pos): + """ + See if the return button has been clicked. + """ + if self.return_button.displayed and self.return_button.rect.collidepoint(pos): + self.return_button.return_to_turn_normal() + def refresh_turn_state(self): """ Refresh the entire state of the turn @@ -380,6 +389,7 @@ class TurnManager(manager.Manager): self.battle_resolution_timer -= 1 else: self.game.control_mode = CTRL_MODES.Battle_Summary + self.return_button.update(surface) ############################# # Section 2 - Turn Entities # @@ -529,6 +539,45 @@ class TurnTrayMoreButton(entity.Entity): self.more = not self.more self.set_sprite((0, int(self.more))) +class ReturnButton(entity.Entity): + """ + Class representing the button that pops up + near the bottom of the screen in exitable + modes that will allow you to return to the + previous mode. + """ + + def __init__(self, sheet, sprite = (0, 0), animation = None, animated = False, + manager = None): + + # Parent initialization + super().__init__(sheet, sprite, animation, animated) + + # Other values + self.manager = manager + self.displayed = False + self.set_position(((SCREEN_WIDTH // 12) * 11, (SCREEN_HEIGHT // 14) * 13)) + + def return_to_turn_normal(self): + """ + Return to the normal mode of play. + """ + if self.displayed: + self.manager.game.control_mode = CTRL_MODES.Turn_Normal + self.manager.bus.perform_load_board_overlay() + + def update(self, surface = None): + """ + Overwrite of update to avoid drawing unless + needed. + """ + if self.manager.game.control_mode in EXITABLE_TURN_MODES: + self.displayed = True + else: + self.displayed = False + if self.displayed: + super().update(surface) + ################################################# # Section 3 - ActionButton class and subclasses # #################################################