game/user_interface/action_prompt.gd

50 lines
1.0 KiB
GDScript3
Raw Normal View History

@tool
class_name ActionPrompt extends Control
##
2023-02-01 01:05:48 +01:00
## The prompt accept button has been pressed.
##
signal prompt_accepted()
##
2023-02-01 01:05:48 +01:00
## The prompt has been started.
##
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.
##
@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-02-01 01:05:48 +01:00
## [signal prompt_accepted] is emitted when the accept button in the action prompt is pressed.
##
func prompt() -> void:
LocalPlayer.override_controls(hidden)
show()
prompted.emit()
if initial_focus != null:
initial_focus.grab_focus()