Repository navigation
Expand file tree
/
Copy pathmain_menu_state.py
More file actions
48 lines (33 loc) · 1.54 KB
/
Copy pathmain_menu_state.py
File metadata and controls
48 lines (33 loc) · 1.54 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
from __future__ import annotations
import tcod.console
import tcod.event
from game.managers.event_manager import Observer
from game.states.base_state import BaseState
from game.ui.ui_main_menu_panel import UIMainMenuPanel
from game.ui.ui_panel import UIPanel
from game.ui.ui_settings_panel import UISettingsPanel
class MainMenuState(BaseState, Observer):
active_panel: UIPanel | None = None
ui_main_menu_panel: UIMainMenuPanel | None = None
ui_settings_panel: UISettingsPanel | None = None
def __init__(self) -> None:
# Initialise UI.
self.ui_main_menu_panel = UIMainMenuPanel()
self.ui_settings_panel = UISettingsPanel()
self.active_panel = self.ui_main_menu_panel
# Observe events.
Observer.__init__(self)
self.observe("settings_button_clicked", self.on_settings_button_clicked)
self.observe("cancel_button_clicked", self.on_cancel_button_clicked)
def on_event(self, event: tcod.event.Event) -> None:
"""Called on events."""
self.active_panel.on_event(event)
def on_draw(self, console: tcod.console.Console) -> None:
"""Called when the state is being drawn."""
self.active_panel.on_draw(console)
def on_settings_button_clicked(self, data: str) -> None:
"""Callback for the settings_button_clicked event."""
self.active_panel = self.ui_settings_panel
def on_cancel_button_clicked(self, data: str) -> None:
"""Callback for the cancel_button_clicked event."""
self.active_panel = self.ui_main_menu_panel