Reshaped the game layout using new lines and boxes
This commit is contained in:
parent
9ca6561bc3
commit
ca57fae19d
@ -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:
|
||||
|
@ -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)
|
||||
|
@ -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(
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user