Return to repo list

heart-of-gold

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

commit 82a0fd393e1dc883dcb338bb3bf6594814f4ea5e
parent adec7196ee3bfa7451cc8ed9935be67180e0d43b
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Mon, 28 Dec 2020 11:08:31 -0600

remove seperate dialog system and retrofit function to scene

Diffstat:
Rdata/img/pictures/jisella_1/dialog_portrait.png -> data/img/actors/jisella/portrait.png | 0
Ddata/json/dialog.json | 16----------------
Mdata/json/scenes/testscene.json | 2++
Mdata/json/sheets.json | 7+++++++
Msrc/constants.py | 5+----
Dsrc/dialog.py | 133-------------------------------------------------------------------------------
Msrc/scene.py | 15++++++++++++++-
7 files changed, 24 insertions(+), 154 deletions(-)

diff --git a/data/img/pictures/jisella_1/dialog_portrait.png b/data/img/actors/jisella/portrait.png Binary files differ. diff --git a/data/json/dialog.json b/data/json/dialog.json @@ -1,16 +0,0 @@ -{ - "test1" : [ - { - "speaker" : "Jisella", - "icon" : null, - "voice" : "Voice2", - "text" : "This is a test of the dialog subsystem." - }, - { - "speaker" : "Jisella", - "icon" : null, - "voice" : "Voice2", - "text" : "Further test." - } - ] -} diff --git a/data/json/scenes/testscene.json b/data/json/scenes/testscene.json @@ -12,6 +12,7 @@ "name_pos" : [20, 480], "line_font" : "A", "voice" : "Voice2", + "portrait" : "jisella_actor_portrait", "line" : "Hello there. How are you doing today? I'm fine, thanks for asking.", "characters" : [ { @@ -34,6 +35,7 @@ "name_pos" : [20, 480], "line_font" : "A", "voice" : null, + "portrait" : null, "line" : "", "characters" : [ ], "effects" : [ diff --git a/data/json/sheets.json b/data/json/sheets.json @@ -83,6 +83,13 @@ "anim_class" : null, "alpha" : true }, + "jisella_actor_portrait" : { + "filename" : "actors/jisella/portrait.png", + "dimensions" : [96, 96], + "total_sprites" : 1, + "anim_class" : null, + "alpha" : false + }, "jisella_1" : { "filename" : "jisella_1.png", "dimensions" : [64, 64], diff --git a/src/constants.py b/src/constants.py @@ -87,12 +87,9 @@ BASIC_STATS = ["ATK", "DEF", "INT", "WIS", "SPD", "ACC", "LUK"] RESERVE_STATS = ["MOVE", "INIT", "CNTR", "GARD", "PUSH", "SKLL", "PASS"] OTHER_STATS = ["HP", "EXP", "LVL", "RNK"] -# Dialog constants -with open(os.path.join(JSON_PATH, "dialog.json")) as f: DIALOGS = json.load(f) - # Enums STATE_MODES = enum.Enum('STATE_MODES', 'Main_Menu_Mode Battle_Mode Still_Scene_Mode') -CTRL_MODES = enum.Enum('CTRL_MODES', 'No_Control Main_Menu_Normal Turn_Normal Turn_Select_Move Turn_Select_Attack Turn_Watch_Move Turn_Watch_Attack Turn_Display_Stats Turn_Watch_Guard Still_Scene_Normal') +CTRL_MODES = enum.Enum('CTRL_MODES', 'No_Control Main_Menu_Normal Turn_Normal Turn_Select_Move Turn_Select_Attack Turn_Watch_Move Turn_Watch_Attack Turn_Display_Stats Turn_Watch_Guard Battle_Dialog Still_Scene_Normal') FACE_DIR = enum.Enum('FACE_DIR', 'U D L R') GAME_EFFECTS = enum.Enum('GAME_EFFECTS', 'ef_game_quit ef_game_switch_mode') ATTACK_NOTATIONS = enum.Enum('ATTACK_NOTATIONS', 'backattack critical counter opposite weakness resist riposte ignoredef parry block sweep miss onetwo stun') diff --git a/src/dialog.py b/src/dialog.py @@ -1,133 +0,0 @@ -import pygame -from . import manager, entity -from .constants import * - -############# -# dialog.py # -############# - -# This file contains the following: -# 1. The DialogManager class, which controls the inter-mode bottom-of-the-screen conversation events -# 2. The Dialog class, which represents a dialog sequence itself - -################################### -# Section 1 - DialogManager class # -################################### - -class DialogManager(manager.Manager): - """ - Manager class for the dialog boxes that display - either during battle or while at the base. - """ - - def __init__(self, game, bus, camera, name): - - # Parent initialization - super().__init__(game, bus, camera, name) - - # Other vals - self.dialog_sequence = [] - self.sequence_index = 0 - self.text_speed = 1 - self.text_write_timer = 0 - self.current_text_char_index = 0 - self.continue_ready = False - self.max_line = 0 - self.total_lines = 0 - self.text_box = None - self.text_box_pos = (0, 508) - self.continue_prompt = None - self.continue_prompt_pos = (964, 748) - self.text_area_topleft = (48, 560) - self.text_area_height = 160 - - # Swap-in values - self.displayed_characters = [] # Must be an ordered list rather than a sprite group - self.current_text_string = "" - self.displayed_strings = [""] # list of text lines - self.rendered_text_surfaces = [None] - self.line_number = 0 - self.current_line_starting_index = 0 - self.current_font = None # An index of the 'fonts' value - self.current_name_font = None - self.current_font_height = 0 - self.current_voice = None - self.voice_delay = 0 - self.script_index = -1 - - def load_sequence(self, seq_id): - """ - Load a dialog sequence from the dialog - definition. Only one sequence is loaded - at a time. Also resets sequence values. - """ - self.dialog_sequence = DIALOGS[seq_id] - self.sequence_index = 0 - -############################ -# Section 2 - Dialog class # -############################ - -class Dialog(object): - """ - A Dialog is an interval of text that is displayed - during interactive modes, such as in battle. - """ - - def __init__(self, manager, dialogdef): - - # Saved values - self.manager = manager - - # Important values - self.name = None - self.script = [] - self.fonts = {} - self.text_speed = 1 - self.text_write_timer = 0 - self.current_text_char_index = 0 - self.continue_ready = False - self.max_line = 0 - self.total_lines = 0 - - # Universal elements - # TODO: Pos vals should not be hardcoded like this - self.name_box = None - self.name_box_pos = (20, 480) - self.rendered_name = None - self.rendered_name_topleft = (0, 0) # Dynamically calculated - self.text_box = None - self.text_box_pos = (0, 508) - self.continue_prompt = None - self.continue_prompt_pos = (964, 748) - self.text_area_topleft = (48, 560) - self.text_area_height = 160 - self.background = None - - # Swap-in values - self.displayed_characters = [] # Must be an ordered list rather than a sprite group - self.current_text_string = "" - self.displayed_strings = [""] # list of text lines - self.rendered_text_surfaces = [None] - self.line_number = 0 - self.current_line_starting_index = 0 - self.current_font = None # An index of the 'fonts' value - self.current_name_font = None - self.current_font_height = 0 - self.current_voice = None - self.voice_delay = 0 - self.script_index = -1 - - # Setup - sh = self.manager.bus.fetch("sheet_manager", "sheets") - - # Load univeral elements - self.name_box = entity.Entity(sh["still_scene_name_box_1"]) - self.name_box.set_position(self.name_box_pos) - self.text_box = entity.Entity(sh["still_scene_text_box_1"]) - self.text_box.set_position(self.text_box_pos) - self.continue_prompt = entity.Entity(sh["continue_prompt_1"], (0, 0), sh["continue_prompt_1"].animations["shimmer"], True) - self.continue_prompt.set_position(self.continue_prompt_pos) - - # Cycle in for the first time - self.cycle_script_segment() diff --git a/src/scene.py b/src/scene.py @@ -109,6 +109,8 @@ class StillScene(object): self.current_name_font = None self.current_font_height = 0 self.current_voice = None + self.current_portrait = None + self.current_portrait_rect = None self.voice_delay = 0 self.script_index = -1 @@ -151,6 +153,8 @@ class StillScene(object): self.rendered_text_surfaces = [None] self.rendered_name = None self.rendered_name_topleft = (0, 0) + self.current_portrait = None + self.current_portrait_rect = None self.line_number = 0 self.current_line_starting_index = 0 self.displayed_characters = [] @@ -180,6 +184,10 @@ class StillScene(object): if self.script[self.script_index]["speaker"] != None: self.rendered_name = self.current_name_font.render(self.script[self.script_index]["speaker"], False, (255, 255, 255)).convert() self.rendered_name_topleft = (self.name_box_pos[0] + ((self.name_box.image.get_width() / 2) - (self.rendered_name.get_width() / 2)), self.name_box_pos[1] + ((self.name_box.image.get_height() / 2) - (self.rendered_name.get_height() / 2))) + if self.script[self.script_index]["portrait"] != None: + self.current_portrait = sh[self.script[self.script_index]["portrait"]].sprites[(0, 0)] + self.current_portrait_rect = self.current_portrait.get_rect() + self.current_portrait_rect.topleft = self.text_area_topleft # Handle effects self.manager.trigger_effects(self.script[self.script_index]["effects"]) @@ -269,6 +277,7 @@ class StillScene(object): """ Update the StillScene and draw visible elements. """ + xoff = 0 if surface != None: self.background.update(surface) @@ -285,12 +294,16 @@ class StillScene(object): if self.continue_ready: self.continue_prompt.update(surface) + + if self.current_portrait != None: + xoff = self.current_portrait_rect.width + 4 + surface.blit(self.current_portrait, self.current_portrait_rect) self.write_text() l = 0 for t in self.rendered_text_surfaces: if t != None: - surface.blit(t, (self.text_area_topleft[0], self.text_area_topleft[1] + (self.current_font_height * l) + 2)) + surface.blit(t, (self.text_area_topleft[0] + xoff, self.text_area_topleft[1] + (self.current_font_height * l) + 2)) l += 1 if self.current_voice != None and not self.continue_ready: