From ec29d41c8d026d2075cc644a81eb0b63dc4d5535 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Schr=C3=B6der?= <fschroeder@techfak.uni-bielefeld.de> Date: Wed, 14 Feb 2024 12:01:17 +0100 Subject: [PATCH] Implement removal of old messages from environment The commit introduces a function to remove old information messages from the environment in the Overcooked simulator. In addition, the visualization code in the GUI was updated to display multiple messages instead of only the latest one. The display now supports different colors for normal and warning messages. --- .../gui_2d_vis/overcooked_gui.py | 30 ++++++++++--------- overcooked_simulator/info_msg.py | 11 +++++++ 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/overcooked_simulator/gui_2d_vis/overcooked_gui.py b/overcooked_simulator/gui_2d_vis/overcooked_gui.py index 4f20e235..b6a62b5b 100644 --- a/overcooked_simulator/gui_2d_vis/overcooked_gui.py +++ b/overcooked_simulator/gui_2d_vis/overcooked_gui.py @@ -605,20 +605,22 @@ class PyGameGUI: self.update_score_label(state) if state["info_msg"]: - text_surface = self.comic_sans.render( - state["info_msg"][0][0], - antialias=True, - color=(0, 0, 0) - if state["info_msg"][0][1] == "Normal" - else ( - (255, 0, 0) if state["info_msg"][0][1] == "Warning" else (0, 255, 0) - ), - # bgcolor=(255, 255, 255), - ) - self.main_window.blit( - text_surface, - (self.window_width / 4, self.window_height - self.screen_margin + 5), - ) + for idx, msg in enumerate(reversed(state["info_msg"])): + text_surface = self.comic_sans.render( + msg[0], + antialias=True, + color=(0, 0, 0) + if msg[1] == "Normal" + else ((255, 0, 0) if msg[1] == "Warning" else (0, 255, 0)), + # bgcolor=(255, 255, 255), + ) + self.main_window.blit( + text_surface, + ( + self.window_width / 4, + self.window_height - self.screen_margin + 5 + (20 * idx), + ), + ) def set_window_size(self): self.game_screen = pygame.Surface( diff --git a/overcooked_simulator/info_msg.py b/overcooked_simulator/info_msg.py index 9f88f5ff..f65385b8 100644 --- a/overcooked_simulator/info_msg.py +++ b/overcooked_simulator/info_msg.py @@ -26,3 +26,14 @@ class InfoMsgManager: "level": self.level, } ) + self.remove_old_msgs(env) + + @staticmethod + def remove_old_msgs(env: Environment): + for player_id, msgs in env.info_msgs_per_player.items(): + delete_msgs = [] + for idx, msg in enumerate(msgs): + if msg["end_time"] < env.env_time: + delete_msgs.append(idx) + for idx in reversed(delete_msgs): + msgs.pop(idx) -- GitLab