Merge branch 'display-fixes' into 'master'
Display fixes see #15 Closes #15 See merge request ynerant/squirrel-battle!21
This commit was merged in pull request #102.
	This commit is contained in:
		@@ -33,7 +33,7 @@ class Display:
 | 
				
			|||||||
        self.width = width
 | 
					        self.width = width
 | 
				
			||||||
        self.height = height
 | 
					        self.height = height
 | 
				
			||||||
        if hasattr(self, "pad") and resize_pad:
 | 
					        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:
 | 
					    def refresh(self, *args, resize_pad: bool = True) -> None:
 | 
				
			||||||
        if len(args) == 4:
 | 
					        if len(args) == 4:
 | 
				
			||||||
@@ -50,3 +50,59 @@ class Display:
 | 
				
			|||||||
    @property
 | 
					    @property
 | 
				
			||||||
    def cols(self) -> int:
 | 
					    def cols(self) -> int:
 | 
				
			||||||
        return curses.COLS if self.screen else 42
 | 
					        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)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,5 @@
 | 
				
			|||||||
import curses
 | 
					import curses
 | 
				
			||||||
 | 
					from squirrelbattle.display.display import VerticalSplit, HorizontalSplit
 | 
				
			||||||
from squirrelbattle.display.mapdisplay import MapDisplay
 | 
					from squirrelbattle.display.mapdisplay import MapDisplay
 | 
				
			||||||
from squirrelbattle.display.statsdisplay import StatsDisplay
 | 
					from squirrelbattle.display.statsdisplay import StatsDisplay
 | 
				
			||||||
from squirrelbattle.display.menudisplay import SettingsMenuDisplay, \
 | 
					from squirrelbattle.display.menudisplay import SettingsMenuDisplay, \
 | 
				
			||||||
@@ -22,6 +23,8 @@ class DisplayManager:
 | 
				
			|||||||
                                               screen, pack)
 | 
					                                               screen, pack)
 | 
				
			||||||
        self.settingsmenudisplay = SettingsMenuDisplay(screen, pack)
 | 
					        self.settingsmenudisplay = SettingsMenuDisplay(screen, pack)
 | 
				
			||||||
        self.logsdisplay = LogsDisplay(screen, pack)
 | 
					        self.logsdisplay = LogsDisplay(screen, pack)
 | 
				
			||||||
 | 
					        self.hbar = HorizontalSplit(screen, pack)
 | 
				
			||||||
 | 
					        self.vbar = VerticalSplit(screen, pack)
 | 
				
			||||||
        self.displays = [self.statsdisplay, self.mapdisplay,
 | 
					        self.displays = [self.statsdisplay, self.mapdisplay,
 | 
				
			||||||
                         self.mainmenudisplay, self.settingsmenudisplay,
 | 
					                         self.mainmenudisplay, self.settingsmenudisplay,
 | 
				
			||||||
                         self.logsdisplay]
 | 
					                         self.logsdisplay]
 | 
				
			||||||
@@ -44,12 +47,14 @@ class DisplayManager:
 | 
				
			|||||||
    def refresh(self) -> None:
 | 
					    def refresh(self) -> None:
 | 
				
			||||||
        if self.game.state == GameMode.PLAY:
 | 
					        if self.game.state == GameMode.PLAY:
 | 
				
			||||||
            # The map pad has already the good size
 | 
					            # The map pad has already the good size
 | 
				
			||||||
            self.mapdisplay.refresh(0, 0, self.rows * 4 // 5, self.cols,
 | 
					            self.mapdisplay.refresh(0, 0, self.rows * 4 // 5,
 | 
				
			||||||
                                    resize_pad=False)
 | 
					                                    self.cols * 4 // 5, resize_pad=False)
 | 
				
			||||||
            self.statsdisplay.refresh(self.rows * 4 // 5, 0,
 | 
					            self.statsdisplay.refresh(0, self.cols * 4 // 5 + 1,
 | 
				
			||||||
                                      self.rows // 10, self.cols)
 | 
					                                      self.rows, self.cols // 5 - 1)
 | 
				
			||||||
            self.logsdisplay.refresh(self.rows * 9 // 10, 0,
 | 
					            self.logsdisplay.refresh(self.rows * 4 // 5 + 1, 0,
 | 
				
			||||||
                                     self.rows // 10, self.cols)
 | 
					                                     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:
 | 
					        if self.game.state == GameMode.MAINMENU:
 | 
				
			||||||
            self.mainmenudisplay.refresh(0, 0, self.rows, self.cols)
 | 
					            self.mainmenudisplay.refresh(0, 0, self.rows, self.cols)
 | 
				
			||||||
        if self.game.state == GameMode.SETTINGS:
 | 
					        if self.game.state == GameMode.SETTINGS:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,5 +19,5 @@ class LogsDisplay(Display):
 | 
				
			|||||||
        for i in range(min(self.height, len(messages))):
 | 
					        for i in range(min(self.height, len(messages))):
 | 
				
			||||||
            self.pad.addstr(self.height - i - 1, self.x,
 | 
					            self.pad.addstr(self.height - i - 1, self.x,
 | 
				
			||||||
                            messages[i][:self.width])
 | 
					                            messages[i][:self.width])
 | 
				
			||||||
        self.pad.refresh(0, 0, self.y, self.x, self.y + self.height,
 | 
					        self.pad.refresh(0, 0, self.y, self.x, self.y + self.height - 1,
 | 
				
			||||||
                         self.x + self.width)
 | 
					                         self.x + self.width - 1)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,16 +1,16 @@
 | 
				
			|||||||
from typing import List
 | 
					from typing import List
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from squirrelbattle.menus import Menu, MainMenu
 | 
					from squirrelbattle.menus import Menu, MainMenu
 | 
				
			||||||
from .display import Display
 | 
					from .display import Display, Box
 | 
				
			||||||
from ..resources import ResourceManager
 | 
					from ..resources import ResourceManager
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class MenuDisplay(Display):
 | 
					class MenuDisplay(Display):
 | 
				
			||||||
    position: int
 | 
					    position: int
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __init__(self, *args):
 | 
					    def __init__(self, *args, **kwargs):
 | 
				
			||||||
        super().__init__(*args)
 | 
					        super().__init__(*args, **kwargs)
 | 
				
			||||||
        self.menubox = self.newpad(self.rows, self.cols)
 | 
					        self.menubox = Box(*args, **kwargs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def update_menu(self, menu: Menu) -> None:
 | 
					    def update_menu(self, menu: Menu) -> None:
 | 
				
			||||||
        self.menu = menu
 | 
					        self.menu = menu
 | 
				
			||||||
@@ -34,15 +34,8 @@ class MenuDisplay(Display):
 | 
				
			|||||||
            if self.height - 2 >= self.trueheight - self.menu.position else 0
 | 
					            if self.height - 2 >= self.trueheight - self.menu.position else 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Menu box
 | 
					        # Menu box
 | 
				
			||||||
        self.menubox.addstr(0, 0, "┏" + "━" * (self.width - 2) + "┓")
 | 
					        self.menubox.refresh(self.y, self.x, self.height, self.width)
 | 
				
			||||||
        for i in range(1, self.height - 1):
 | 
					        self.pad.clear()
 | 
				
			||||||
            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.update_pad()
 | 
					        self.update_pad()
 | 
				
			||||||
        self.pad.refresh(cornery, 0, self.y + 1, self.x + 2,
 | 
					        self.pad.refresh(cornery, 0, self.y + 1, self.x + 2,
 | 
				
			||||||
                         self.height - 2 + self.y,
 | 
					                         self.height - 2 + self.y,
 | 
				
			||||||
@@ -88,7 +81,8 @@ class MainMenuDisplay(Display):
 | 
				
			|||||||
        for i in range(len(self.title)):
 | 
					        for i in range(len(self.title)):
 | 
				
			||||||
            self.pad.addstr(4 + i, max(self.width // 2
 | 
					            self.pad.addstr(4 + i, max(self.width // 2
 | 
				
			||||||
                            - len(self.title[0]) // 2 - 1, 0), self.title[i])
 | 
					                            - 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)
 | 
					        menuwidth = min(self.menudisplay.preferred_width, self.width)
 | 
				
			||||||
        menuy, menux = len(self.title) + 8, self.width // 2 - menuwidth // 2 - 1
 | 
					        menuy, menux = len(self.title) + 8, self.width // 2 - menuwidth // 2 - 1
 | 
				
			||||||
        self.menudisplay.refresh(
 | 
					        self.menudisplay.refresh(
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,31 +17,23 @@ class StatsDisplay(Display):
 | 
				
			|||||||
        self.player = p
 | 
					        self.player = p
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def update_pad(self) -> None:
 | 
					    def update_pad(self) -> None:
 | 
				
			||||||
        string = ""
 | 
					        string2 = "Player -- LVL {}\nEXP {}/{}\nHP {}/{}"\
 | 
				
			||||||
        for _ in range(self.width - 1):
 | 
					 | 
				
			||||||
            string = string + "-"
 | 
					 | 
				
			||||||
        self.pad.addstr(0, 0, string)
 | 
					 | 
				
			||||||
        string2 = "Player -- LVL {}  EXP {}/{}  HP {}/{}"\
 | 
					 | 
				
			||||||
            .format(self.player.level, self.player.current_xp,
 | 
					            .format(self.player.level, self.player.current_xp,
 | 
				
			||||||
                    self.player.max_xp, self.player.health,
 | 
					                    self.player.max_xp, self.player.health,
 | 
				
			||||||
                    self.player.maxhealth)
 | 
					                    self.player.maxhealth)
 | 
				
			||||||
        for _ in range(self.width - len(string2) - 1):
 | 
					        self.pad.addstr(0, 0, string2)
 | 
				
			||||||
            string2 = string2 + " "
 | 
					        string3 = "STR {}\nINT {}\nCHR {}\nDEX {}\nCON {}"\
 | 
				
			||||||
        self.pad.addstr(1, 0, string2)
 | 
					 | 
				
			||||||
        string3 = "Stats : STR {}  INT {}  CHR {}  DEX {} CON {}"\
 | 
					 | 
				
			||||||
            .format(self.player.strength,
 | 
					            .format(self.player.strength,
 | 
				
			||||||
                    self.player.intelligence, self.player.charisma,
 | 
					                    self.player.intelligence, self.player.charisma,
 | 
				
			||||||
                    self.player.dexterity, self.player.constitution)
 | 
					                    self.player.dexterity, self.player.constitution)
 | 
				
			||||||
        for _ in range(self.width - len(string3) - 1):
 | 
					        self.pad.addstr(3, 0, string3)
 | 
				
			||||||
            string3 = string3 + " "
 | 
					 | 
				
			||||||
        self.pad.addstr(2, 0, string3)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        inventory_str = "Inventaire : " + "".join(
 | 
					        inventory_str = "Inventaire : " + "".join(
 | 
				
			||||||
            self.pack[item.name.upper()] for item in self.player.inventory)
 | 
					            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:
 | 
					        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
 | 
					                            curses.A_BOLD | curses.A_BLINK | curses.A_STANDOUT
 | 
				
			||||||
                            | self.color_pair(3))
 | 
					                            | self.color_pair(3))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -49,4 +41,4 @@ class StatsDisplay(Display):
 | 
				
			|||||||
        self.pad.clear()
 | 
					        self.pad.clear()
 | 
				
			||||||
        self.update_pad()
 | 
					        self.update_pad()
 | 
				
			||||||
        self.pad.refresh(0, 0, self.y, self.x,
 | 
					        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)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user