2020-11-06 14:34:24 +00:00
|
|
|
import curses
|
2020-11-08 22:40:03 +00:00
|
|
|
from typing import Any, Union
|
|
|
|
|
|
|
|
from dungeonbattle.tests.screen import FakePad
|
2020-11-09 00:33:23 +00:00
|
|
|
from dungeonbattle.display.mapdisplay import MapDisplay
|
|
|
|
from dungeonbattle.display.statsdisplay import StatsDisplay
|
|
|
|
from dungeonbattle.display.menudisplay import MenuDisplay
|
|
|
|
from dungeonbattle.interfaces import Map
|
|
|
|
from .entities.player import Player
|
2020-11-06 14:34:24 +00:00
|
|
|
|
|
|
|
class Display:
|
2020-11-09 00:33:23 +00:00
|
|
|
map: Map
|
|
|
|
player: Player
|
|
|
|
|
|
|
|
def __init__(self, screen: Any, texture: Any):
|
2020-11-06 14:34:24 +00:00
|
|
|
self.screen = screen
|
2020-11-09 00:33:23 +00:00
|
|
|
self.texture = texture
|
|
|
|
self.mapdisplay = MapDisplay(self.screen, self.texture, curses.LINES * 4//5, curses.COLS)
|
|
|
|
self.statsdisplay = StatsDisplay(self.screen, curses.LINES//5, curses.COLS)
|
|
|
|
|
|
|
|
def refresh(self, m : Map, p : Player) -> None:
|
|
|
|
self.map = m
|
|
|
|
self.player = p
|
2020-11-09 00:39:15 +00:00
|
|
|
self.mapdisplay.refresh(self.map, self.player)
|
2020-11-09 00:33:23 +00:00
|
|
|
self.statsdisplay.refresh(self.player)
|
2020-11-09 00:39:15 +00:00
|
|
|
# self.menudisplay.refresh(self.position)
|
2020-11-08 22:40:03 +00:00
|
|
|
|
|
|
|
def newpad(self, height: int, width: int) -> Union[FakePad, Any]:
|
2020-11-08 22:48:26 +00:00
|
|
|
return curses.newpad(height, width) if self.screen else FakePad()
|
2020-11-08 23:44:08 +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 height(self) -> int:
|
|
|
|
return self.rows
|
|
|
|
|
|
|
|
@property
|
|
|
|
def cols(self) -> int:
|
|
|
|
return curses.COLS if self.screen else 42
|
|
|
|
|
|
|
|
@property
|
|
|
|
def width(self) -> int:
|
|
|
|
return self.cols
|