Skip to content
Snippets Groups Projects
Commit a3d40aaf authored by Fabian Heinrich's avatar Fabian Heinrich
Browse files

Changed init window size to minimum window size

parent dd1507a9
No related branches found
No related tags found
1 merge request!28Resolve "Game time limit"
Pipeline #43856 passed
......@@ -4,4 +4,4 @@ plates:
plate_delay: [ 5, 10 ]
game:
time_limit_seconds: 30.0
time_limit_seconds: 90
......@@ -44,6 +44,10 @@
},
"misc": {
"tool_tip_delay": "1.5"
},
"font": {
"size": 15,
"bold": 1
}
},
"#timer_label": {
......@@ -63,5 +67,12 @@
"size": 20,
"bold": 1
}
},
"#quit_button": {
"colours": {
"normal_bg": "#f71b29",
"hovered_bg": "#bf0310",
"normal_border": "#DDDDDD"
}
}
}
\ No newline at end of file
......@@ -115,11 +115,14 @@ class PyGameGUI:
self.visualization_config = yaml.safe_load(file)
self.screen_margin = self.visualization_config["GameWindow"]["screen_margin"]
self.init_width = self.visualization_config["GameWindow"]["init_width"]
self.init_height = self.visualization_config["GameWindow"]["init_height"]
self.min_width = self.visualization_config["GameWindow"]["min_width"]
self.min_height = self.visualization_config["GameWindow"]["min_height"]
self.window_width = self.init_width
self.window_height = self.init_height
self.buttons_width = self.visualization_config["GameWindow"]["buttons_width"]
self.buttons_height = self.visualization_config["GameWindow"]["buttons_height"]
self.window_width = self.min_width
self.window_height = self.min_height
self.main_window = pygame.display.set_mode(
(
......@@ -146,27 +149,38 @@ class PyGameGUI:
kitchen_aspect_ratio = kitchen_height / kitchen_width
game_height = int(game_width * kitchen_aspect_ratio)
grid_size = int(game_width / self.simulator.env.kitchen_width)
elif self.visualization_config["GameWindow"]["WhatIsFixed"] == "window_height":
game_height = self.visualization_config["GameWindow"]["size"]
kitchen_aspect_ratio = kitchen_width / kitchen_height
game_width = int(game_height * kitchen_aspect_ratio)
grid_size = int(game_width / self.simulator.env.kitchen_width)
elif self.visualization_config["GameWindow"]["WhatIsFixed"] == "grid":
grid_size = self.visualization_config["GameWindow"]["size"]
game_width, game_height = (
kitchen_width * grid_size,
kitchen_height * grid_size,
)
else:
game_width, game_height = 0, 0
grid_size = 0
window_width, window_height = (
game_width + (2 * self.screen_margin),
game_height + (2 * self.screen_margin),
game_height + (2 * self.screen_margin), # bar with orders
)
return int(window_width), int(window_height), game_width, game_height, grid_size
window_width = max(window_width, self.min_width)
window_height = max(window_height, self.min_height)
return (
int(window_width),
int(window_height),
game_width,
game_height,
grid_size,
)
def create_player_colors(self) -> list[Color]:
number_player = len(self.simulator.env.players)
......@@ -515,14 +529,13 @@ class PyGameGUI:
self.manager = pygame_gui.UIManager((self.window_width, self.window_height))
self.manager.get_theme().load_theme(ROOT_DIR / "gui_2d_vis" / "gui_theme.json")
button_width, button_height = 200, 60
self.start_button = pygame_gui.elements.UIButton(
relative_rect=pygame.Rect(
(
(self.window_width // 2) - button_width // 2,
(self.window_height / 2) - button_height // 2,
(self.window_width // 2) - self.buttons_width // 2,
(self.window_height / 2) - self.buttons_height // 2,
),
(button_width, button_height),
(self.buttons_width, self.buttons_height),
),
text="Start Game",
manager=self.manager,
......@@ -532,23 +545,24 @@ class PyGameGUI:
self.quit_button = pygame_gui.elements.UIButton(
relative_rect=pygame.Rect(
(
(self.window_width - button_width),
(self.window_width - self.buttons_width),
0,
),
(button_width, button_height),
(self.buttons_width, self.buttons_height),
),
text="Quit Game",
manager=self.manager,
object_id="#quit_button",
)
self.quit_button.can_hover()
self.finished_button = pygame_gui.elements.UIButton(
relative_rect=pygame.Rect(
(
(self.window_width - button_width),
(self.window_height - button_height),
(self.window_width - self.buttons_width),
(self.window_height - self.buttons_height),
),
(button_width, button_height),
(self.buttons_width, self.buttons_height),
),
text="End screen",
manager=self.manager,
......@@ -559,9 +573,9 @@ class PyGameGUI:
relative_rect=pygame.Rect(
(
(0),
(self.window_height - button_height),
(self.window_height - self.buttons_height),
),
(button_width, button_height),
(self.buttons_width, self.buttons_height),
),
text="Back to Start",
manager=self.manager,
......@@ -570,10 +584,10 @@ class PyGameGUI:
self.score_rect = pygame.Rect(
(
(self.window_width // 2) - button_width // 2,
(self.window_height / 2) - button_height // 2,
(self.window_width // 2) - self.buttons_width // 2,
(self.window_height / 2) - self.buttons_height // 2,
),
(button_width, button_height),
(self.buttons_width, self.buttons_height),
)
self.score_label = pygame_gui.elements.UILabel(
......@@ -606,7 +620,7 @@ class PyGameGUI:
text="GAMETIME",
relative_rect=pygame.Rect(
(0, 0),
(button_width * 1.5, button_height),
(self.buttons_width * 1.5, self.buttons_height),
),
manager=self.manager,
object_id="#timer_label",
......@@ -627,11 +641,11 @@ class PyGameGUI:
)
def reset_window_size(self):
self.window_width = self.init_width
self.window_height = self.init_height
self.window_width = self.min_width
self.window_height = self.min_height
self.game_width = 0
self.game_height = 0
self.set_window_size(self.init_width, self.init_height, 0, 0)
self.set_window_size(self.min_width, self.min_height, 0, 0)
self.init_ui_elements()
def setup_simulation(self, config_path, layout_path):
......@@ -694,10 +708,9 @@ class PyGameGUI:
log.debug("Pressed start button")
def back_button_press(self):
self.menu_state = MenuStates.Start
self.reset_window_size()
self.simulator.stop()
self.menu_state = MenuStates.Start
log.debug("Pressed back button")
def quit_button_press(self):
......@@ -706,9 +719,9 @@ class PyGameGUI:
log.debug("Pressed quit button")
def finished_button_press(self):
self.menu_state = MenuStates.End
self.reset_window_size()
self.simulator.stop()
self.menu_state = MenuStates.End
log.debug("Pressed finished button")
def start_pygame(self):
......@@ -729,7 +742,6 @@ class PyGameGUI:
while self.running:
try:
time_delta = clock.tick(self.FPS) / 1000.0
state = self.simulator.get_state()
for event in pygame.event.get():
if event.type == pygame.QUIT:
......@@ -759,6 +771,8 @@ class PyGameGUI:
# drawing:
state = self.simulator.get_state()
self.main_window.fill(colors["lemonchiffon1"])
self.manager.draw_ui(self.main_window)
......@@ -773,6 +787,7 @@ class PyGameGUI:
if state["ended"]:
self.finished_button_press()
self.manage_button_visibility()
self.draw(state)
game_screen_rect = self.game_screen.get_rect()
......
# colors: https://www.webucator.com/article/python-color-constants-module/
GameWindow:
WhatIsFixed: grid # grid or window_width or window_height
size: 40
WhatIsFixed: window_height # grid or window_width or window_height
size: 400
screen_margin: 100
init_width: 600
init_height: 600
min_width: 700
min_height: 600
buttons_width: 180
buttons_height: 60
Kitchen:
ground_tiles_color: sgigray76
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment