Fixed bug that only the buttons in the button list got updated.

This commit is contained in:
The Wobbler 2023-11-11 20:28:00 +01:00
parent 6b69d32ad1
commit 9b2fe07fca

View file

@ -3,7 +3,7 @@
import os import os
import pygame import pygame
from tools import pg # if you import pg from tools, you dont need to init pygame. from tools import pg # if you import pg from tools, you dont need to init pygame.
from tools.settings import Settings from tools.file_dict import FileDict
# integrated settings (I dont trust my own settings class.) # integrated settings (I dont trust my own settings class.)
@ -18,10 +18,10 @@ screen = pygame.display.set_mode(DEFAULT_WINDOW_SIZE)
pygame.display.set_caption("Cowyeet 2.0") pygame.display.set_caption("Cowyeet 2.0")
if os.path.isfile("settings.txt"): if os.path.isfile("settings.txt"):
settings = Settings("settings.txt") settings = FileDict("settings.txt")
else: else:
settings = Settings() settings = FileDict()
settings.path = "settings.txt" settings.path = "settings.txt"
settings["win_size"] = DEFAULT_WINDOW_SIZE settings["win_size"] = DEFAULT_WINDOW_SIZE
settings.save() settings.save()
@ -70,8 +70,8 @@ def center(size):
# buttons # buttons
start_button = pg.TextButton("Start", center, screen, lambda: page_switch("game"), text_color=white_smoke, bg_color=dim_gray, font=bigger_default_font) buttons.append(pg.TextButton("Start", center, screen, lambda: page_switch("game"), text_color=white_smoke, bg_color=dim_gray, font=bigger_default_font))
buttons.append(start_button) start_button = len(buttons) - 1
text_buttons.append(start_button) text_buttons.append(start_button)
@ -82,11 +82,13 @@ def close():
def window_size_reload(new_size): def window_size_reload(new_size):
for button in text_buttons: for button in text_buttons:
button.update() buttons[button].update()
settings["win_size"] = new_size
def main_menu_page(): def main_menu_page():
start_button.blit(screen) buttons[start_button].blit(screen)
def page_selector(): def page_selector():
@ -101,9 +103,6 @@ def page_switch(new_page: str=None):
if not new_page is None: if not new_page is None:
page = new_page page = new_page
if page == "main_menu":
active_buttons = [start_button]
else: else:
print("Error: Page not found.") print("Error: Page not found.")
@ -161,10 +160,11 @@ def loop():
# loading completed # loading completed
screen = pygame.display.set_mode(settings["win_size"], flags=pygame.RESIZABLE) screen = pygame.display.set_mode(settings["win_size"], flags=pygame.RESIZABLE)
window_size_reload(settings["win_size"])
screen.fill(nero) screen.fill(nero)
pygame.display.update() pygame.display.update()
page_switch() page_switch("main_menu")
running = True running = True