From 589f825765b216388f1830e5e1e381d249e568ab Mon Sep 17 00:00:00 2001 From: Nicolas Margulies Date: Thu, 19 Nov 2020 12:55:06 +0100 Subject: [PATCH] Added logs to the layout, clear logs on new game (tests still aren't fixed) --- squirrelbattle/display/display.py | 2 +- squirrelbattle/display/display_manager.py | 4 +++- squirrelbattle/display/logsdisplay.py | 11 ++++++++--- squirrelbattle/game.py | 1 + 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/squirrelbattle/display/display.py b/squirrelbattle/display/display.py index 47e4bce..1e47189 100644 --- a/squirrelbattle/display/display.py +++ b/squirrelbattle/display/display.py @@ -33,7 +33,7 @@ class Display: self.width = width self.height = height if hasattr(self, "pad") and resize_pad: - self.pad.resize(self.height - 1, self.width - 1) + self.pad.resize(self.height, self.width) def refresh(self, *args, resize_pad: bool = True) -> None: if len(args) == 4: diff --git a/squirrelbattle/display/display_manager.py b/squirrelbattle/display/display_manager.py index 408086c..a4636eb 100644 --- a/squirrelbattle/display/display_manager.py +++ b/squirrelbattle/display/display_manager.py @@ -47,7 +47,9 @@ class DisplayManager: self.mapdisplay.refresh(0, 0, self.rows * 4 // 5, self.cols, resize_pad=False) self.statsdisplay.refresh(self.rows * 4 // 5, 0, - self.rows // 5, self.cols) + self.rows // 10, self.cols) + self.logsdisplay.refresh(self.rows * 9 // 10, 0, + self.rows // 10, self.cols) if self.game.state == GameMode.MAINMENU: self.mainmenudisplay.refresh(0, 0, self.rows, self.cols) if self.game.state == GameMode.SETTINGS: diff --git a/squirrelbattle/display/logsdisplay.py b/squirrelbattle/display/logsdisplay.py index bacbbf7..36adcaa 100644 --- a/squirrelbattle/display/logsdisplay.py +++ b/squirrelbattle/display/logsdisplay.py @@ -12,6 +12,11 @@ class LogsDisplay(Display): self.logs = logs def display(self) -> None: - messages = self.logs.messages[-self.height:].reverse() - for i, y in enumerate(range(self.y + self.height - 1, self.y - 1, - 1)): - self.pad.addstr(y, self.x, messages[i][:self.width]) + print(type(self.logs.messages), flush=True) + messages = self.logs.messages[-self.height:] + messages = messages[::-1] + self.pad.clear() + for i in range(min(self.height, len(messages))): + self.pad.addstr(self.height - i - 1, self.x, messages[i][:self.width]) + self.pad.refresh(0, 0, self.y, self.x, self.y + self.height, + self.x + self.width) diff --git a/squirrelbattle/game.py b/squirrelbattle/game.py index 320ecff..0bb3024 100644 --- a/squirrelbattle/game.py +++ b/squirrelbattle/game.py @@ -42,6 +42,7 @@ class Game: # TODO generate a new map procedurally self.map = Map.load(ResourceManager.get_asset_path("example_map_2.txt")) self.map.logs = self.logs + self.logs.clear() self.player = Player() self.map.add_entity(self.player) self.player.move(self.map.start_y, self.map.start_x)