Refactor HUD initialization to accept UI manager and update simulation engine for dynamic screen sizing

This commit is contained in:
Sam 2025-06-18 17:44:54 -05:00
parent ff43022b3a
commit 2b1b348cb1
2 changed files with 19 additions and 3 deletions

View File

@ -3,6 +3,8 @@ import time
import random import random
import sys import sys
from pygame_gui import UIManager
from world.base.brain import CellBrain, FlexibleNeuralNetwork from world.base.brain import CellBrain, FlexibleNeuralNetwork
from world.world import World, Position, Rotation from world.world import World, Position, Rotation
from world.objects import FoodObject, DefaultCell from world.objects import FoodObject, DefaultCell
@ -16,7 +18,15 @@ from ui.hud import HUD
class SimulationEngine: class SimulationEngine:
def __init__(self): def __init__(self):
pygame.init() pygame.init()
self.screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT), vsync=1)
info = pygame.display.Info()
self.window_width, self.window_height = info.current_w, info.current_h
self.screen = pygame.display.set_mode((self.window_width, self.window_height),
pygame.RESIZABLE | pygame.FULLSCREEN)
self.ui_manager = UIManager((self.window_width, self.window_height))
# self.screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT), vsync=1)
pygame.display.set_caption("Dynamic Abstraction System Testing") pygame.display.set_caption("Dynamic Abstraction System Testing")
self.clock = pygame.time.Clock() self.clock = pygame.time.Clock()
self.camera = Camera(SCREEN_WIDTH, SCREEN_HEIGHT, RENDER_BUFFER) self.camera = Camera(SCREEN_WIDTH, SCREEN_HEIGHT, RENDER_BUFFER)
@ -34,6 +44,12 @@ class SimulationEngine:
self.running = True self.running = True
def _update_simulation_view(self):
self.sim_view_width = int(self.window_width * 0.75)
self.sim_view_height = int(self.window_height * 0.75)
self.sim_view = pygame.Surface((self.sim_view_width, self.sim_view_height))
self.sim_view_rect = self.sim_view.get_rect(center=(self.window_width // 2, self.window_height // 2))
@staticmethod @staticmethod
def _setup_world(): def _setup_world():
world = World(CELL_SIZE, (CELL_SIZE * GRID_WIDTH, CELL_SIZE * GRID_HEIGHT)) world = World(CELL_SIZE, (CELL_SIZE * GRID_WIDTH, CELL_SIZE * GRID_HEIGHT))

View File

@ -10,11 +10,11 @@ import math
class HUD: class HUD:
def __init__(self): def __init__(self, ui_manager):
self.font = pygame.font.Font("freesansbold.ttf", FONT_SIZE) self.font = pygame.font.Font("freesansbold.ttf", FONT_SIZE)
self.legend_font = pygame.font.Font("freesansbold.ttf", LEGEND_FONT_SIZE) self.legend_font = pygame.font.Font("freesansbold.ttf", LEGEND_FONT_SIZE)
self.manager = pygame_gui.UIManager((SCREEN_WIDTH, SCREEN_HEIGHT), "ui/theme.json") self.manager = ui_manager
def render_mouse_position(self, screen, camera): def render_mouse_position(self, screen, camera):
"""Render mouse position in top left.""" """Render mouse position in top left."""