Skip to content
Snippets Groups Projects
Commit ec29d41c authored by Florian Schröder's avatar Florian Schröder
Browse files

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.
parent 5055e503
No related branches found
No related tags found
1 merge request!53Resolve "Info screens (pop ups etc)"
Pipeline #46072 passed
......@@ -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(
......
......@@ -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)
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