diff --git a/CHANGELOG.md b/CHANGELOG.md index c62dca6a65b6a2b0fa8c9cfcfb66f64bd68aa6b5..1cfacd4d945ac7f271a9e9541ab044d76b7ec37f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ - Pathfinding in random agent - Level layouts from 2d-grid-overcooked-literature - Caching of graph recipe layouts +- Score label changes color when score changes ### Changed diff --git a/cooperative_cuisine/pygame_2d_vis/gui.py b/cooperative_cuisine/pygame_2d_vis/gui.py index df472228b29051133df2872bc8b1b28db9d3d767..c74bf0f4f62d16530b383b631c375b75e394c84e 100644 --- a/cooperative_cuisine/pygame_2d_vis/gui.py +++ b/cooperative_cuisine/pygame_2d_vis/gui.py @@ -203,6 +203,10 @@ class PyGameGUI: self.images_path = ROOT_DIR / "pygame_gui" / "images" self.vis = Visualizer(self.visualization_config) + self.last_score: float = 0 + self.switch_score_color: bool = False + self.count_frames_score_label: int = 0 + self.fullscreen = False if self.show_debug_elements else True self.menu_state = MenuStates.Start @@ -827,13 +831,12 @@ class PyGameGUI: anchors={"centerx": "centerx", "top_target": self.level_name_label}, ) - scroll_height = ( + self.scroll_height = ( self.continue_button.get_abs_rect().top - self.text_recipes_label.get_abs_rect().bottom ) - self.scroll_width = self.window_width self.scroll_space_recipes = pygame_gui.elements.UIScrollingContainer( - relative_rect=pygame.Rect((0, 0), (self.scroll_width, scroll_height)), + relative_rect=pygame.Rect((0, 0), (self.window_width, self.scroll_height)), manager=self.manager, anchors={"centerx": "centerx", "top_target": self.text_recipes_label}, ) @@ -947,7 +950,7 @@ class PyGameGUI: ) self.scroll_width_completed_meals = self.window_width self.scroll_space_completed_meals = pygame_gui.elements.UIScrollingContainer( - relative_rect=pygame.Rect((0, 0), (self.scroll_width, scroll_height)), + relative_rect=pygame.Rect((0, 0), (self.window_width, scroll_height)), manager=self.manager, anchors={ "centerx": "centerx", @@ -1425,6 +1428,33 @@ class PyGameGUI: "translations.score", text_kwargs={"score": str(score)} ) + if self.switch_score_color: + self.count_frames_score_label += 1 + + duration_color_change = 90 + if score > self.last_score: + self.score_label.update_theming( + '{"colours": {"normal_text": "#03b706"}, "font": { "size": 22, "bold": 1}}' + ) + + self.count_frames_score_label = 0 + self.switch_score_color = True + elif score < self.last_score: + self.score_label.update_theming( + '{"colours": {"normal_text": "#e22312"}, "font": { "size": 22, "bold": 1}}' + ) + self.count_frames_score_label = 0 + self.switch_score_color = True + elif self.switch_score_color: + if self.count_frames_score_label >= duration_color_change: + self.score_label.update_theming( + '{"colours": {"normal_text": "#000000"}, "font": { "size": 20, "bold": 0}}' + ) + self.count_frames_score_label = 0 + self.switch_score_color = False + + self.last_score = score + def update_remaining_time(self, remaining_time: float): """Updates the remaining time label. @@ -1472,7 +1502,7 @@ class PyGameGUI: environment_config=environment_config, layout_config=layout, seed=seed, - env_name=layout_path.stem + env_name=layout_path.stem, ).model_dump(mode="json") # print(CreateEnvironmentConfig.model_validate_json(json_data=creation_json)) @@ -1519,7 +1549,7 @@ class PyGameGUI: for rg in self.level_info["recipe_graphs"]: rows += len(np.unique(np.array(list(rg["layout"].values()))[:, 1])) row_height = self.window_height / 14 - container_width = self.scroll_width * 0.9 + container_width = self.window_width * 0.9 container_height = rows * row_height icon_size = row_height * 0.9 @@ -1600,11 +1630,10 @@ class PyGameGUI: container=container, anchors={"centery": "centery", "right": "right"}, ) - last_recipes_labels.append(container) self.scroll_space_recipes.set_scrollable_area_dimensions( - (self.scroll_width * 0.95, container_height) + (self.window_width * 0.95, container_height) ) def setup_tutorial(self): diff --git a/cooperative_cuisine/pygame_2d_vis/locales/translations.de.json b/cooperative_cuisine/pygame_2d_vis/locales/translations.de.json index 3631b59148638e31c73f8246d6613756ceab91fa..6e3098c96adcec81e6481b04d31062f8a9922539 100644 --- a/cooperative_cuisine/pygame_2d_vis/locales/translations.de.json +++ b/cooperative_cuisine/pygame_2d_vis/locales/translations.de.json @@ -13,7 +13,7 @@ "salad_recipe": "Rezept für Salat:", "recipes_in_this_level": "Rezepte in diesem Level:", "level_name": "%{level}", - "was_served": " wurde serviert", + "was_served": " wurde serviert.", "waiting_for_players": "WARTE AUF ANDERE SPIELER", "orders": "Bestellungen:", "score": "Punktestand: %{score}", diff --git a/cooperative_cuisine/pygame_2d_vis/locales/translations.en.json b/cooperative_cuisine/pygame_2d_vis/locales/translations.en.json index 3e1b3f392fb7cc071e60695cf5f89798eb793516..b2674d78e5abe8373c93eb914b124ccac798e596 100644 --- a/cooperative_cuisine/pygame_2d_vis/locales/translations.en.json +++ b/cooperative_cuisine/pygame_2d_vis/locales/translations.en.json @@ -13,7 +13,7 @@ "salad_recipe": "Salad recipe:", "recipes_in_this_level": "Recipes in this level:", "level_name": "%{level}", - "was_served": " was served", + "was_served": " was served.", "waiting_for_players": "WAITING FOR OTHER PLAYERS", "orders": "Orders:", "score": "Score: %{score}",