-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathui_settings_panel.py
More file actions
59 lines (45 loc) · 1.65 KB
/
ui_settings_panel.py
File metadata and controls
59 lines (45 loc) · 1.65 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
from __future__ import annotations
import tcod.console
import tcod.event
from tcod.event import KeySym
from game.constants import COLOR_GRAY, COLOR_WHITE
from game.managers.event_manager import Event
from game.ui.ui_button import UIButton
from game.ui.ui_panel import UIPanel
class UISettingsPanel(UIPanel):
buttons: tuple[UIButton, ...] | None = None
def on_event(self, event: tcod.event.Event) -> None:
"""Called on events."""
match event:
case tcod.event.Quit():
raise SystemExit()
case tcod.event.KeyDown():
for i, button in enumerate(self.buttons):
button.on_event(event)
def on_draw(self, console: tcod.console.Console) -> None:
"""Called when the panel is being drawn."""
self.draw_title(console)
self.draw_buttons(console)
def draw_title(self, console: tcod.console.Console) -> None:
console.print(
console.width // 2,
3,
"Settings",
alignment = tcod.constants.CENTER,
)
def draw_buttons(self, console: tcod.console.Console) -> None:
self.buttons = (
UIButton("[c] Cancel", KeySym.c, self.cancel_button_clicked),
)
for i, button in enumerate(self.buttons):
console.print(
console.width // 2,
5 + i,
button.label,
COLOR_WHITE,
COLOR_GRAY,
alignment=tcod.constants.CENTER
)
def cancel_button_clicked(self) -> None:
"""Callback for the 'Cancel' button."""
Event('cancel_button_clicked', '')