Skip to content
Snippets Groups Projects
Commit 952f18b3 authored by Fabian Heinrich's avatar Fabian Heinrich
Browse files

Merge branch '121-score-green-or-red-when-changed' into 'dev'

Resolve "Score green or red when changed"

Closes #121

See merge request scs/cocosy/overcooked-simulator!91
parents fcec5d6b 5c016f3e
No related branches found
No related tags found
1 merge request!91Resolve "Score green or red when changed"
Pipeline #49354 passed
......@@ -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
......
......@@ -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):
......
......@@ -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}",
......
......@@ -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}",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment