Return to repo list

heart-of-gold

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

commit 27a80d1b2329cca72718422dc16be5742704e7a7
parent ee2f1cc91319e0d9dc6baca4f9422edd08d127ec
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Sat, 17 Oct 2020 21:25:20 -0500

Text now scrolls away in scenes if need be

Diffstat:
Mdata/json/scenes/testscene.json | 2+-
Msrc/scene.py | 13+++++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/data/json/scenes/testscene.json b/data/json/scenes/testscene.json @@ -12,7 +12,7 @@ "name_pos" : [20, 480], "line_font" : "A", "voice" : 0, - "line" : "Hi there. This is a test of the Scene system. This test is currently being done. This is a very long line meant to be automatically split appart several lines in the actual rendered display in the pygame window.", + "line" : "Hi there to anyone who is listening to this message. How are you? I am writing today in this huge string defined in a large JSON file that is used by the program to create a scene such as the one you are viewing right now. This is a test of the Scene system. This test is currently being done. This is a very long line meant to be automatically split appart several lines in the actual rendered display in the pygame window. This string is extremely long, of course. I'm going to keep talking for a little while longer in order to make sure this string is sufficiently long for my purposes. Whew!!!", "characters" : [ { "name" : "Jisella1", diff --git a/src/scene.py b/src/scene.py @@ -73,6 +73,7 @@ class StillScene(object): 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 @@ -83,6 +84,7 @@ class StillScene(object): 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 @@ -141,6 +143,7 @@ class StillScene(object): 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((3 * SCREEN_WIDTH) / self.current_font_height) + self.total_lines = int(self.text_area_height / 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"])) @@ -191,6 +194,16 @@ class StillScene(object): com2 = com2[1:len(com2)] self.rendered_text_surfaces[self.line_number - 1] = self.current_font.render(com2, False, (0, 0, 0)).convert() + # Scroll down if need be + if self.line_number > self.total_lines: + self.displayed_strings.pop(0) + self.line_number -= 1 + ln = 0 + for st in self.displayed_strings: + self.rendered_text_surfaces[ln] = self.current_font.render(st, False, (0, 0, 0)).convert() + ln += 1 + + # Compensate for initial white space compen = self.displayed_strings[self.line_number] while len(compen) > 0 and compen[0] == " ":