2020-11-27 16:32:26 +00:00
|
|
|
# Copyright (C) 2020 by ÿnérant, eichhornchen, nicomarg, charlse
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2020-11-27 16:52:26 +00:00
|
|
|
import curses
|
2020-11-27 16:32:26 +00:00
|
|
|
|
|
|
|
from squirrelbattle.display.display import Box, Display
|
|
|
|
|
|
|
|
|
|
|
|
class MessageDisplay(Display):
|
2020-11-27 16:35:51 +00:00
|
|
|
"""
|
|
|
|
Display a message in a popup.
|
|
|
|
"""
|
|
|
|
|
2020-11-27 16:32:26 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
2020-11-27 16:52:26 +00:00
|
|
|
self.box = Box(fg_border_color=curses.COLOR_RED, *args, **kwargs)
|
2020-11-27 16:32:26 +00:00
|
|
|
self.message = ""
|
|
|
|
self.pad = self.newpad(1, 1)
|
|
|
|
|
|
|
|
def update_message(self, msg: str) -> None:
|
|
|
|
self.message = msg
|
|
|
|
|
|
|
|
def display(self) -> None:
|
|
|
|
self.box.refresh(self.y - 1, self.x - 2,
|
|
|
|
self.height + 2, self.width + 4)
|
|
|
|
self.box.display()
|
|
|
|
self.pad.erase()
|
2020-12-12 12:46:45 +00:00
|
|
|
self.addstr(self.pad, 0, 0, self.message, bold=True)
|
2020-11-27 16:32:26 +00:00
|
|
|
self.refresh_pad(self.pad, 0, 0, self.y, self.x,
|
|
|
|
self.height + self.y - 1,
|
|
|
|
self.width + self.x - 1)
|