Return to repo list

heart-of-gold

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

commit 88e21c6a164dc270e7822af4df3f49a527be4b59
parent a9ca5eeeb51c09112db1f3ca40b65a0b5b35c409
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Tue, 17 Nov 2020 13:32:47 -0600

Improvements to the turn UI

Diffstat:
Adata/img/team_indicator_small_1.png | 0
Mdata/img/turn_order_tray_1.png | 0
Mdata/img/turn_order_tray_extended_1.png | 0
Mdata/json/sheets.json | 5+++++
Msrc/turn.py | 46++++++++++++++++++++++++++--------------------
5 files changed, 31 insertions(+), 20 deletions(-)

diff --git a/data/img/team_indicator_small_1.png b/data/img/team_indicator_small_1.png Binary files differ. diff --git a/data/img/turn_order_tray_1.png b/data/img/turn_order_tray_1.png Binary files differ. diff --git a/data/img/turn_order_tray_extended_1.png b/data/img/turn_order_tray_extended_1.png Binary files differ. diff --git a/data/json/sheets.json b/data/json/sheets.json @@ -108,5 +108,10 @@ "filename" : "action_buttons_1.png", "dimensions" : [198, 48], "total_sprites" : 12 + }, + "team_indicator_small_1" : { + "filename" : "team_indicator_small_1.png", + "dimensions" : [12, 12], + "total_sprites" : 2 } } diff --git a/src/turn.py b/src/turn.py @@ -10,8 +10,6 @@ from .constants import * # 1. The TurnManager class, which handles turn order and displaying turn info in the GUI # 2. The TurnTray Entity subclass, which represents the tray where turn information is reported onscreen -# TODO: TurnManager takes the camera as an argument. Should all managers??? - ################################# # Section 1 - TurnManager class # ################################# @@ -29,7 +27,6 @@ class TurnManager(manager.Manager): super().__init__(game, bus, camera, name) # Important values - self.camera = camera self.current_turn = 1 self.current_active_piece = None self.turn_projection = [] @@ -55,16 +52,15 @@ class TurnManager(manager.Manager): self.in_play_pieces = pieces 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)) + self.turn_tray.set_position((3 * (SCREEN_WIDTH // 4), (SCREEN_HEIGHT // 10) - 1)) + self.turn_tray_more_button.set_position((3 * (SCREEN_WIDTH // 4), self.turn_tray.rect.bottom + 2)) self.turn_icons = [] 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))) + nab.set_position(((SCREEN_WIDTH // 8), (SCREEN_HEIGHT // 12) + (((SCREEN_HEIGHT // 14) - 4)) * b)) self.action_buttons.append(nab) self.shift_turns() @@ -178,7 +174,7 @@ class TurnManager(manager.Manager): if self.turn_tray_more_button.rect.collidepoint(pos): self.turn_tray_more_button.toggle_more() self.turn_tray.toggle_sheet(self.turn_tray_more_button.more) - self.turn_tray_more_button.set_position((798, self.turn_tray.rect.bottom + 2)) + 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) @@ -279,11 +275,9 @@ class TurnIcon(entity.Entity): self.piece = piece self.piece_name = piece.name self.piece_picture = entity.Entity(self.manager.bus.fetch("sheet_manager", "sheets")[piece.pictures["icons_small"]]) - # TODO: Font size should be dynamically determined from screen size - self.font = pygame.font.Font(os.path.join(FONT_PATH, UI_FONT), 12) + self.font = pygame.font.Font(os.path.join(FONT_PATH, UI_FONT), SCREEN_HEIGHT // 18) self.index = index - # TODO: Set this in settings??? Should at least dynamically derive y multiple from screen size - self.set_position((800, 32 + (31 * index))) + self.set_position(((3 * (SCREEN_WIDTH // 4)) + 4, ((2 * (SCREEN_HEIGHT // 20)) + 1) + ((SCREEN_HEIGHT // 24) * index))) self.piece_picture.set_position(self.rect.topleft) self.clickable = False self.health_bar = None @@ -295,6 +289,8 @@ class TurnIcon(entity.Entity): self.name_surface = None self.name_surface_rect = None self.render_name() + self.team_indicator = None + self.indicate_team() def create_health_bar(self): """ @@ -316,21 +312,34 @@ class TurnIcon(entity.Entity): self.name_surface = self.font.render(self.piece.name, False, (255, 255, 255)).convert() self.name_surface_rect = self.name_surface.get_rect() + def indicate_team(self): + """ + Create a small indicator to show what team + this icon's piece is on. + """ + if self.piece.team == "Player": + sp = (0, 0) + elif self.piece.team == "Enemy": + sp = (0, 1) + self.team_indicator = entity.Entity(self.manager.bus.fetch("sheet_manager", "sheets")["team_indicator_small_1"], sp) + self.team_indicator.set_position((self.rect.width - self.team_indicator.rect.width, 0)) + def update(self, surface = None): """ Overwrite of parent update() since this entity draws sub-sprites. """ + if self.team_indicator != None: + self.team_indicator.update(self.image) super().update(surface) self.piece_picture.update(surface) - # TODO: Hardcoding magic numbers if self.health_bar != None and self.health_bar_fill != None: - self.health_bar_rect.center = (self.rect.center[0] + 8, self.rect.center[1] + 8) + self.health_bar_rect.center = (self.rect.center[0] + (TILE_WIDTH // 8), self.rect.center[1] + (TILE_HEIGHT // 8)) self.health_bar_fill_rect.topleft = (self.health_bar_rect.topleft[0] + 1, self.health_bar_rect.topleft[1] + 1) surface.blit(self.health_bar, self.health_bar_rect) surface.blit(self.health_bar_fill, self.health_bar_fill_rect) if self.name_surface != None: - self.name_surface_rect.center = (self.rect.center[0] + 8, self.rect.center[1] - 4) + self.name_surface_rect.center = (self.rect.center[0] + (TILE_WIDTH // 8), self.rect.center[1] - (TILE_HEIGHT // 16)) surface.blit(self.name_surface, self.name_surface_rect) class TurnTrayMoreButton(entity.Entity): @@ -356,7 +365,7 @@ class TurnTrayMoreButton(entity.Entity): Toggle the more setting. """ self.more = not self.more - self.set_sprite((0, abs(self.sprite[1] - 1))) + self.set_sprite((0, int(self.more))) class ActionButton(entity.Entity): """ @@ -381,7 +390,4 @@ class ActionButton(entity.Entity): states. """ self.clickable = not self.clickable - if self.clickable: - self.set_sprite((0, self.sprite[1])) - else: - self.set_sprite((1, self.sprite[1])) + self.set_sprite((int(not self.clickable), self.sprite[1]))