From 015909d759d25e67af06d14996c233e3bb666a8c Mon Sep 17 00:00:00 2001
From: fheinrich <fheinrich@techfak.uni-bielefeld.de>
Date: Thu, 21 Mar 2024 13:43:50 +0100
Subject: [PATCH] Color of score label is green when score increases, red if
 score decreases.

---
 cooperative_cuisine/pygame_2d_vis/gui.py | 30 +++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/cooperative_cuisine/pygame_2d_vis/gui.py b/cooperative_cuisine/pygame_2d_vis/gui.py
index df472228..0b4e18cb 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
@@ -1425,6 +1429,30 @@ class PyGameGUI:
             "translations.score", text_kwargs={"score": str(score)}
         )
 
+        if self.switch_score_color:
+            self.count_frames_score_label += 1
+
+        duration_color_change = 30
+        if score > self.last_score:
+            self.score_label.update_theming('{"colours": {"normal_text": "#00FF00"}}')
+            self.count_frames_score_label = 0
+            self.switch_score_color = True
+            print("do once?")
+        elif score < self.last_score:
+            self.score_label.update_theming('{"colours": {"normal_text": "#FF0000"}}')
+            self.count_frames_score_label = 0
+            self.switch_score_color = True
+            print("do once?1")
+        else:
+            if self.count_frames_score_label >= duration_color_change:
+                self.score_label.update_theming(
+                    '{"colours": {"normal_text": "#000000"}}'
+                )
+                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 +1500,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))
-- 
GitLab