Return to repo list

heart-of-gold

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

commit c87b262f82c037522bce3f29edaa8a1e2b9cedef
parent d2471d1858ef02e7899e977932b122d54246027a
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Sun, 15 Nov 2020 14:46:39 -0600

Added action buttons

Diffstat:
Adata/img/action_buttons_1.png | 0
Mdata/json/sheets.json | 5+++++
Msrc/constants.py | 2+-
Msrc/turn.py | 63++++++++++++++++++++++++++++++++++++++++++++++-----------------
4 files changed, 52 insertions(+), 18 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 @@ -103,5 +103,10 @@ "filename" : "toggle_more_turn_button_1.png", "dimensions" : [135, 14], "total_sprites" : 2 + }, + "action_buttons_1" : { + "filename" : "action_buttons_1.png", + "dimensions" : [198, 48], + "total_sprites" : 6 } } diff --git a/src/constants.py b/src/constants.py @@ -24,7 +24,7 @@ TILE_HEIGHT = 64 COLORKEY = (255, 0, 255) # Other constants -PIECE_MOVE_SPEED = 2 +PIECE_MOVE_SPEED = 4 PIECE_MOVE_DELAY = PIECE_MOVE_SPEED * 4 SCROLL_SPEED = 4 UI_FONT = "ArchivoNarrow-Regular.otf" diff --git a/src/turn.py b/src/turn.py @@ -41,15 +41,18 @@ class TurnManager(manager.Manager): self.turn_tray = None self.turn_tray_more_button = None self.turn_icons = [] + self.action_buttons = [] def initialize_turns(self, pieces): """ - Load up the turns for the first time. + Load up the turns for the first time. This + also sets up persistent parts of the turn UI + such as the trays and action buttons. """ + sheets = self.bus.fetch("sheet_manager", "sheets") self.in_play_pieces = pieces - self.turn_tray = TurnTray(self.bus.fetch("sheet_manager", "sheets")["turn_order_tray_1"], (0, 0), None, False, - self.bus.fetch("sheet_manager", "sheets")["turn_order_tray_extended_1"]) - self.turn_tray_more_button = TurnTrayMoreButton(self.bus.fetch("sheet_manager", "sheets")["toggle_more_turn_button_1"], (0, 0), None, False, self) + self.turn_tray = TurnTray(sheets["turn_order_tray_1"], (0, 0), None, False, sheets["turn_order_tray_extended_1"]) + self.turn_tray_more_button = TurnTrayMoreButton(sheets["toggle_more_turn_button_1"], (0, 0), None, False, self) # TODO: Probably shouldn't be hardcoded self.turn_tray.set_position((798, 28)) self.turn_tray_more_button.set_position((798, self.turn_tray.rect.bottom + 2)) @@ -57,6 +60,10 @@ class TurnManager(manager.Manager): self.turn_projection = [] self.former_candidates = [] self.current_turn = 1 + for b in range(0, 6): + nab = ActionButton(sheets["action_buttons_1"], (0, b), None, False, self) + nab.set_position((64, 50 + (52 * b))) + self.action_buttons.append(nab) self.shift_turns() def shift_turns(self): @@ -128,6 +135,7 @@ class TurnManager(manager.Manager): rds[p] += p.active_stats["INIT"] + min(1, (p.active_stats["SPD"] // 3)) if rds[p] >= 100: next_turn_candidates.append(p) + rds[p] -= 100 if len(next_turn_candidates) > 0: next_turn_candidates.sort(reverse = True, key = lambda can: (rds[can] + 100, can.active_stats["SPD"])) @@ -184,18 +192,22 @@ class TurnManager(manager.Manager): Update the entities this manager controls. """ if surface != None: - self.turn_tray.update(surface) - self.turn_tray_more_button.update(surface) - if self.turn_tray_more_button.more: - for i in self.turn_icons: - i.update(surface) - i.clickable = True - else: - for i in self.turn_icons: - i.clickable = False - for j in range(0, 4): - self.turn_icons[j].update(surface) - self.turn_icons[j].clickable = True + + if self.game.control_mode == CTRL_MODES.Turn_Normal: + self.turn_tray.update(surface) + self.turn_tray_more_button.update(surface) + if self.turn_tray_more_button.more: + for i in self.turn_icons: + i.update(surface) + i.clickable = True + else: + for i in self.turn_icons: + i.clickable = False + for j in range(0, 4): + self.turn_icons[j].update(surface) + self.turn_icons[j].clickable = True + for b in self.action_buttons: + b.update(surface) ############################# # Section 2 - Turn Entities # @@ -272,7 +284,7 @@ class TurnTrayMoreButton(entity.Entity): """ def __init__(self, sheet, sprite = (0, 0), animation = None, animated = False, - manager = None): + manager = None): # Parent initialization super().__init__(sheet, sprite, animation, animated) @@ -287,3 +299,20 @@ class TurnTrayMoreButton(entity.Entity): """ self.more = not self.more self.set_sprite((0, abs(self.sprite[1] - 1))) + +class ActionButton(entity.Entity): + """ + Class representing the buttons that can be + pressed to perform pieces' unit actions + during their turn. + """ + + def __init__(self, sheet, sprite = (0, 0), animation = None, animated = None, + manager = None): + + # Parent initialization + super().__init__(sheet, sprite, animation, animated) + + # Other values + self.manager = manager + self.clickable = False