diff --git a/flatland/utils/graphics_layer.py b/flatland/utils/graphics_layer.py index 5f0ce53afceef4aade5ed57b2e3da59e44093597..30ad93a24931e67b8f671a03f38a7e180c6e71f3 100644 --- a/flatland/utils/graphics_layer.py +++ b/flatland/utils/graphics_layer.py @@ -73,7 +73,8 @@ class GraphicsLayer(object): """ pass - def set_agent_at(self, iAgent, row, col, iDirIn, iDirOut, isSelected=False,rail_grid=None,show_debug=False): + def set_agent_at(self, iAgent, row, col, iDirIn, iDirOut, isSelected=False,rail_grid=None,show_debug=False, + clear_debug_text=True): pass def set_cell_occupied(self, iAgent, row, col): diff --git a/flatland/utils/graphics_pil.py b/flatland/utils/graphics_pil.py index f67996436f7afaea1bef423669330a47c0439f4e..3a29b64859b6de6d26b9a9deae8e17095d9d10c1 100644 --- a/flatland/utils/graphics_pil.py +++ b/flatland/utils/graphics_pil.py @@ -639,7 +639,7 @@ class PILSVG(PILGL): self.pil_zug[(in_direction_2, out_direction_2, color_idx)] = pils[color_idx] def set_agent_at(self, agent_idx, row, col, in_direction, out_direction, is_selected, - rail_grid=None, show_debug=False): + rail_grid=None, show_debug=False,clear_debug_text=True): delta_dir = (out_direction - in_direction) % 4 color_idx = agent_idx % self.n_agent_colors # when flipping direction at a dead end, use the "out_direction" direction. @@ -656,7 +656,25 @@ class PILSVG(PILGL): self.clear_layer(PILGL.SELECTED_AGENT_LAYER, 0) self.draw_image_row_col(bg_svg, (row, col), layer=PILGL.SELECTED_AGENT_LAYER) if show_debug: - self.text_rowcol((row + 0.2, col + 0.2,), str(agent_idx)) + if not clear_debug_text: + dr = 0.2 + dc = 0.2 + if in_direction == 0: + dr = 0.8 + dc = 0.0 + if in_direction == 1: + dr = 0.0 + dc = 0.8 + if in_direction == 2: + dr = 0.4 + dc = 0.8 + if in_direction == 3: + dr = 0.8 + dc = 0.4 + + self.text_rowcol((row + dr, col + dc,), str(agent_idx), layer=PILGL.SELECTED_AGENT_LAYER) + else: + self.text_rowcol((row + 0.2, col + 0.2,), str(agent_idx)) def set_cell_occupied(self, agent_idx, row, col): occupied_im = self.cell_occupied[agent_idx % len(self.cell_occupied)] diff --git a/flatland/utils/rendertools.py b/flatland/utils/rendertools.py index be6ffb79bee866590762bd5dcf3b6edd8a80e2fb..a26aa5ef3191e0b968c5cd1396f397d6cafd1dd9 100644 --- a/flatland/utils/rendertools.py +++ b/flatland/utils/rendertools.py @@ -41,7 +41,7 @@ class RenderTool(object): def __init__(self, env, gl="PILSVG", jupyter=False, agent_render_variant=AgentRenderVariant.ONE_STEP_BEHIND, - show_debug=False, screen_width=800, screen_height=600): + show_debug=False, clear_debug_text=True,screen_width=800, screen_height=600): self.env = env self.frame_nr = 0 @@ -60,6 +60,7 @@ class RenderTool(object): self.new_rail = True self.show_debug = show_debug + self.clear_debug_text = clear_debug_text self.update_background() def reset(self): @@ -556,7 +557,8 @@ class RenderTool(object): if self.agent_render_variant == AgentRenderVariant.ONE_STEP_BEHIND_AND_BOX: self.gl.set_cell_occupied(agent_idx, *(agent.position)) self.gl.set_agent_at(agent_idx, *position, old_direction, direction, - selected_agent == agent_idx, rail_grid=env.rail.grid, show_debug=self.show_debug) + selected_agent == agent_idx, rail_grid=env.rail.grid, + show_debug=self.show_debug,clear_debug_text=self.clear_debug_text) else: position = agent.position direction = agent.direction @@ -569,7 +571,7 @@ class RenderTool(object): # set_agent_at uses the agent index for the color self.gl.set_agent_at(agent_idx, *position, agent.direction, direction, selected_agent == agent_idx, rail_grid=env.rail.grid, - show_debug=self.show_debug) + show_debug=self.show_debug,clear_debug_text=self.clear_debug_text) # set_agent_at uses the agent index for the color if self.agent_render_variant == AgentRenderVariant.AGENT_SHOWS_OPTIONS_AND_BOX: