From 237b619eb7de7b127685c87cf45289a8fb48108d Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Sun, 5 Nov 2023 19:44:35 +0100 Subject: [PATCH] Tiny GUI setup --- cowyeet.py | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) diff --git a/cowyeet.py b/cowyeet.py index 44f7725..05bf64f 100644 --- a/cowyeet.py +++ b/cowyeet.py @@ -1 +1,93 @@ -#!/usr/bin/python3 \ No newline at end of file +#!/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()