2023-01-25 00:26:17 +01:00
|
|
|
@tool
|
|
|
|
class_name ActionPrompt extends Control
|
|
|
|
|
|
|
|
##
|
2023-02-01 01:05:48 +01:00
|
|
|
## The prompt accept button has been pressed.
|
2023-01-25 00:26:17 +01:00
|
|
|
##
|
|
|
|
signal prompt_accepted()
|
|
|
|
|
|
|
|
##
|
2023-02-01 01:05:48 +01:00
|
|
|
## The prompt has been started.
|
2023-01-25 00:26:17 +01:00
|
|
|
##
|
|
|
|
signal prompted()
|
|
|
|
|
|
|
|
@export
|
|
|
|
var _accept_button: BaseButton = null
|
|
|
|
|
2023-02-01 01:05:48 +01:00
|
|
|
##
|
|
|
|
## The initial control focused on when it is prompted or [code]null[/code] for no default.
|
|
|
|
##
|
2023-01-25 00:26:17 +01:00
|
|
|
@export
|
|
|
|
var initial_focus: Control = null
|
|
|
|
|
|
|
|
func _get_configuration_warnings() -> PackedStringArray:
|
|
|
|
var warnings := PackedStringArray()
|
|
|
|
|
|
|
|
if _accept_button == null:
|
|
|
|
warnings.append("`Accept Button` must point to a valid BaseButton instance")
|
|
|
|
|
|
|
|
return warnings
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
assert(_accept_button != null, "accept button cannot be null")
|
|
|
|
|
|
|
|
_accept_button.pressed.connect(func () -> void:
|
|
|
|
prompt_accepted.emit()
|
|
|
|
hide())
|
|
|
|
|
|
|
|
##
|
2023-02-01 01:05:48 +01:00
|
|
|
## Starts the prompt, emitting [signal prompted].
|
2023-01-25 00:26:17 +01:00
|
|
|
##
|
2023-02-01 01:05:48 +01:00
|
|
|
## [signal prompt_accepted] is emitted when the accept button in the action prompt is pressed.
|
2023-01-25 00:26:17 +01:00
|
|
|
##
|
|
|
|
func prompt() -> void:
|
2023-01-26 00:39:10 +01:00
|
|
|
LocalPlayer.override_controls(hidden)
|
2023-01-25 00:26:17 +01:00
|
|
|
show()
|
|
|
|
prompted.emit()
|
|
|
|
|
|
|
|
if initial_focus != null:
|
|
|
|
initial_focus.grab_focus()
|