diff --git a/cooperative_cuisine/pygame_2d_vis/gui.py b/cooperative_cuisine/pygame_2d_vis/gui.py index 645d5a46ad4dedf74b72ed4bd432a9641bda93cb..42a539c247a4ebe0886f6ac2dea5649bf6d7c0a5 100644 --- a/cooperative_cuisine/pygame_2d_vis/gui.py +++ b/cooperative_cuisine/pygame_2d_vis/gui.py @@ -191,9 +191,10 @@ class PyGameGUI: self.sub_processes = [] - self.layout_file_paths = sorted( - (ROOT_DIR / "configs" / "layouts").rglob("*.layout") - ) + self.layout_file_paths_dict = { + p.name: p for p in (ROOT_DIR / "configs" / "layouts").rglob("*.layout") + } + self.layout_file_paths = sorted(list(self.layout_file_paths_dict.keys())) self.current_layout_idx = 0 self.last_state: StateRepresentation @@ -506,7 +507,23 @@ class PyGameGUI: img_height = img_width * (image_rect.height / image_rect.width) new_dims = (img_width, img_height) self.press_a_image.set_dimensions(new_dims) - + if not self.CONNECT_WITH_STUDY_SERVER: + assert len(self.layout_file_paths) != 0, "No layout files." + dropdown_width, dropdown_height = 200, 40 + self.layout_selection = pygame_gui.elements.UIDropDownMenu( + relative_rect=pygame.Rect( + ( + 0, + 0, + ), + (dropdown_width, dropdown_height), + ), + manager=self.manager, + options_list=self.layout_file_paths, + starting_option="basic.layout" + if "basic.layout" in self.layout_file_paths + else random.choice(self.layout_file_paths), + ) player_selection_rect = pygame.Rect( (0, 0), ( @@ -951,6 +968,11 @@ class PyGameGUI: self.fullscreen_button, ] + if not self.CONNECT_WITH_STUDY_SERVER: + self.start_screen_elements.append(self.layout_selection) + else: + self.other_elements.append(self.layout_selection) + self.tutorial_screen_elements = [ self.tutorial_image, self.continue_button, @@ -1269,7 +1291,10 @@ class PyGameGUI: environment_config_path = ROOT_DIR / "configs" / "tutorial_env_config.yaml" else: environment_config_path = ROOT_DIR / "configs" / "environment_config.yaml" - layout_path = self.layout_file_paths[self.current_layout_idx] + layout_path = self.layout_file_paths_dict[ + self.layout_selection.selected_option + ] + # layout_path = self.layout_file_paths[self.current_layout_idx] item_info_path = ROOT_DIR / "configs" / "item_info.yaml" with open(item_info_path, "r") as file: @@ -1320,6 +1345,8 @@ class PyGameGUI: number_key_sets=min(self.number_humans_to_be_added, num_key_set), disjunct=self.split_players, ) + self.level_info = env_info + self.level_info["name"] = self.layout_selection.selected_option def update_pregame_screen(self): self.level_name_label.set_text(f"Level: {self.level_info['name']}") @@ -1716,12 +1743,14 @@ class PyGameGUI: if not self.last_level: self.get_game_connection() else: - self.current_layout_idx += 1 - self.create_env_on_game_server() - 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.current_layout_idx += 1 + self.menu_state = MenuStates.Start + return + # self.create_env_on_game_server(tutorial=False) + # 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