SaveDeletionWarning.gd 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. extends Control
  2. @onready var cursor: TextureRect = $Cursor
  3. var selected_index := 0
  4. signal selected
  5. signal cancelled
  6. var active := false
  7. @onready var choices := [$PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/Yes, $PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/No]
  8. func _process(_delta: float) -> void:
  9. if active:
  10. handle_input()
  11. cursor.global_position.x = choices[selected_index].global_position.x - 6
  12. func open() -> void:
  13. show()
  14. AudioManager.play_global_sfx("pause")
  15. selected_index = 1
  16. await get_tree().process_frame
  17. active = true
  18. await selected
  19. hide()
  20. func handle_input() -> void:
  21. if Input.is_action_just_pressed("ui_left"):
  22. selected_index -= 1
  23. if Input.is_action_just_pressed("ui_right"):
  24. selected_index += 1
  25. if Input.is_action_just_pressed("ui_back"):
  26. close()
  27. cancelled.emit()
  28. selected_index = clamp(selected_index, 0, 1)
  29. if Input.is_action_just_pressed("ui_accept"):
  30. select()
  31. func select() -> void:
  32. selected.emit()
  33. close()
  34. func close() -> void:
  35. active = false
  36. hide()