feat: can now add things to prompter and it can perform things.
This commit is contained in:
parent
6b9a338a20
commit
a49325eb37
|
|
@ -3,22 +3,33 @@ extends Button
|
||||||
## A button representing a specific action, and offering a default prompt that can be changed
|
## A button representing a specific action, and offering a default prompt that can be changed
|
||||||
class_name PromptButton
|
class_name PromptButton
|
||||||
|
|
||||||
var _action : StringName
|
signal performed(action: StringName)
|
||||||
|
|
||||||
|
@onready var action_prompt : ActionPrompt = $ActionPrompt
|
||||||
|
|
||||||
@export_custom(PROPERTY_HINT_INPUT_NAME, "show_builtin") var action : StringName = &"ui_accept":
|
@export_custom(PROPERTY_HINT_INPUT_NAME, "show_builtin") var action : StringName = &"ui_accept":
|
||||||
set(value):
|
set(value):
|
||||||
_action = value
|
action = value
|
||||||
if is_node_ready():
|
if is_node_ready():
|
||||||
_update_action()
|
_update_action()
|
||||||
else:
|
else:
|
||||||
_update_action.call_deferred()
|
_update_action.call_deferred()
|
||||||
|
|
||||||
get: return _action
|
get: return action
|
||||||
|
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
self.pressed.connect(perform)
|
||||||
|
action_prompt.pressed.connect(perform)
|
||||||
|
|
||||||
|
|
||||||
|
func perform() -> void:
|
||||||
|
performed.emit(action)
|
||||||
|
|
||||||
|
|
||||||
func _update_action():
|
func _update_action():
|
||||||
text = _action
|
text = action
|
||||||
$ActionPrompt.action = _action
|
action_prompt.action = action
|
||||||
|
|
||||||
|
|
||||||
func _override_prompt(prompt: String):
|
func _override_prompt(prompt: String):
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,63 @@ extends Control
|
||||||
class_name Prompter
|
class_name Prompter
|
||||||
|
|
||||||
|
|
||||||
signal action_performed(action: String)
|
signal performed(action: String)
|
||||||
|
|
||||||
var _prompts : Dictionary[StringName, Control] = {}
|
var _prompts : Dictionary[StringName, Control] = {}
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
for prompt in get_tree().get_nodes_in_group("prompts"):
|
_register_prompts()
|
||||||
|
test()
|
||||||
|
|
||||||
|
func _register_prompts() -> void:
|
||||||
|
for prompt in get_tree().get_nodes_in_group("prompts") as Array[PromptButton]:
|
||||||
_prompts[prompt.name] = prompt
|
_prompts[prompt.name] = prompt
|
||||||
prompt.get_parent().remove_child(prompt)
|
prompt.get_parent().remove_child(prompt)
|
||||||
print(prompt)
|
prompt.performed.connect(_perform)
|
||||||
|
prints("Prompter.gd:", "registered", prompt)
|
||||||
|
|
||||||
|
|
||||||
|
func _perform(action : StringName):
|
||||||
|
prints("Prompter.gd:", "PERFORMED", action)
|
||||||
|
performed.emit(action)
|
||||||
|
|
||||||
|
|
||||||
|
func test() -> void:
|
||||||
|
await get_tree().create_timer(0.5).timeout
|
||||||
|
var prompts := pick("ui_cancel", "ui_accept")
|
||||||
|
show_left_bottom(prompts)
|
||||||
|
|
||||||
|
|
||||||
|
func _show(container: Control, controls: Array[Control], overrides: Array[StringName] = []) -> void:
|
||||||
|
for i in range(len(controls)):
|
||||||
|
var control := controls[i]
|
||||||
|
var override : StringName = overrides[i] if overrides else &""
|
||||||
|
container.add_child(control)
|
||||||
|
control.appear(override)
|
||||||
|
|
||||||
|
|
||||||
|
func _clear(container: Control) -> void:
|
||||||
|
for child in container.get_children():
|
||||||
|
container.remove_child(child)
|
||||||
|
|
||||||
|
|
||||||
|
func show_left_bottom(controls: Array[Control], overrides: Array[StringName] = []) -> void:
|
||||||
|
_show(%LeftBottom, controls, overrides)
|
||||||
|
|
||||||
|
|
||||||
|
func clear_left_bottom() -> void:
|
||||||
|
_clear(%LeftBottom)
|
||||||
|
|
||||||
|
|
||||||
|
## Selects a list of up to three prompts to be passed to the show_xxxxx() functions
|
||||||
|
func pick(p0: StringName, p1: StringName = "", p2: StringName = "") -> Array[Control]:
|
||||||
|
var result : Array[Control] = []
|
||||||
|
assert(p0 in _prompts, p0 + " is not a known prompt.")
|
||||||
|
assert(not p1 or p1 in _prompts, p1 + " is not a known prompt.")
|
||||||
|
assert(not p2 or p2 in _prompts, p2 + " is not a known prompt.")
|
||||||
|
|
||||||
|
result.append(_prompts[p0])
|
||||||
|
if p1: result.append(_prompts[p1])
|
||||||
|
if p2: result.append(_prompts[p2])
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
|
||||||
|
|
@ -41,30 +41,30 @@ offset_right = 1836.0
|
||||||
offset_bottom = 996.0
|
offset_bottom = 996.0
|
||||||
mouse_filter = 2
|
mouse_filter = 2
|
||||||
|
|
||||||
[node name="MarginContainer" type="MarginContainer" parent="SafeZone/CenterContainer"]
|
[node name="CenterZone" type="MarginContainer" parent="SafeZone/CenterContainer"]
|
||||||
custom_minimum_size = Vector2(700, 700)
|
custom_minimum_size = Vector2(700, 700)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
theme_override_constants/margin_top = 42
|
theme_override_constants/margin_top = 42
|
||||||
theme_override_constants/margin_right = 42
|
theme_override_constants/margin_right = 42
|
||||||
|
|
||||||
[node name="TopCenter" type="PanelContainer" parent="SafeZone/CenterContainer/MarginContainer"]
|
[node name="TopCenter" type="PanelContainer" parent="SafeZone/CenterContainer/CenterZone"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 4
|
size_flags_horizontal = 4
|
||||||
size_flags_vertical = 0
|
size_flags_vertical = 0
|
||||||
theme_override_styles/panel = SubResource("StyleBoxFlat_ba0r8")
|
theme_override_styles/panel = SubResource("StyleBoxFlat_ba0r8")
|
||||||
|
|
||||||
[node name="Label" type="Label" parent="SafeZone/CenterContainer/MarginContainer/TopCenter"]
|
[node name="Label" type="Label" parent="SafeZone/CenterContainer/CenterZone/TopCenter"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "object to interact with"
|
text = "object to interact with"
|
||||||
label_settings = SubResource("LabelSettings_fbpt0")
|
label_settings = SubResource("LabelSettings_fbpt0")
|
||||||
horizontal_alignment = 1
|
horizontal_alignment = 1
|
||||||
|
|
||||||
[node name="Control" type="Control" parent="SafeZone/CenterContainer/MarginContainer"]
|
[node name="CenterAnchor" type="Control" parent="SafeZone/CenterContainer/CenterZone"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 4
|
size_flags_horizontal = 4
|
||||||
size_flags_vertical = 8
|
size_flags_vertical = 8
|
||||||
|
|
||||||
[node name="VBoxContainer" type="VBoxContainer" parent="SafeZone/CenterContainer/MarginContainer/Control"]
|
[node name="Center" type="VBoxContainer" parent="SafeZone/CenterContainer/CenterZone/CenterAnchor"]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 7
|
anchors_preset = 7
|
||||||
anchor_left = 0.5
|
anchor_left = 0.5
|
||||||
|
|
@ -81,14 +81,11 @@ size_flags_vertical = 8
|
||||||
theme_override_constants/separation = 48
|
theme_override_constants/separation = 48
|
||||||
alignment = 2
|
alignment = 2
|
||||||
|
|
||||||
[node name="collect_memento_ui" parent="SafeZone/CenterContainer/MarginContainer/Control/VBoxContainer" instance=ExtResource("5_fbpt0")]
|
[node name="collect_memento_ui" parent="SafeZone/CenterContainer/CenterZone/CenterAnchor/Center" instance=ExtResource("5_fbpt0")]
|
||||||
unique_name_in_owner = true
|
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "collect_memento_ui"
|
text = "collect_memento_ui"
|
||||||
action = &"collect_memento_ui"
|
|
||||||
|
|
||||||
[node name="option_memento_ui" parent="SafeZone/CenterContainer/MarginContainer/Control/VBoxContainer" instance=ExtResource("5_fbpt0")]
|
[node name="option_memento_ui" parent="SafeZone/CenterContainer/CenterZone/CenterAnchor/Center" instance=ExtResource("5_fbpt0")]
|
||||||
unique_name_in_owner = true
|
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "option_memento_ui"
|
text = "option_memento_ui"
|
||||||
action = &"option_memento_ui"
|
action = &"option_memento_ui"
|
||||||
|
|
@ -109,14 +106,15 @@ text = "a general explanation or hint about what is going on
|
||||||
or an evaluation such as on the card-board"
|
or an evaluation such as on the card-board"
|
||||||
horizontal_alignment = 1
|
horizontal_alignment = 1
|
||||||
|
|
||||||
[node name="LeftBottom" type="Control" parent="SafeZone"]
|
[node name="LeftBottomAnchor" type="Control" parent="SafeZone"]
|
||||||
anchors_preset = 0
|
anchors_preset = 0
|
||||||
offset_top = 996.0
|
offset_top = 996.0
|
||||||
offset_bottom = 996.0
|
offset_bottom = 996.0
|
||||||
size_flags_horizontal = 0
|
size_flags_horizontal = 0
|
||||||
size_flags_vertical = 8
|
size_flags_vertical = 8
|
||||||
|
|
||||||
[node name="VBox" type="VBoxContainer" parent="SafeZone/LeftBottom"]
|
[node name="LeftBottom" type="VBoxContainer" parent="SafeZone/LeftBottomAnchor"]
|
||||||
|
unique_name_in_owner = true
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 2
|
anchors_preset = 2
|
||||||
anchor_top = 1.0
|
anchor_top = 1.0
|
||||||
|
|
@ -130,22 +128,20 @@ size_flags_vertical = 4
|
||||||
theme_override_constants/separation = 48
|
theme_override_constants/separation = 48
|
||||||
alignment = 2
|
alignment = 2
|
||||||
|
|
||||||
[node name="Accept" parent="SafeZone/LeftBottom/VBox" instance=ExtResource("5_fbpt0")]
|
[node name="ui_accept" parent="SafeZone/LeftBottomAnchor/LeftBottom" instance=ExtResource("5_fbpt0")]
|
||||||
unique_name_in_owner = true
|
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
||||||
[node name="Cancel" parent="SafeZone/LeftBottom/VBox" instance=ExtResource("5_fbpt0")]
|
[node name="ui_cancel" parent="SafeZone/LeftBottomAnchor/LeftBottom" instance=ExtResource("5_fbpt0")]
|
||||||
unique_name_in_owner = true
|
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "ui_cancel"
|
text = "ui_cancel"
|
||||||
action = &"ui_cancel"
|
action = &"ui_cancel"
|
||||||
|
|
||||||
[node name="Skip" parent="SafeZone/LeftBottom/VBox" instance=ExtResource("5_fbpt0")]
|
[node name="scene_skip" parent="SafeZone/LeftBottomAnchor/LeftBottom" instance=ExtResource("5_fbpt0")]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "scene_skip"
|
text = "scene_skip"
|
||||||
action = &"scene_skip"
|
action = &"scene_skip"
|
||||||
|
|
||||||
[node name="RightBottom" type="Control" parent="SafeZone"]
|
[node name="RightBottomAnchor" type="Control" parent="SafeZone"]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 3
|
anchors_preset = 3
|
||||||
anchor_left = 1.0
|
anchor_left = 1.0
|
||||||
|
|
@ -157,7 +153,8 @@ offset_top = -40.0
|
||||||
grow_horizontal = 0
|
grow_horizontal = 0
|
||||||
grow_vertical = 0
|
grow_vertical = 0
|
||||||
|
|
||||||
[node name="VBox" type="VBoxContainer" parent="SafeZone/RightBottom"]
|
[node name="RightBottom" type="VBoxContainer" parent="SafeZone/RightBottomAnchor"]
|
||||||
|
unique_name_in_owner = true
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 3
|
anchors_preset = 3
|
||||||
anchor_left = 1.0
|
anchor_left = 1.0
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue