2020-11-10 17:08:06 +00:00
|
|
|
import curses
|
|
|
|
from dungeonbattle.display.mapdisplay import MapDisplay
|
|
|
|
from dungeonbattle.display.statsdisplay import StatsDisplay
|
2020-11-10 18:40:59 +00:00
|
|
|
from dungeonbattle.display.menudisplay import MainMenuDisplay
|
2020-11-10 17:08:06 +00:00
|
|
|
from dungeonbattle.display.texturepack import TexturePack
|
|
|
|
from typing import Any
|
2020-11-10 18:40:59 +00:00
|
|
|
from dungeonbattle.game import Game, GameMode
|
2020-11-10 17:08:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
class DisplayManager:
|
2020-11-10 19:34:22 +00:00
|
|
|
|
2020-11-10 17:08:06 +00:00
|
|
|
def __init__(self, screen: Any, g: Game):
|
|
|
|
self.game = g
|
|
|
|
self.screen = screen
|
2020-11-10 18:40:59 +00:00
|
|
|
pack = TexturePack.get_pack(self.game.settings.TEXTURE_PACK)
|
|
|
|
self.mapdisplay = MapDisplay(screen, pack)
|
|
|
|
self.statsdisplay = StatsDisplay(screen, pack)
|
2020-11-10 19:34:22 +00:00
|
|
|
self.mainmenudisplay = MainMenuDisplay(self.game.main_menu,
|
|
|
|
screen, pack)
|
|
|
|
self.displays = [self.statsdisplay, self.mapdisplay,
|
|
|
|
self.mainmenudisplay]
|
2020-11-10 17:08:06 +00:00
|
|
|
self.update_game_components()
|
|
|
|
|
2020-11-10 19:34:22 +00:00
|
|
|
def update_game_components(self) -> None:
|
2020-11-10 17:08:06 +00:00
|
|
|
for d in self.displays:
|
|
|
|
d.pack = TexturePack.get_pack(self.game.settings.TEXTURE_PACK)
|
|
|
|
self.mapdisplay.update_map(self.game.map)
|
|
|
|
self.statsdisplay.update_player(self.game.player)
|
|
|
|
|
|
|
|
def refresh(self) -> None:
|
2020-11-10 18:40:59 +00:00
|
|
|
if self.game.state == GameMode.PLAY:
|
|
|
|
self.mapdisplay.refresh(0, 0, self.rows * 4 // 5, self.cols)
|
2020-11-10 19:34:22 +00:00
|
|
|
self.statsdisplay.refresh(self.rows * 4 // 5, 0,
|
|
|
|
self.rows // 5, self.cols)
|
2020-11-10 18:40:59 +00:00
|
|
|
if self.game.state == GameMode.MAINMENU:
|
2020-11-10 19:34:22 +00:00
|
|
|
self.mainmenudisplay.refresh(0, 0, self.rows, self.cols)
|
2020-11-10 17:08:06 +00:00
|
|
|
|
|
|
|
def ensure_resized(self, *pads) -> bool:
|
|
|
|
"""
|
|
|
|
If the window got resized, ensure that the pads are also resized.
|
|
|
|
"""
|
|
|
|
y, x = self.screen.getmaxyx() if self.screen else (0, 0)
|
|
|
|
for pad in pads:
|
|
|
|
pad.resize(y, x)
|
|
|
|
if self.screen and curses.is_term_resized(self.rows, self.cols):
|
|
|
|
curses.resizeterm(y, x)
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
@property
|
|
|
|
def rows(self) -> int:
|
|
|
|
return curses.LINES if self.screen else 42
|
|
|
|
|
|
|
|
@property
|
|
|
|
def cols(self) -> int:
|
2020-11-10 19:34:22 +00:00
|
|
|
return curses.COLS if self.screen else 42
|