From 62599ea72c5f5fdeaa085186b64ec7c9eb2c3605 Mon Sep 17 00:00:00 2001 From: Nicolas Margulies Date: Fri, 20 Nov 2020 16:05:21 +0100 Subject: [PATCH 1/6] Clear menu pads before putting the new text in them, see #15 --- squirrelbattle/display/menudisplay.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/squirrelbattle/display/menudisplay.py b/squirrelbattle/display/menudisplay.py index fca1ddf..082772b 100644 --- a/squirrelbattle/display/menudisplay.py +++ b/squirrelbattle/display/menudisplay.py @@ -34,6 +34,7 @@ class MenuDisplay(Display): if self.height - 2 >= self.trueheight - self.menu.position else 0 # Menu box + self.menubox.clear() self.menubox.addstr(0, 0, "┏" + "━" * (self.width - 2) + "┓") for i in range(1, self.height - 1): self.menubox.addstr(i, 0, "┃" + " " * (self.width - 2) + "┃") @@ -43,6 +44,7 @@ class MenuDisplay(Display): self.menubox.refresh(0, 0, self.y, self.x, self.height + self.y, self.width + self.x) + self.pad.clear() self.update_pad() self.pad.refresh(cornery, 0, self.y + 1, self.x + 2, self.height - 2 + self.y, From 7e636078363d2b105cd137dc0501122092809e29 Mon Sep 17 00:00:00 2001 From: Nicolas Margulies Date: Fri, 20 Nov 2020 16:52:04 +0100 Subject: [PATCH 2/6] Added vertical and horizontal lines as display elements --- squirrelbattle/display/display.py | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/squirrelbattle/display/display.py b/squirrelbattle/display/display.py index 1e47189..eba86b9 100644 --- a/squirrelbattle/display/display.py +++ b/squirrelbattle/display/display.py @@ -50,3 +50,43 @@ class Display: @property def cols(self) -> int: return curses.COLS if self.screen else 42 + + +class VerticalSplit(Display): + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.pad = self.newpad(self.rows, 1) + + @property + def width(self) -> int: + return 1 + + @width.setter + def width(self, val: Any) -> None: + pass + + def display(self) -> None: + for i in range(self.height): + self.pad.addstr(i, 0, "┃") + self.pad.refresh(0, 0, self.y, self.x, self.y + self.height, self.x) + + +class HorizontalSplit(Display): + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.pad = self.newpad(1, self.cols) + + @property + def height(self) -> int: + return 1 + + @height.setter + def height(self, val: Any) -> None: + pass + + def display(self) -> None: + for i in range(self.width): + self.pad.addstr(0, i, "━") + self.pad.refresh(0, 0, self.y, self.x, self.y, self.x + self.width) From 9ca6561bc3e83f27203e28981c6eb63c936a1b8e Mon Sep 17 00:00:00 2001 From: Nicolas Margulies Date: Fri, 20 Nov 2020 18:06:43 +0100 Subject: [PATCH 3/6] Added a box element --- squirrelbattle/display/display.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/squirrelbattle/display/display.py b/squirrelbattle/display/display.py index eba86b9..d1ead44 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, self.width) + self.pad.resize(self.height + 1, self.width + 1) def refresh(self, *args, resize_pad: bool = True) -> None: if len(args) == 4: @@ -69,7 +69,7 @@ class VerticalSplit(Display): def display(self) -> None: for i in range(self.height): self.pad.addstr(i, 0, "┃") - self.pad.refresh(0, 0, self.y, self.x, self.y + self.height, self.x) + self.pad.refresh(0, 0, self.y, self.x, self.y + self.height - 1, self.x) class HorizontalSplit(Display): @@ -89,4 +89,19 @@ class HorizontalSplit(Display): def display(self) -> None: for i in range(self.width): self.pad.addstr(0, i, "━") - self.pad.refresh(0, 0, self.y, self.x, self.y, self.x + self.width) + self.pad.refresh(0, 0, self.y, self.x, self.y, self.x + self.width - 1) + +class Box(Display): + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.pad = self.newpad(self.rows, self.cols) + + def display(self) -> None: + self.pad.addstr(0, 0, "┏" + "━" * (self.width - 2) + "┓") + for i in range(1, self.height - 1): + self.pad.addstr(i, 0, "┃") + self.pad.addstr(i, self.width - 1, "┃") + self.pad.addstr(self.height - 1, 0, + "┗" + "━" * (self.width - 2) + "┛") + self.pad.refresh(0, 0, self.y, self.x, self.y + self.height - 1, self.x + self.width - 1) From ca57fae19d39b1aeb32dbe36abe6ea9abd6f9a66 Mon Sep 17 00:00:00 2001 From: Nicolas Margulies Date: Fri, 20 Nov 2020 18:07:09 +0100 Subject: [PATCH 4/6] Reshaped the game layout using new lines and boxes --- squirrelbattle/display/display_manager.py | 17 +++++++++++------ squirrelbattle/display/logsdisplay.py | 4 ++-- squirrelbattle/display/menudisplay.py | 21 ++++++--------------- squirrelbattle/display/statsdisplay.py | 18 +++++++----------- 4 files changed, 26 insertions(+), 34 deletions(-) diff --git a/squirrelbattle/display/display_manager.py b/squirrelbattle/display/display_manager.py index a4636eb..d50dfa1 100644 --- a/squirrelbattle/display/display_manager.py +++ b/squirrelbattle/display/display_manager.py @@ -1,4 +1,5 @@ import curses +from squirrelbattle.display.display import VerticalSplit, HorizontalSplit from squirrelbattle.display.mapdisplay import MapDisplay from squirrelbattle.display.statsdisplay import StatsDisplay from squirrelbattle.display.menudisplay import SettingsMenuDisplay, \ @@ -22,6 +23,8 @@ class DisplayManager: screen, pack) self.settingsmenudisplay = SettingsMenuDisplay(screen, pack) self.logsdisplay = LogsDisplay(screen, pack) + self.hbar = HorizontalSplit(screen, pack) + self.vbar = VerticalSplit(screen, pack) self.displays = [self.statsdisplay, self.mapdisplay, self.mainmenudisplay, self.settingsmenudisplay, self.logsdisplay] @@ -44,12 +47,14 @@ class DisplayManager: def refresh(self) -> None: if self.game.state == GameMode.PLAY: # The map pad has already the good size - self.mapdisplay.refresh(0, 0, self.rows * 4 // 5, self.cols, - resize_pad=False) - self.statsdisplay.refresh(self.rows * 4 // 5, 0, - self.rows // 10, self.cols) - self.logsdisplay.refresh(self.rows * 9 // 10, 0, - self.rows // 10, self.cols) + self.mapdisplay.refresh(0, 0, self.rows * 4 // 5, + self.cols * 4 // 5, resize_pad=False) + self.statsdisplay.refresh(0, self.cols * 4 // 5 + 1, + self.rows, self.cols // 5 - 1) + self.logsdisplay.refresh(self.rows * 4 // 5 + 1, 0, + self.rows // 5 - 1, self.cols * 4 // 5) + self.hbar.refresh(self.rows * 4 // 5, 0, 1, self.cols * 4 // 5) + self.vbar.refresh(0, self.cols * 4 // 5, self.rows, 1) 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 0d95915..368c036 100644 --- a/squirrelbattle/display/logsdisplay.py +++ b/squirrelbattle/display/logsdisplay.py @@ -19,5 +19,5 @@ class LogsDisplay(Display): 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) + self.pad.refresh(0, 0, self.y, self.x, self.y + self.height - 1, + self.x + self.width - 1) diff --git a/squirrelbattle/display/menudisplay.py b/squirrelbattle/display/menudisplay.py index 082772b..443722f 100644 --- a/squirrelbattle/display/menudisplay.py +++ b/squirrelbattle/display/menudisplay.py @@ -1,16 +1,16 @@ from typing import List from squirrelbattle.menus import Menu, MainMenu -from .display import Display +from .display import Display, Box from ..resources import ResourceManager class MenuDisplay(Display): position: int - def __init__(self, *args): - super().__init__(*args) - self.menubox = self.newpad(self.rows, self.cols) + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.menubox = Box(*args, **kwargs) def update_menu(self, menu: Menu) -> None: self.menu = menu @@ -34,16 +34,7 @@ class MenuDisplay(Display): if self.height - 2 >= self.trueheight - self.menu.position else 0 # Menu box - self.menubox.clear() - self.menubox.addstr(0, 0, "┏" + "━" * (self.width - 2) + "┓") - for i in range(1, self.height - 1): - self.menubox.addstr(i, 0, "┃" + " " * (self.width - 2) + "┃") - self.menubox.addstr(self.height - 1, 0, - "┗" + "━" * (self.width - 2) + "┛") - - self.menubox.refresh(0, 0, self.y, self.x, - self.height + self.y, - self.width + self.x) + self.menubox.refresh(self.y, self.x, self.height, self.width) self.pad.clear() self.update_pad() self.pad.refresh(cornery, 0, self.y + 1, self.x + 2, @@ -90,7 +81,7 @@ class MainMenuDisplay(Display): for i in range(len(self.title)): self.pad.addstr(4 + i, max(self.width // 2 - len(self.title[0]) // 2 - 1, 0), self.title[i]) - self.pad.refresh(0, 0, self.y, self.x, self.height, self.width) + self.pad.refresh(0, 0, self.y, self.x, self.height + self.y - 1, self.width + self.x - 1) menuwidth = min(self.menudisplay.preferred_width, self.width) menuy, menux = len(self.title) + 8, self.width // 2 - menuwidth // 2 - 1 self.menudisplay.refresh( diff --git a/squirrelbattle/display/statsdisplay.py b/squirrelbattle/display/statsdisplay.py index 77ddb30..bc7a864 100644 --- a/squirrelbattle/display/statsdisplay.py +++ b/squirrelbattle/display/statsdisplay.py @@ -17,31 +17,27 @@ class StatsDisplay(Display): self.player = p def update_pad(self) -> None: - string = "" - for _ in range(self.width - 1): - string = string + "-" - self.pad.addstr(0, 0, string) - string2 = "Player -- LVL {} EXP {}/{} HP {}/{}"\ + string2 = "Player -- LVL {}\nEXP {}/{}\nHP {}/{}"\ .format(self.player.level, self.player.current_xp, self.player.max_xp, self.player.health, self.player.maxhealth) for _ in range(self.width - len(string2) - 1): string2 = string2 + " " - self.pad.addstr(1, 0, string2) - string3 = "Stats : STR {} INT {} CHR {} DEX {} CON {}"\ + self.pad.addstr(0, 0, string2) + string3 = "STR {}\nINT {}\nCHR {}\nDEX {}\nCON {}"\ .format(self.player.strength, self.player.intelligence, self.player.charisma, self.player.dexterity, self.player.constitution) for _ in range(self.width - len(string3) - 1): string3 = string3 + " " - self.pad.addstr(2, 0, string3) + self.pad.addstr(3, 0, string3) inventory_str = "Inventaire : " + "".join( self.pack[item.name.upper()] for item in self.player.inventory) - self.pad.addstr(3, 0, inventory_str) + self.pad.addstr(8, 0, inventory_str) if self.player.dead: - self.pad.addstr(4, 0, "VOUS ÊTES MORT", + self.pad.addstr(10, 0, "VOUS ÊTES MORT", curses.A_BOLD | curses.A_BLINK | curses.A_STANDOUT | self.color_pair(3)) @@ -49,4 +45,4 @@ class StatsDisplay(Display): self.pad.clear() self.update_pad() self.pad.refresh(0, 0, self.y, self.x, - 4 + self.y, self.width + self.x) + self.y + self.height - 1, self.width + self.x - 1) From 223c20e792e61fcfc16b65738bb2bf1f513599bf Mon Sep 17 00:00:00 2001 From: Nicolas Margulies Date: Fri, 20 Nov 2020 18:09:39 +0100 Subject: [PATCH 5/6] Linting --- squirrelbattle/display/display.py | 9 +++++---- squirrelbattle/display/menudisplay.py | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/squirrelbattle/display/display.py b/squirrelbattle/display/display.py index d1ead44..0cdba98 100644 --- a/squirrelbattle/display/display.py +++ b/squirrelbattle/display/display.py @@ -91,17 +91,18 @@ class HorizontalSplit(Display): self.pad.addstr(0, i, "━") self.pad.refresh(0, 0, self.y, self.x, self.y, self.x + self.width - 1) + class Box(Display): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.pad = self.newpad(self.rows, self.cols) - + def display(self) -> None: self.pad.addstr(0, 0, "┏" + "━" * (self.width - 2) + "┓") for i in range(1, self.height - 1): self.pad.addstr(i, 0, "┃") self.pad.addstr(i, self.width - 1, "┃") - self.pad.addstr(self.height - 1, 0, - "┗" + "━" * (self.width - 2) + "┛") - self.pad.refresh(0, 0, self.y, self.x, self.y + self.height - 1, self.x + self.width - 1) + self.pad.addstr(self.height - 1, 0, "┗" + "━" * (self.width - 2) + "┛") + self.pad.refresh(0, 0, self.y, self.x, self.y + self.height - 1, + self.x + self.width - 1) diff --git a/squirrelbattle/display/menudisplay.py b/squirrelbattle/display/menudisplay.py index 443722f..3c4e5a1 100644 --- a/squirrelbattle/display/menudisplay.py +++ b/squirrelbattle/display/menudisplay.py @@ -81,7 +81,8 @@ class MainMenuDisplay(Display): for i in range(len(self.title)): self.pad.addstr(4 + i, max(self.width // 2 - len(self.title[0]) // 2 - 1, 0), self.title[i]) - self.pad.refresh(0, 0, self.y, self.x, self.height + self.y - 1, self.width + self.x - 1) + self.pad.refresh(0, 0, self.y, self.x, self.height + self.y - 1, + self.width + self.x - 1) menuwidth = min(self.menudisplay.preferred_width, self.width) menuy, menux = len(self.title) + 8, self.width // 2 - menuwidth // 2 - 1 self.menudisplay.refresh( From b3df257103f619686c9c8ffc20db8e7bb3ca4aa9 Mon Sep 17 00:00:00 2001 From: Nicolas Margulies Date: Fri, 20 Nov 2020 18:12:30 +0100 Subject: [PATCH 6/6] Removed useless code --- squirrelbattle/display/statsdisplay.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/squirrelbattle/display/statsdisplay.py b/squirrelbattle/display/statsdisplay.py index bc7a864..f47862e 100644 --- a/squirrelbattle/display/statsdisplay.py +++ b/squirrelbattle/display/statsdisplay.py @@ -21,15 +21,11 @@ class StatsDisplay(Display): .format(self.player.level, self.player.current_xp, self.player.max_xp, self.player.health, self.player.maxhealth) - for _ in range(self.width - len(string2) - 1): - string2 = string2 + " " self.pad.addstr(0, 0, string2) string3 = "STR {}\nINT {}\nCHR {}\nDEX {}\nCON {}"\ .format(self.player.strength, self.player.intelligence, self.player.charisma, self.player.dexterity, self.player.constitution) - for _ in range(self.width - len(string3) - 1): - string3 = string3 + " " self.pad.addstr(3, 0, string3) inventory_str = "Inventaire : " + "".join(