Added the GUI system.

This commit is contained in:
The Wobbler 2024-02-27 20:12:13 +01:00
parent 5b44dd7e30
commit ec6bbf817b
4 changed files with 30 additions and 6 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 656 B

After

Width:  |  Height:  |  Size: 614 B

Binary file not shown.

View file

@ -4,6 +4,7 @@ import pygame
from pygame._sdl2 import Window from pygame._sdl2 import Window
from dataclasses import dataclass from dataclasses import dataclass
from wobbl_tools.data_file import load_dataclass_json, save_dataclass_json from wobbl_tools.data_file import load_dataclass_json, save_dataclass_json
from ui import UI
@dataclass @dataclass
@ -28,9 +29,11 @@ class GDPygame:
setattr(self.settings, "save", lambda: save_dataclass_json(self.settings, "settings.json")) setattr(self.settings, "save", lambda: save_dataclass_json(self.settings, "settings.json"))
self.fps = self.settings.fps self.fps = self.settings.fps
self.ui = UI(self)
# colors # colors
self.gray = (20, 20, 20) self.gray = (20, 20, 20)
self.blue = (10, 10, 140)
# pygame objects # pygame objects
self.clock = pygame.time.Clock() self.clock = pygame.time.Clock()
@ -58,6 +61,8 @@ class GDPygame:
def loop(self): def loop(self):
self.screen.fill(self.gray) self.screen.fill(self.gray)
self.ui.draw()
self.get_events() self.get_events()
if not self.running: if not self.running:
return return

31
ui.py
View file

@ -1,14 +1,33 @@
#!/usr/bin/python3 #!/usr/bin/python3
class UI: class UI:
def __init__(self): def __init__(self, app):
self.app = app
self.main_menu = MainMenu(app)
self.current_page = "main_menu" self.current_page = "main_menu"
self.main_menu = Page() def draw(self):
page = getattr(self, self.current_page)
page.draw()
def update(self):
page = getattr(self, self.current_page)
page.update()
class Page: class Page:
def __init__(self, elements: dict=None): def __init__(self, app):
if not elements is None: self.app = app
for name, element in elements.items():
setattr(self, name, element) def draw(self):
pass
def update(self):
pass
class MainMenu(Page):
def draw(self):
self.app.screen.fill(self.app.blue)