diff --git a/squirrelbattle/display/display.py b/squirrelbattle/display/display.py index 1e47189..0cdba98 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: @@ -50,3 +50,59 @@ 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 - 1, 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 - 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) 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 fca1ddf..3c4e5a1 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,15 +34,8 @@ class MenuDisplay(Display): if self.height - 2 >= self.trueheight - self.menu.position else 0 # Menu box - 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, self.height - 2 + self.y, @@ -88,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.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..f47862e 100644 --- a/squirrelbattle/display/statsdisplay.py +++ b/squirrelbattle/display/statsdisplay.py @@ -17,31 +17,23 @@ 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 +41,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)