car_select.gd 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. extends Control
  2. var town: Node3D = null
  3. func _ready():
  4. # Automatically focus the first item for gamepad accessibility.
  5. $HBoxContainer/MiniVan.call_deferred("grab_focus")
  6. func _process(_delta: float):
  7. if Input.is_action_just_pressed(&"back"):
  8. _on_back_pressed()
  9. func _load_scene(car_scene: PackedScene):
  10. var car: Node3D = car_scene.instantiate()
  11. car.name = "car"
  12. town = preload("res://town/town_scene.tscn").instantiate()
  13. town.get_node(^"InstancePos").add_child(car)
  14. town.get_node(^"Spedometer").car_body = car.get_child(0)
  15. town.get_node(^"Back").pressed.connect(self._on_back_pressed)
  16. get_parent().add_child(town)
  17. hide()
  18. func _on_back_pressed():
  19. if is_instance_valid(town):
  20. # Currently in the town, go back to main menu.
  21. town.queue_free()
  22. show()
  23. # Automatically focus the first item for gamepad accessibility.
  24. $HBoxContainer/MiniVan.call_deferred("grab_focus")
  25. else:
  26. # In main menu, exit the game.
  27. get_tree().quit()
  28. func _on_mini_van_pressed():
  29. _load_scene(preload("res://vehicles/car_base.tscn"))
  30. func _on_trailer_truck_pressed():
  31. _load_scene(preload("res://vehicles/trailer_truck.tscn"))
  32. func _on_tow_truck_pressed():
  33. _load_scene(preload("res://vehicles/tow_truck.tscn"))