diff --git a/overcooked_simulator/example_study_server.py b/overcooked_simulator/example_study_server.py index d6538fa83bcc02aa11e297bb0723b6ddbe780913..9c1b09d96d9bac33be79628094b1d3091138184c 100644 --- a/overcooked_simulator/example_study_server.py +++ b/overcooked_simulator/example_study_server.py @@ -190,10 +190,9 @@ class StudyState: def get_connection(self, participant_id: str): player_info = self.participant_id_to_player_info[participant_id] - mock_recipes = ["Onion?", "Tomato?", "HAMBURGER!"] current_level = self.levels[self.current_level_idx] if self.current_config["meals"]["all"]: - return ["all"] + recipes = ["all"] else: recipes = self.current_config["meals"]["list"] level_info = LevelInfo(name=current_level["name"], last_level=self.last_level, recipes=recipes) @@ -321,10 +320,11 @@ async def get_game_connection(participant_id: str): @app.post("/connect_to_tutorial/{participant_id}") async def want_to_play_tutorial(participant_id: str): environment_config_path = ( - ROOT_DIR / "game_content" / "tutorial" / "tutorial_env_config.yaml" + ROOT_DIR / "game_content" / "tutorial_env_config.yaml" ) - layout_path = ROOT_DIR / "game_content" / "tutorial" / "tutorial.layout" + layout_path = ROOT_DIR / "game_content" / "layouts" / "tutorial.layout" item_info_path = ROOT_DIR / "game_content" / "item_info.yaml" + with open(item_info_path, "r") as file: item_info = file.read() with open(layout_path, "r") as file: diff --git a/overcooked_simulator/gui_2d_vis/overcooked_gui.py b/overcooked_simulator/gui_2d_vis/overcooked_gui.py index 7b99a75be82dbf1beca88a9086149dea9f2e7e31..f3881f2d48c7ac88c9b4cc2e18029717600c5e4e 100644 --- a/overcooked_simulator/gui_2d_vis/overcooked_gui.py +++ b/overcooked_simulator/gui_2d_vis/overcooked_gui.py @@ -645,11 +645,11 @@ class PyGameGUI: text=f"not set", relative_rect=pygame.Rect( (0, 0), - (self.window_width * 0.7, self.window_height * 0.2), + (self.window_width, 50), ), manager=self.manager, object_id="#level_name", - anchors={"centerx": "centerx", "top": "top"}, + anchors={"centerx": "centerx", "top_target": self.quit_button}, ) self.text_recipes_label = pygame_gui.elements.UILabel( @@ -732,36 +732,52 @@ class PyGameGUI: # PostGame screen ######################################################################## - conclusion_rect = pygame.Rect(0, 0, self.window_width, self.window_height * 0.4) - conclusion_rect.top = 50 - self.conclusion_label = pygame_gui.elements.UILabel( - text="not set", - relative_rect=conclusion_rect, - manager=self.manager, - object_id="#score_label", - anchors={"centerx": "centerx", "top": "top"}, - ) - next_game_button_rect = pygame.Rect((0, 0), (220, 80)) - next_game_button_rect.center = (self.buttons_width // 2, 200) + + rect = pygame.Rect((0, 0), (220, 80)) self.next_game_button = pygame_gui.elements.UIButton( - relative_rect=next_game_button_rect, + relative_rect=rect, manager=self.manager, text="Next game", - anchors={"centerx": "centerx", "centery": "centery"}, + anchors={"centerx": "centerx", "bottom": "bottom"}, object_id="#split_players_button", ) - finish_study_rect = pygame.Rect((0, 0), (220, 80)) - finish_study_rect.center = (self.buttons_width // 2, 200) + rect = pygame.Rect((0, 0), (220, 80)) self.finish_study_button = pygame_gui.elements.UIButton( - relative_rect=finish_study_rect, + relative_rect=rect, manager=self.manager, text="Finish study", - anchors={"center": "center"}, + anchors={"centerx": "centerx", "bottom": "bottom"}, object_id="#split_players_button", ) + rect = pygame.Rect( + (0, 0), + (self.window_width, 50), + ) + self.score_conclusion = pygame_gui.elements.UILabel( + text=f"not set", + relative_rect=rect, + manager=self.manager, + object_id="#level_name", + anchors={"centerx": "centerx", "top_target": self.level_name_label}, + ) + + self.completed_meals_text_label = pygame_gui.elements.UILabel( + text=f"Completed meals:", + relative_rect=pygame.Rect( + (0, 0), + (self.window_width * 0.7, 50), + ), + manager=self.manager, + object_id="#level_name", + anchors={"centerx": "centerx", "top_target": self.score_conclusion}, + ) + + self.all_completed_meals = [] + self.last_completed_meals = [] + ######################################################################## # End screen ######################################################################## @@ -811,10 +827,12 @@ class PyGameGUI: ] self.postgame_screen_elements = [ - self.conclusion_label, + self.score_conclusion, self.quit_button, + self.level_name_label, self.next_game_button, self.finish_study_button, + self.completed_meals_text_label, ] self.end_screen_elements = [ @@ -839,6 +857,7 @@ class PyGameGUI: + self.end_screen_elements + self.rest + self.all_recipes_labels + + self.all_completed_meals ): element.hide() for element in elements: @@ -921,8 +940,37 @@ class PyGameGUI: def update_conclusion_label(self, state): score = state["score"] - print(state["served_meals"]) - self.conclusion_label.set_text(f"Your final score is {score}. Hurray!") + + self.level_name_label.set_text(f"Completed: {self.level_info['name']}!") + + self.last_completed_meals = [] + for idx, (player, meal) in enumerate(state["served_meals"]): + text = f"Player {player} served meal {meal}." + print(text) + rect = pygame.Rect( + (0, 0), + (self.window_width, 30), + ) + if idx == 0: + meal_label = pygame_gui.elements.UILabel( + text=text, + relative_rect=rect, + manager=self.manager, + object_id="#recipe", + anchors={"centerx": "centerx", "top_target": self.completed_meals_text_label}, + ) + else: + meal_label = pygame_gui.elements.UILabel( + text=text, + relative_rect=rect, + manager=self.manager, + object_id="#recipe", + anchors={"centerx": "centerx", "top_target": self.last_completed_meals[idx - 1]}, + ) + self.last_completed_meals.append(meal_label) + self.all_completed_meals.append(meal_label) + + self.score_conclusion.set_text(f"Your final score is {score}. Hurray!") def exit_game(self): self.menu_state = MenuStates.PostGame @@ -935,6 +983,8 @@ class PyGameGUI: self.update_conclusion_label(self.last_state) self.update_screen_elements() + for el in self.last_completed_meals: + el.show() self.beeped_once = False def draw_game_screen_frame(self): @@ -1149,13 +1199,6 @@ class PyGameGUI: min(self.number_humans_to_be_added, num_key_set), self.split_players, ) - - # self.key_sets[0].current_player = int(self.player_info["player_id"]) - # self.player_id = self.player_info["player_id"] - # self.player_info = {self.player_info["player_id"]: self.player_info} - - # for i, k in enumerate(self.key_sets): - # k.current_player = list(self.player_info.keys())[i] self.player_ids = list(self.player_info.keys()) def create_and_connect_bot(self, player_id, player_info): diff --git a/overcooked_simulator/overcooked_environment.py b/overcooked_simulator/overcooked_environment.py index 20209f16e5856c6b51f47a9a27c68f88fe5a4d0b..c76c9942038c18a27e7a8c8f980e2b0dae12c88d 100644 --- a/overcooked_simulator/overcooked_environment.py +++ b/overcooked_simulator/overcooked_environment.py @@ -158,6 +158,7 @@ class Environment: if self.as_files: with open(env_config, "r") as file: env_config = file.read() + self.environment_config: EnvironmentConfig = yaml.load( env_config, Loader=yaml.Loader ) @@ -858,7 +859,7 @@ class Environment: ] if self.player_view_restricted else None, - "served_meals": [("?", str(meal)) for (meal, time) in self.order_and_score.served_meals], + "served_meals": [("?", str(meal)) for (meal, time) in self.order_manager.served_meals], "info_msg": [ (msg["msg"], msg["level"]) for msg in self.info_msgs_per_player[player_id]