-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathui_log_panel.py
More file actions
61 lines (47 loc) · 1.58 KB
/
ui_log_panel.py
File metadata and controls
61 lines (47 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""A UI panel which displays log messages."""
from __future__ import annotations
from collections.abc import Reversible
import tcod.console
import tcod.event
import game.managers.global_manager as global_manager
from game.constants import COLOR_BLACK
from game.managers.log_manager import Message, Log
from game.ui.ui_panel import UIPanel
class UILogPanel(UIPanel):
log_height: int = 3
def __init__(self) -> None:
self.is_visible = True
def on_event(self, event: tcod.event.Event) -> None:
"""Called on events."""
def on_draw(self, console: tcod.console.Console) -> None:
"""Called when the panel is being drawn."""
self.draw_frame(console)
self.draw_body(console)
def draw_frame(self, console: tcod.console.Console) -> None:
console.draw_rect(
0,
console.height - self.log_height,
console.width,
self.log_height,
0,
COLOR_BLACK,
COLOR_BLACK
)
def draw_body(self, console: tcod.console.Console) -> None:
messages: Reversible[Message] = global_manager.world[None].components[Log]
y = self.log_height
i = 0
for message in reversed(messages):
console.print_box(
0,
console.height - self.log_height + i,
console.width,
0,
message.full_text,
message.fg
)
if y <= 0:
# No more space to print messages.
break
y -= 1
i += 1