From a3d40aaf5eb38b7513941209cc669f9f66f59ea9 Mon Sep 17 00:00:00 2001
From: fheinrich <fheinrich@techfak.uni-bielefeld.de>
Date: Tue, 16 Jan 2024 17:15:13 +0100
Subject: [PATCH] Changed init window size to minimum window size

---
 .../game_content/environment_config.yaml      |  2 +-
 .../gui_2d_vis/gui_theme.json                 | 11 +++
 .../gui_2d_vis/overcooked_gui.py              | 71 +++++++++++--------
 .../gui_2d_vis/visualization.yaml             | 11 +--
 4 files changed, 62 insertions(+), 33 deletions(-)

diff --git a/overcooked_simulator/game_content/environment_config.yaml b/overcooked_simulator/game_content/environment_config.yaml
index 1bee3dc3..d597fabe 100644
--- a/overcooked_simulator/game_content/environment_config.yaml
+++ b/overcooked_simulator/game_content/environment_config.yaml
@@ -4,4 +4,4 @@ plates:
   plate_delay: [ 5, 10 ]
 
 game:
-  time_limit_seconds: 30.0
+  time_limit_seconds: 90
diff --git a/overcooked_simulator/gui_2d_vis/gui_theme.json b/overcooked_simulator/gui_2d_vis/gui_theme.json
index 3db73ba4..4683e4e3 100644
--- a/overcooked_simulator/gui_2d_vis/gui_theme.json
+++ b/overcooked_simulator/gui_2d_vis/gui_theme.json
@@ -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
diff --git a/overcooked_simulator/gui_2d_vis/overcooked_gui.py b/overcooked_simulator/gui_2d_vis/overcooked_gui.py
index 39aa1e7a..f31f1cff 100644
--- a/overcooked_simulator/gui_2d_vis/overcooked_gui.py
+++ b/overcooked_simulator/gui_2d_vis/overcooked_gui.py
@@ -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()
diff --git a/overcooked_simulator/gui_2d_vis/visualization.yaml b/overcooked_simulator/gui_2d_vis/visualization.yaml
index 6dd5bc91..3c80ea22 100644
--- a/overcooked_simulator/gui_2d_vis/visualization.yaml
+++ b/overcooked_simulator/gui_2d_vis/visualization.yaml
@@ -1,11 +1,14 @@
 # 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
-- 
GitLab