| 1241 | |
| 1242 | |
| 1243 | class ModuleInput(object): |
| 1244 | def __init__(self, name): |
| 1245 | self.name = name |
| 1246 | self.mouse_pos = (0, 0) |
| 1247 | self.mouse_offset = [0.0, 0.0] |
| 1248 | self.wheel_offset = 0.1 |
| 1249 | self.wheel_amount = 0.025 |
| 1250 | self._steer_cache = 0.0 |
| 1251 | self.control = None |
| 1252 | self._autopilot_enabled = False |
| 1253 | |
| 1254 | def start(self): |
| 1255 | hud = module_manager.get_module(MODULE_HUD) |
| 1256 | hud.notification("Press 'H' or '?' for help.", seconds=4.0) |
| 1257 | |
| 1258 | def render(self, display): |
| 1259 | pass |
| 1260 | |
| 1261 | def tick(self, clock): |
| 1262 | self.parse_input(clock) |
| 1263 | |
| 1264 | def _parse_events(self): |
| 1265 | self.mouse_pos = pygame.mouse.get_pos() |
| 1266 | for event in pygame.event.get(): |
| 1267 | if event.type == pygame.QUIT: |
| 1268 | exit_game() |
| 1269 | elif event.type == pygame.KEYUP: |
| 1270 | if self._is_quit_shortcut(event.key): |
| 1271 | exit_game() |
| 1272 | elif event.key == K_h or (event.key == K_SLASH and pygame.key.get_mods() & KMOD_SHIFT): |
| 1273 | module_hud = module_manager.get_module(MODULE_HUD) |
| 1274 | module_hud.help.toggle() |
| 1275 | elif event.key == K_TAB: |
| 1276 | module_world = module_manager.get_module(MODULE_WORLD) |
| 1277 | module_hud = module_manager.get_module(MODULE_HUD) |
| 1278 | if module_world.hero_actor is None: |
| 1279 | module_world.select_hero_actor() |
| 1280 | self.wheel_offset = HERO_DEFAULT_SCALE |
| 1281 | self.control = carla.VehicleControl() |
| 1282 | module_hud.notification('Hero Mode') |
| 1283 | else: |
| 1284 | self.wheel_offset = MAP_DEFAULT_SCALE |
| 1285 | self.mouse_offset = [0, 0] |
| 1286 | self.mouse_pos = [0, 0] |
| 1287 | module_world.scale_offset = [0, 0] |
| 1288 | module_world.hero_actor = None |
| 1289 | module_hud.notification('Map Mode') |
| 1290 | elif event.key == K_F1: |
| 1291 | module_hud = module_manager.get_module(MODULE_HUD) |
| 1292 | module_hud.show_info = not module_hud.show_info |
| 1293 | elif event.key == K_i: |
| 1294 | module_hud = module_manager.get_module(MODULE_HUD) |
| 1295 | module_hud.show_actor_ids = not module_hud.show_actor_ids |
| 1296 | elif isinstance(self.control, carla.VehicleControl): |
| 1297 | if event.key == K_q: |
| 1298 | self.control.gear = 1 if self.control.reverse else -1 |
| 1299 | elif event.key == K_m: |
| 1300 | self.control.manual_gear_shift = not self.control.manual_gear_shift |