Return to repo list

heart-of-gold

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

commit 1b8e48eca50de1b760237ceb69eb951783c3577a
parent c87b262f82c037522bce3f29edaa8a1e2b9cedef
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Sun, 15 Nov 2020 15:51:01 -0600

Added action buttons

Diffstat:
Mdata/img/action_buttons_1.png | 0
Mdata/json/sheets.json | 2+-
Msrc/board.py | 8+++-----
Msrc/bus.py | 4+++-
Msrc/interface.py | 20+++++---------------
Msrc/turn.py | 36++++++++++++++++++++++++++++++++++--
6 files changed, 46 insertions(+), 24 deletions(-)

diff --git a/data/img/action_buttons_1.png b/data/img/action_buttons_1.png Binary files differ. diff --git a/data/json/sheets.json b/data/json/sheets.json @@ -107,6 +107,6 @@ "action_buttons_1" : { "filename" : "action_buttons_1.png", "dimensions" : [198, 48], - "total_sprites" : 6 + "total_sprites" : 12 } } diff --git a/src/board.py b/src/board.py @@ -106,7 +106,7 @@ class BoardManager(manager.Manager): return e.custom_flags[1] return None - def display_as_move_range(self, tile_pos_list): + def display_as_move_range(self, piece, tile_pos_list): """ Display a move range from a given list of tile_pos tuples. @@ -114,11 +114,9 @@ class BoardManager(manager.Manager): # First, refresh overlay to avoid drawing over existing move markers self.load_overlay() - # TEMP!!!! - sp = self.bus.fetch("piece_manager", "selected_piece") - self.create_move_range(sp) + self.create_move_range(piece) for t in self.move_targets: - if not self.bus.check_is_ally_occupied_by_tile_pos(t, sp.team): + if not self.bus.check_is_ally_occupied_by_tile_pos(t, piece.team): e = entity.Entity(self.bus.fetch("sheet_manager", "sheets")["board_overlays_1"], (1, 0)) e.set_position((t[0] * TILE_WIDTH, t[1] * TILE_HEIGHT)) e.custom_flags = ("OverlayMove", t) diff --git a/src/bus.py b/src/bus.py @@ -115,8 +115,10 @@ class ManagerBus(subsystem.GameSubsystem): def perform_continue_current_scene_script(self): self.game.scene_manager.current_scene.continue_script() def perform_display_move_range_of_piece(self, piece): - self.game.board_manager.display_as_move_range(self.game.piece_manager.get_piece_max_legal_move(self.game.piece_manager.selected_piece)) + self.game.board_manager.display_as_move_range(piece, self.game.piece_manager.get_piece_max_legal_move(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_toggle_action_button_activation(self, index): + self.game.turn_manager.action_buttons(index).toggle_activation() diff --git a/src/interface.py b/src/interface.py @@ -87,26 +87,18 @@ class GameInterface(subsystem.GameSubsystem): elif self.game.state_mode == STATE_MODES.Battle_Mode: # Normal in-battle turn control + # See if we clicked a UI button if self.game.control_mode == CTRL_MODES.Turn_Normal: - self.bus.perform_select_piece_with_tile_cursor() - sp = self.bus.fetch("piece_manager", "selected_piece") - if sp != None and sp.taking_turn: - self.bus.perform_display_move_range_of_piece(sp) - self.game.control_mode = CTRL_MODES.Turn_Select_Move - - # Else, see if we clicked a UI button - else: - self.bus.perform_trigger_turn_manager_buttons_at_pos(mouseraw) + self.bus.perform_trigger_turn_manager_buttons_at_pos(mouseraw) # Selecting a move for the active piece control elif self.game.control_mode == CTRL_MODES.Turn_Select_Move: if self.bus.check_for_overlay_move_entity_by_screen_pos(mousepos) != None: + ap = self.bus.fetch("turn_manager", "active_piece") targ = self.bus.check_for_tile_pos_by_screen_pos(mousepos) - to_path = self.bus.check_for_piece_path_by_previous_moves(self.bus.fetch("piece_manager", "selected_piece").tile_pos, targ) + to_path = self.bus.check_for_piece_path_by_previous_moves(ap.tile_pos, targ) if to_path != None: - self.bus.perform_set_piece_move_along_tile_path(self.bus.fetch("piece_manager", "selected_piece"), to_path) - # TODO: Not like this - #self.game.lose_control(len(to_path) * PIECE_MOVE_DELAY, CTRL_MODES.Turn_Normal) + self.bus.perform_set_piece_move_along_tile_path(ap, to_path) self.game.control_mode = CTRL_MODES.Turn_Watch_Move self.bus.perform_load_board_overlay() @@ -146,7 +138,5 @@ class GameInterface(subsystem.GameSubsystem): elif self.game.control_mode == CTRL_MODES.Turn_Watch_Move: ap = self.bus.fetch("turn_manager", "active_piece") if not ap.path_moving: - self.bus.perform_shift_turns() self.game.control_mode = CTRL_MODES.Turn_Normal - diff --git a/src/turn.py b/src/turn.py @@ -36,6 +36,8 @@ class TurnManager(manager.Manager): self.turn_tick = 0 self.in_play_pieces = [] self.turn_depth = 10 + self.active_piece_has_moved = False + self.active_piece_has_acted = False # Turn tray and other associated entities self.turn_tray = None @@ -98,12 +100,20 @@ class TurnManager(manager.Manager): # Set the 0th candidate as the current active piece and let it take a turn self.current_active_piece = candidates.pop(0) self.current_active_piece.taking_turn = True + self.active_piece_has_moved = False + self.active_piece_has_acted = False self.camera.snap_to_position(self.current_active_piece.rect.center) # Predict the next turn order self.project_turn_order() self.current_active_piece.readiness -= 100 + # Set up important UI vals + for b in self.action_buttons: + if not b.clickable: + b.toggle_activation() + self.action_buttons[5].toggle_activation() + def project_turn_order(self): """ Make a projection of the upcoming turn order. @@ -174,6 +184,12 @@ class TurnManager(manager.Manager): if i.rect.collidepoint(pos) and i.clickable: self.camera.snap_to_position(i.piece.rect.center) 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) + self.game.control_mode = CTRL_MODES.Turn_Select_Move + elif self.action_buttons[5].rect.collidepoint(pos) and self.action_buttons[5].clickable: + self.shift_turns() def expose(self): """ @@ -183,7 +199,8 @@ class TurnManager(manager.Manager): "active_piece" : self.current_active_piece, "turn_number" : self.current_turn, "in_play_pieces" : self.in_play_pieces, - "turn_projection" : self.turn_projection + "turn_projection" : self.turn_projection, + "action_buttons" : self.action_buttons } self.bus.record(self.name, data) @@ -192,7 +209,6 @@ class TurnManager(manager.Manager): Update the entities this manager controls. """ if surface != None: - if self.game.control_mode == CTRL_MODES.Turn_Normal: self.turn_tray.update(surface) self.turn_tray_more_button.update(surface) @@ -208,6 +224,11 @@ class TurnManager(manager.Manager): self.turn_icons[j].clickable = True for b in self.action_buttons: b.update(surface) + elif self.game.control_mode == CTRL_MODES.Turn_Watch_Move: + if self.action_buttons[0].clickable: + self.action_buttons[0].toggle_activation() + if not self.action_buttons[5].clickable: + self.action_buttons[5].toggle_activation() ############################# # Section 2 - Turn Entities # @@ -316,3 +337,14 @@ class ActionButton(entity.Entity): # Other values self.manager = manager self.clickable = False + + def toggle_activation(self): + """ + Toggle between on (clickable) and off (not) + states. + """ + self.clickable = not self.clickable + if self.clickable: + self.set_sprite((0, self.sprite[1])) + else: + self.set_sprite((1, self.sprite[1]))