MCPcopy Create free account
hub / github.com/OpenDriveLab/DriveAdapter / ModuleHUD

Class ModuleHUD

scenario_runner/no_rendering_mode.py:283–388  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

281
282
283class ModuleHUD (object):
284
285 def __init__(self, name, width, height):
286 self.name = name
287 self.dim = (width, height)
288 self._init_hud_params()
289 self._init_data_params()
290
291 def start(self):
292 pass
293
294 def _init_hud_params(self):
295 fonts = [x for x in pygame.font.get_fonts() if 'mono' in x]
296 default_font = 'ubuntumono'
297 mono = default_font if default_font in fonts else fonts[0]
298 mono = pygame.font.match_font(mono)
299 self._font_mono = pygame.font.Font(mono, 14)
300 self._header_font = pygame.font.SysFont('Arial', 14, True)
301 self.help = HelpText(pygame.font.Font(mono, 24), *self.dim)
302 self._notifications = FadingText(
303 pygame.font.Font(pygame.font.get_default_font(), 20),
304 (self.dim[0], 40), (0, self.dim[1] - 40))
305
306 def _init_data_params(self):
307 self.show_info = True
308 self.show_actor_ids = False
309 self._info_text = {}
310
311 def notification(self, text, seconds=2.0):
312 self._notifications.set_text(text, seconds=seconds)
313
314 def tick(self, clock):
315 self._notifications.tick(clock)
316
317 def add_info(self, module_name, info):
318 self._info_text[module_name] = info
319
320 def render_vehicles_ids(self, vehicle_id_surface, list_actors, world_to_pixel, hero_actor, hero_transform):
321 vehicle_id_surface.fill(COLOR_BLACK)
322 if self.show_actor_ids:
323 vehicle_id_surface.set_alpha(150)
324 for actor in list_actors:
325 x, y = world_to_pixel(actor[1].location)
326
327 angle = 0
328 if hero_actor is not None:
329 angle = -hero_transform.rotation.yaw - 90
330
331 color = COLOR_SKY_BLUE_0
332 if int(actor[0].attributes['number_of_wheels']) == 2:
333 color = COLOR_CHOCOLATE_0
334 if actor[0].attributes['role_name'] == 'hero':
335 color = COLOR_CHAMELEON_0
336
337 font_surface = self._header_font.render(str(actor[0].id), True, color)
338 rotated_font_surface = pygame.transform.rotate(font_surface, angle)
339 rect = rotated_font_surface.get_rect(center=(x, y))
340 vehicle_id_surface.blit(rotated_font_surface, rect)

Callers 1

game_loopFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected