feat(gui): add main menu

This commit is contained in:
Kristofers Solo 2024-01-03 21:53:32 +02:00
parent 293ffbc393
commit d935a4c6d6
3 changed files with 67 additions and 5 deletions

View File

@ -78,13 +78,13 @@ def main(args: argparse.ArgumentParser) -> None:
if args.train is not None:
# train(args.train)
ai.log.debug("Train")
ai.log.debug("Training the AI")
elif args.noui:
game.log.debug("Run game in CLI")
game.log.debug("Running the game in CLI")
game.play()
else:
gui.log.debug("Run app")
# play()
gui.log.debug("Running the game in GUI")
gui.launch()
if __name__ == "__main__":

View File

@ -1,3 +1,4 @@
from .log import log
from .menu import Menu, launch
__all__ = ["log"]
__all__ = ["log", "Menu", "launch"]

61
src/gui/menu.py Normal file
View File

@ -0,0 +1,61 @@
from typing import Callable, Optional
from kivy.app import App
from kivy.config import Config
from kivy.core.window import Window
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from utils import Size
from .log import log
def launch(size: Size = Size(200, 100)) -> None:
Window.size = size
Window.minimum_width, Window.minimum_height = Window.size
Window.maximum_width, Window.maximum_height = Window.size
Window.resizable = False
Config.set("graphics", "width", size.width)
Config.set("graphics", "height", size.height)
Menu().run()
Config.set("graphics", "resizable", False)
class Menu(App):
def build(self) -> BoxLayout:
layout = BoxLayout(orientation="vertical", spacing=10, padding=10)
buttons: dict[str, Callable[[Button], None]] = {
"Play": self.play,
"AI": self.ai,
"Algorithm": self.algorithm,
"Settings": self.settings,
"Quit": self.quit,
}
for text, action in buttons.items():
button = Button(text=text, size_hint=(None, None), size=(100, 50))
button.bind(on_press=action)
layout.add_widget(button)
return layout
def play(self, instance: Button) -> None:
log.debug(f"Play button was pressed")
def ai(self, instance: Button) -> None:
log.debug(f"AI button was pressed")
def algorithm(self, instance: Button) -> None:
log.debug(f"Algorithm button was pressed")
def settings(self, instance: Button) -> None:
log.debug(f"Settings button was pressed")
def quit(self, instance: Button) -> None:
log.debug(f"Quit button was pressed")
self.exit()
def exit(self) -> None:
self.stop()