45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
"""The main menu state"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import g
|
|
import game.states.menus
|
|
import game.world_tools
|
|
from game.state import Reset, StateResult
|
|
from game.states.game_screens import MainScreen
|
|
|
|
class MainMenu(game.states.menus.ListMenu):
|
|
"""Main/escape menu."""
|
|
__slots__ = ()
|
|
|
|
def __init__(self) -> None:
|
|
"""Initialize the main menu."""
|
|
items = [
|
|
game.states.menus.SelectItem("New game", self.new_game),
|
|
game.states.menus.SelectItem("Quit", self.quit),
|
|
]
|
|
if hasattr(g, "world"):
|
|
items.insert(0, game.states.menus.SelectItem("Continue", self.continue_))
|
|
|
|
super().__init__(
|
|
items=tuple(items),
|
|
selected=0,
|
|
x=5,
|
|
y=5,
|
|
)
|
|
|
|
@staticmethod
|
|
def continue_() -> StateResult:
|
|
"""Return to the game."""
|
|
return Reset(MainScreen())
|
|
|
|
@staticmethod
|
|
def new_game() -> StateResult:
|
|
"""Begin a new game."""
|
|
g.world = game.world_tools.new_world()
|
|
return Reset(MainScreen())
|
|
|
|
@staticmethod
|
|
def quit() -> StateResult:
|
|
"""Close the program."""
|
|
raise SystemExit()
|