Tiny GUI setup

This commit is contained in:
The Wobbler 2023-11-05 19:44:35 +01:00
parent 530a7f49f9
commit 237b619eb7

View file

@ -1 +1,93 @@
#!/usr/bin/python3 #!/usr/bin/python3
import os
import pygame
from tools import pg # if you import pg from tools, you dont need to init pygame.
from tools.settings import Settings
# integrated settings (I dont trust my own settings class.)
DEFAULT_WINDOW_SIZE = (800, 600)
FPS = 60
SAVE_SETTINGS_ON_EXIT = True
# some initializing
pygame.init()
screen = pygame.display.set_mode(DEFAULT_WINDOW_SIZE)
if os.path.isfile("settings.txt"):
settings = Settings("settings.txt")
else:
settings = Settings()
settings.path = "settings.txt"
settings["win_size"] = DEFAULT_WINDOW_SIZE
settings.save()
# loading screen
default_font = pygame.font.SysFont("ubuntu", 16)
loading_text = default_font.render("Loading...", True, (240, 240, 240))
screen.fill((40, 40, 40))
screen.blit(loading_text, (400 - loading_text.get_width() / 2, 300 - loading_text.get_height() / 2))
pygame.display.update()
# colors (color names by https://www.color-blindness.com/color-name-hue/)
nero = (40, 40, 40)
dim_gray = (100, 100, 100)
white_smoke = (240, 240, 240)
# pygame objects
clock = pygame.time.Clock()
bigger_default_font = pygame.font.SysFont("ubuntu", 32)
# buttons
start_button = pg.TextButton("Start", (400, 300), lambda: print("bla"), text_color=white_smoke, bg_color=dim_gray, font=bigger_default_font)
def close():
global running
running = False
def get_events():
for event in pygame.event.get():
if event.type == pygame.QUIT:
close()
return
def loop():
screen.fill(nero)
get_events()
if not running:
return
start_button.blit(screen)
start_button.check(pygame.mouse.get_pos(), [True])
pygame.display.update()
clock.tick(FPS)
# loading completed
screen = pygame.display.set_mode(settings["win_size"], flags=pygame.RESIZABLE)
running = True
while running:
loop()
pygame.quit()
if SAVE_SETTINGS_ON_EXIT:
settings.save()