First pass on the logs
The newly-added logs manage a list of messages. Entities do register a message to it when hitting each other. Display is created, but not yet added to the layout actually displayed.
This commit is contained in:
@ -3,6 +3,7 @@ from squirrelbattle.display.mapdisplay import MapDisplay
|
||||
from squirrelbattle.display.statsdisplay import StatsDisplay
|
||||
from squirrelbattle.display.menudisplay import SettingsMenuDisplay, \
|
||||
MainMenuDisplay
|
||||
from squirrelbattle.display.logsdisplay import LogsDisplay
|
||||
from squirrelbattle.display.texturepack import TexturePack
|
||||
from typing import Any
|
||||
from squirrelbattle.game import Game, GameMode
|
||||
@ -20,8 +21,10 @@ class DisplayManager:
|
||||
self.mainmenudisplay = MainMenuDisplay(self.game.main_menu,
|
||||
screen, pack)
|
||||
self.settingsmenudisplay = SettingsMenuDisplay(screen, pack)
|
||||
self.logsdisplay = LogsDisplay(screen, pack)
|
||||
self.displays = [self.statsdisplay, self.mapdisplay,
|
||||
self.mainmenudisplay, self.settingsmenudisplay]
|
||||
self.mainmenudisplay, self.settingsmenudisplay,
|
||||
self.logsdisplay]
|
||||
self.update_game_components()
|
||||
|
||||
def handle_display_action(self, action: DisplayActions) -> None:
|
||||
@ -36,6 +39,7 @@ class DisplayManager:
|
||||
self.mapdisplay.update_map(self.game.map)
|
||||
self.statsdisplay.update_player(self.game.player)
|
||||
self.settingsmenudisplay.update_menu(self.game.settings_menu)
|
||||
self.logsdisplay.update_logs(self.game.logs)
|
||||
|
||||
def refresh(self) -> None:
|
||||
if self.game.state == GameMode.PLAY:
|
||||
|
17
squirrelbattle/display/logsdisplay.py
Normal file
17
squirrelbattle/display/logsdisplay.py
Normal file
@ -0,0 +1,17 @@
|
||||
from squirrelbattle.display.display import Display
|
||||
from squirrelbattle.interfaces import Logs
|
||||
|
||||
|
||||
class LogsDisplay(Display):
|
||||
|
||||
def __init__(self, *args) -> None:
|
||||
super().__init__(*args)
|
||||
self.pad = self.newpad(self.rows, self.cols)
|
||||
|
||||
def update_logs(self, logs: Logs) -> None:
|
||||
self.logs = logs
|
||||
|
||||
def display(self) -> None:
|
||||
messages = self.logs.messages[-self.height:].reverse()
|
||||
for i, y in enumerate(range(self.y + self.height - 1, self.y - 1, - 1)):
|
||||
self.pad.addstr(y, self.x, messages[i][:self.width])
|
Reference in New Issue
Block a user