From 398cac7a8787dd9b36972e8d630a0ca6a4daca1c Mon Sep 17 00:00:00 2001
From: fheinrich <fheinrich@techfak.uni-bielefeld.de>
Date: Thu, 22 Feb 2024 13:44:21 +0100
Subject: [PATCH] Only use space to continue in menu

---
 overcooked_simulator/__main__.py              |  2 +-
 .../study/environment_config.yaml             |  2 +-
 .../study/environment_config_dark.yaml        |  2 +-
 .../game_content/study/study_config.yaml      | 24 +++++-----
 .../gui_2d_vis/overcooked_gui.py              | 48 +++++++++++--------
 5 files changed, 44 insertions(+), 34 deletions(-)

diff --git a/overcooked_simulator/__main__.py b/overcooked_simulator/__main__.py
index 7b79494b..8dcd0fba 100644
--- a/overcooked_simulator/__main__.py
+++ b/overcooked_simulator/__main__.py
@@ -8,7 +8,7 @@ from overcooked_simulator.utils import (
     add_list_of_manager_ids_arguments,
 )
 
-USE_STUDY_SERVER = True
+USE_STUDY_SERVER = False
 
 
 def start_game_server(cli_args):
diff --git a/overcooked_simulator/game_content/study/environment_config.yaml b/overcooked_simulator/game_content/study/environment_config.yaml
index eadb5b3d..357c14af 100644
--- a/overcooked_simulator/game_content/study/environment_config.yaml
+++ b/overcooked_simulator/game_content/study/environment_config.yaml
@@ -5,7 +5,7 @@ plates:
   # range of seconds until the dirty plate arrives.
 
 game:
-  time_limit_seconds: 20
+  time_limit_seconds: 3
 
 meals:
   all: true
diff --git a/overcooked_simulator/game_content/study/environment_config_dark.yaml b/overcooked_simulator/game_content/study/environment_config_dark.yaml
index b11ae4fd..7890ad12 100644
--- a/overcooked_simulator/game_content/study/environment_config_dark.yaml
+++ b/overcooked_simulator/game_content/study/environment_config_dark.yaml
@@ -5,7 +5,7 @@ plates:
   # range of seconds until the dirty plate arrives.
 
 game:
-  time_limit_seconds: 20
+  time_limit_seconds: 3
 
 meals:
   all: true
diff --git a/overcooked_simulator/game_content/study/study_config.yaml b/overcooked_simulator/game_content/study/study_config.yaml
index 883f4304..966dc3ec 100644
--- a/overcooked_simulator/game_content/study/study_config.yaml
+++ b/overcooked_simulator/game_content/study/study_config.yaml
@@ -1,23 +1,23 @@
 levels:
-  - config_path: environment_config.yaml
+  - config_path: study/environment_config.yaml
     layout_path: overcooked-1/1-1-far-apart.layout
     item_info_path: item_info.yaml
     name: "Level 1-1: Far Apart"
 
-  #  - config_path: environment_config.yaml
-  #    layout_path: overcooked-1/1-4-bottleneck.layout
-  #    item_info_path: item_info.yaml
-  #    name: "Level 1-4: Bottleneck"
-  #
-  #  - config_path: environment_config.yaml
-  #    layout_path: overcooked-1/1-5-circle.layout
-  #    item_info_path: item_info.yaml
-  #    name: "Level 1-5: Circle"
+  - config_path: study/environment_config.yaml
+    layout_path: overcooked-1/1-4-bottleneck.layout
+    item_info_path: item_info.yaml
+    name: "Level 1-4: Bottleneck"
+
+  - config_path: study/environment_config.yaml
+    layout_path: overcooked-1/1-5-circle.layout
+    item_info_path: item_info.yaml
+    name: "Level 1-5: Circle"
 
-  - config_path: environment_config_dark.yaml
+  - config_path: study/environment_config_dark.yaml
     layout_path: overcooked-1/4-2-dark.layout
     item_info_path: item_info.yaml
     name: "Level 4-2: Dark"
 
 
-num_players: 2
+num_players: 1
diff --git a/overcooked_simulator/gui_2d_vis/overcooked_gui.py b/overcooked_simulator/gui_2d_vis/overcooked_gui.py
index 2804fd68..7af51124 100644
--- a/overcooked_simulator/gui_2d_vis/overcooked_gui.py
+++ b/overcooked_simulator/gui_2d_vis/overcooked_gui.py
@@ -1342,6 +1342,15 @@ class PyGameGUI:
         # self.last_level = answer["last_level"]
         # print("\nAT LAST LEVEL:", self.last_level, "\n")
 
+    def button_continue_postgame_pressed(self):
+        if not self.CONNECT_WITH_STUDY_SERVER:
+            self.current_layout_idx += 1
+            if self.current_layout_idx == len(self.layout_file_paths) - 1:
+                self.last_level = True
+            else:
+                log.debug(f"LEVEL: {self.layout_file_paths[self.current_layout_idx]}")
+        self.menu_state = MenuStates.PreGame
+
     def manage_button_event(self, event):
         if event.ui_element == self.quit_button:
             self.running = False
@@ -1438,15 +1447,7 @@ class PyGameGUI:
                         self.menu_state = MenuStates.PreGame
 
                     case self.next_game_button:
-                        if not self.CONNECT_WITH_STUDY_SERVER:
-                            self.current_layout_idx += 1
-                            if self.current_layout_idx == len(self.layout_file_paths) - 1:
-                                self.last_level = True
-                            else:
-                                log.debug(
-                                    f"LEVEL: {self.layout_file_paths[self.current_layout_idx]}"
-                                )
-                        self.menu_state = MenuStates.PreGame
+                        self.button_continue_postgame_pressed()
 
                     case self.finish_study_button:
                         self.menu_state = MenuStates.End
@@ -1508,16 +1509,25 @@ class PyGameGUI:
                         print("Number of joysticks:", pygame.joystick.get_count())
 
                     # Press key instead of mouse button press
-                    if self.menu_state == MenuStates.Start:
-                        if event.type in [pygame.JOYBUTTONDOWN, pygame.KEYDOWN]:
-                            self.menu_state = MenuStates.ControllerTutorial
-                            self.update_screen_elements()
-                    elif self.menu_state == MenuStates.PreGame:
-                        if event.type in [pygame.JOYBUTTONDOWN, pygame.KEYDOWN]:
-                            self.setup_game()
-                            self.set_game_size()
-                            self.menu_state = MenuStates.Game
-                            self.update_screen_elements()
+                    if (
+                        event.type in [pygame.JOYBUTTONDOWN, pygame.KEYDOWN]
+                        and event.key == pygame.K_SPACE
+                    ):
+                        match self.menu_state:
+                            case MenuStates.Start:
+                                self.menu_state = MenuStates.ControllerTutorial
+                                self.update_screen_elements()
+                            case MenuStates.PreGame:
+                                self.setup_game()
+                                self.set_game_size()
+                                self.menu_state = MenuStates.Game
+                                self.update_screen_elements()
+                            case MenuStates.PostGame:
+                                if self.last_level:
+                                    self.menu_state = MenuStates.End
+                                else:
+                                    self.button_continue_postgame_pressed()
+                                self.update_screen_elements()
 
                     if event.type == pygame_gui.UI_BUTTON_PRESSED:
                         self.manage_button_event(event)
-- 
GitLab