diff --git a/config/constants.py b/config/constants.py index 486ef30..0fa60a3 100644 --- a/config/constants.py +++ b/config/constants.py @@ -2,8 +2,8 @@ """Configuration constants for the simulation.""" # Screen settings -SCREEN_WIDTH = 1920 // 2 -SCREEN_HEIGHT = 1080 // 2 +SCREEN_WIDTH = 1920 +SCREEN_HEIGHT = 1080 # Colors BLACK = (0, 0, 0) diff --git a/core/input_handler.py b/core/input_handler.py index 4ed32e8..7c227b4 100644 --- a/core/input_handler.py +++ b/core/input_handler.py @@ -27,11 +27,13 @@ class InputHandler: self.default_tps = DEFAULT_TPS self.sprint_mode = False - def handle_events(self, events): + def handle_events(self, events, ui_manager): """Process all pygame events and return game state.""" running = True for event in events: + ui_manager.process_events(event) + if event.type == pygame.QUIT: running = False elif event.type == pygame.KEYDOWN: diff --git a/core/simulation_engine.py b/core/simulation_engine.py index 119b25e..d8deaec 100644 --- a/core/simulation_engine.py +++ b/core/simulation_engine.py @@ -69,7 +69,8 @@ class SimulationEngine: tick_interval = 1.0 / self.input_handler.tps # Handle events - self.running = self.input_handler.handle_events(pygame.event.get()) + events = pygame.event.get() + self.running = self.input_handler.handle_events(events, self.hud.manager) if self.input_handler.sprint_mode: # Sprint mode: run as many ticks as possible, skip rendering @@ -104,6 +105,7 @@ class SimulationEngine: self.input_handler.update_selected_objects() self.world.tick_all() + self.hud.manager.update(deltatime) if current_time - self.last_tps_time >= 1.0: self.actual_tps = self.tick_counter @@ -113,6 +115,7 @@ class SimulationEngine: self.last_tick_time = time.perf_counter() self.last_tps_time = time.perf_counter() + self.hud.manager.draw_ui(self.screen) self._update(deltatime) self._render() diff --git a/ui/hud.py b/ui/hud.py index f7b73d1..e09cd57 100644 --- a/ui/hud.py +++ b/ui/hud.py @@ -2,6 +2,7 @@ """Handles HUD elements and text overlays.""" import pygame +import pygame_gui from config.constants import * from world.base.brain import CellBrain, FlexibleNeuralNetwork from world.objects import DefaultCell @@ -13,6 +14,8 @@ class HUD: self.font = pygame.font.Font("freesansbold.ttf", 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") + def render_mouse_position(self, screen, camera): """Render mouse position in top left.""" mouse_x, mouse_y = camera.get_real_coordinates(*pygame.mouse.get_pos())