Return to repo list

heart-of-gold

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

commit 5be4277ff865dd6a6fb95181f75e87e5e02ced58
parent 47a93e59fe4c96cf13b2bc0ffaf14bb3ae30592d
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Sat, 17 Oct 2020 17:17:50 -0500

StillScene text formatting advancement

Diffstat:
Msrc/scene.py | 26+++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/src/scene.py b/src/scene.py @@ -72,7 +72,7 @@ class StillScene(object): self.text_write_timer = 0 self.current_text_char_index = 0 self.continue_ready = False - self.max_line = 100 + self.max_line = 0 # Universal elements # TODO: Pos vals should not be hardcoded like this @@ -138,6 +138,7 @@ class StillScene(object): self.script_index += 1 self.current_font = self.fonts[self.script[self.script_index]["line_font"]] self.current_font_height = self.current_font.get_height() + self.max_line = int(3200 / self.current_font_height) self.current_text_string = self.script[self.script_index]["line"] for c in self.script[self.script_index]["characters"]: nc = vgo.VisibleGameObject(self.manager.game.sheet_manager.loaded_sheets[c["sheet"]], tuple(c["sprite"])) @@ -161,19 +162,34 @@ class StillScene(object): else: self.text_write_timer = 0 self.current_text_char_index += 1 - self.displayed_strings[self.line_number] = self.current_text_string[0:self.current_text_char_index] + self.displayed_strings[self.line_number] = self.current_text_string[self.max_line * self.line_number:self.current_text_char_index] # Check if we need to add a new line - if len(self.displayed_strings[self.line_number]) >= self.max_line: + if len(self.displayed_strings[self.line_number]) > self.max_line: self.displayed_strings.append("") self.rendered_text_surfaces.append(None) self.line_number += 1 + # Factor in line breaks in the middle of words + ch = len(self.displayed_strings[self.line_number - 1]) - 1 + while self.displayed_strings[self.line_number - 1][ch] != " ": + self.displayed_strings[self.line_number] += self.displayed_strings[self.line_number - 1][ch] + self.displayed_strings[self.line_number - 1] = self.displayed_strings[self.line_number - 1][0:ch] + ch -= 1 + + # Render the preceding line one last time + self.rendered_text_surfaces[self.line_number - 1] = self.current_font.render(self.displayed_strings[self.line_number - 1], False, (0, 0, 0)).convert() + + # Compensate for initial white space + compen = self.displayed_strings[self.line_number] + while len(compen) > 0 and compen[0] == " ": + compen = compen[1:len(compen)] + # Render to a surface - self.rendered_text_surfaces[self.line_number] = self.current_font.render(self.displayed_strings[self.line_number], False, (0, 0, 0)).convert() + self.rendered_text_surfaces[self.line_number] = self.current_font.render(compen, False, (0, 0, 0)).convert() # Check if we have written the last character - if self.current_text_char_index >= len(self.current_text_string) - 1: + if self.current_text_char_index >= len(self.current_text_string): self.continue_ready = True def continue_script(self):