Reshaped the game layout using new lines and boxes

This commit is contained in:
Nicolas Margulies 2020-11-20 18:07:09 +01:00
parent 9ca6561bc3
commit ca57fae19d
4 changed files with 26 additions and 34 deletions

View File

@ -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:

View File

@ -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)

View File

@ -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,16 +34,7 @@ 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.clear() self.menubox.refresh(self.y, self.x, self.height, self.width)
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.pad.clear() self.pad.clear()
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,
@ -90,7 +81,7 @@ 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(

View File

@ -17,31 +17,27 @@ 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): for _ in range(self.width - len(string2) - 1):
string2 = string2 + " " string2 = string2 + " "
self.pad.addstr(1, 0, string2) self.pad.addstr(0, 0, string2)
string3 = "Stats : STR {} INT {} CHR {} DEX {} CON {}"\ string3 = "STR {}\nINT {}\nCHR {}\nDEX {}\nCON {}"\
.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): for _ in range(self.width - len(string3) - 1):
string3 = string3 + " " string3 = string3 + " "
self.pad.addstr(2, 0, string3) self.pad.addstr(3, 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 +45,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)