2021-01-10 09:46:17 +00:00
|
|
|
# Copyright (C) 2020-2021 by ÿnérant, eichhornchen, nicomarg, charlse
|
2020-11-27 15:33:17 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2020-11-19 11:03:05 +00:00
|
|
|
from squirrelbattle.display.display import Display
|
2020-12-18 14:07:09 +00:00
|
|
|
from squirrelbattle.game import Game
|
2020-11-19 11:03:05 +00:00
|
|
|
from squirrelbattle.interfaces import Logs
|
|
|
|
|
|
|
|
|
|
|
|
class LogsDisplay(Display):
|
2020-12-13 20:29:25 +00:00
|
|
|
"""
|
|
|
|
A class to handle the display of the logs.
|
|
|
|
"""
|
2020-11-19 11:03:05 +00:00
|
|
|
|
2021-01-05 09:27:39 +00:00
|
|
|
logs: Logs
|
2021-01-05 09:59:17 +00:00
|
|
|
|
2020-11-19 11:03:05 +00:00
|
|
|
def __init__(self, *args) -> None:
|
|
|
|
super().__init__(*args)
|
|
|
|
self.pad = self.newpad(self.rows, self.cols)
|
|
|
|
|
2020-12-18 14:07:09 +00:00
|
|
|
def update(self, game: Game) -> None:
|
|
|
|
self.logs = game.logs
|
2020-11-19 11:03:05 +00:00
|
|
|
|
|
|
|
def display(self) -> None:
|
2020-11-19 11:55:06 +00:00
|
|
|
messages = self.logs.messages[-self.height:]
|
|
|
|
messages = messages[::-1]
|
2020-11-26 21:20:14 +00:00
|
|
|
self.pad.erase()
|
2020-11-19 11:55:06 +00:00
|
|
|
for i in range(min(self.height, len(messages))):
|
2020-11-26 11:35:52 +00:00
|
|
|
self.addstr(self.pad, self.height - i - 1, self.x,
|
|
|
|
messages[i][:self.width])
|
2020-11-26 19:58:46 +00:00
|
|
|
self.refresh_pad(self.pad, 0, 0, self.y, self.x,
|
|
|
|
self.y + self.height - 1, self.x + self.width - 1)
|