squirrel-battle/dungeonbattle/menus.py

45 lines
982 B
Python

from enum import Enum
from typing import Any
from .settings import Settings
class Menu:
values: list
def __init__(self):
self.position = 0
def go_up(self) -> None:
self.position = max(0, self.position - 1)
def go_down(self) -> None:
self.position = min(len(self.values) - 1, self.position + 1)
def validate(self) -> Any:
return self.values[self.position]
class MainMenuValues(Enum):
START = 'Jouer'
SETTINGS = 'Paramètres'
EXIT = 'Quitter'
def __str__(self):
return self.value
class MainMenu(Menu):
values = [e for e in MainMenuValues]
class SettingsMenu(Menu) :
def __init__(self):
super().__init__()
def update_values(self, settings : Settings):
s = settings.dumps_to_string()
self.values = s[6:-2].replace("\"","").split(",\n ")
class ArbitraryMenu(Menu):
def __init__(self, values: list):
super().__init__()
self.values = values