Refactor HUD initialization to accept UI manager and update simulation engine for dynamic screen sizing
This commit is contained in:
parent
ff43022b3a
commit
2b1b348cb1
@ -3,6 +3,8 @@ import time
|
||||
import random
|
||||
import sys
|
||||
|
||||
from pygame_gui import UIManager
|
||||
|
||||
from world.base.brain import CellBrain, FlexibleNeuralNetwork
|
||||
from world.world import World, Position, Rotation
|
||||
from world.objects import FoodObject, DefaultCell
|
||||
@ -16,7 +18,15 @@ from ui.hud import HUD
|
||||
class SimulationEngine:
|
||||
def __init__(self):
|
||||
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")
|
||||
self.clock = pygame.time.Clock()
|
||||
self.camera = Camera(SCREEN_WIDTH, SCREEN_HEIGHT, RENDER_BUFFER)
|
||||
@ -34,6 +44,12 @@ class SimulationEngine:
|
||||
|
||||
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
|
||||
def _setup_world():
|
||||
world = World(CELL_SIZE, (CELL_SIZE * GRID_WIDTH, CELL_SIZE * GRID_HEIGHT))
|
||||
|
||||
@ -10,11 +10,11 @@ import math
|
||||
|
||||
|
||||
class HUD:
|
||||
def __init__(self):
|
||||
def __init__(self, ui_manager):
|
||||
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")
|
||||
self.manager = ui_manager
|
||||
|
||||
def render_mouse_position(self, screen, camera):
|
||||
"""Render mouse position in top left."""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user