frame-of-mind/src/ui/prompter/prompt_button.gd

39 lines
947 B
GDScript3
Raw Normal View History

2026-01-23 12:39:47 +00:00
@tool
extends Button
## A button representing a specific action, and offering a default prompt that can be changed
class_name PromptButton
var _action : StringName
var _override : String
@export_custom(PROPERTY_HINT_INPUT_NAME, "show_builtin") var action : StringName = &"ui_accept":
set(value):
if is_node_ready():
_set_action(value)
else:
_set_action.call_deferred(value)
get: return _action
func _set_action(value: StringName):
if _action == text or not text or not _action:
text = value
_action = value
$ActionPrompt.action = _action
func appear(prompt: String = "") -> void:
assert(not _override, "Prompt is already in use, overridden from '" + _override + "' to '" + text + "'")
if prompt:
_override = text
text = prompt
show()
func vanish() -> void:
hide()
if _override:
text = _override
_override = ""
else:
text = action # TODO: this is a bit backwards and doesn't allow manual overrides in editor