Added dialogue manager plugin

This commit is contained in:
Matthew Barbour
2026-08-30 01:15:04 -05:00
parent e90ea3a0a4
commit f983ab64ce
186 changed files with 20125 additions and 0 deletions
@@ -0,0 +1,43 @@
@tool
class_name DMCueEditorProperty extends EditorProperty
var DMCuePropertyEditorControl: PackedScene = preload("./editor_property_control.tscn")
var control: Control = DMCuePropertyEditorControl.instantiate()
var current_value: String
var is_updating: bool = false
func _init() -> void:
add_child(control)
control.cue = current_value
control.cue_changed.connect(_on_cue_changed)
func _update_property() -> void:
control.actionable = get_edited_object()
var next_value: String = get_edited_object()[get_edited_property()]
if next_value.is_empty():
control.cue = ""
return
if next_value == current_value: return
is_updating = true
current_value = next_value
control.cue = current_value
is_updating = false
#region Signals
func _on_cue_changed(next_cue: String) -> void:
emit_changed(get_edited_property(), next_cue)
#endregion
@@ -0,0 +1 @@
uid://bak7go3j7n0qf
@@ -0,0 +1,142 @@
@tool
extends HBoxContainer
signal cue_changed(next_cue: String)
const CUE_ICON: Texture2D = preload("uid://d1aawtj2vsnxx")
var actionable: Node = null
var cue: String = "":
set(value):
cue = value
if not is_node_ready():
await ready
_update()
get:
return cue
var link_action: String = "show"
@onready var button: OptionButton = %Button
@onready var link_button: Button = %LinkButton
@onready var confirm_cue_name_dialog: ConfirmationDialog = %ConfirmCueNameDialog
@onready var cue_name_label: Label = %CueNameLabel
@onready var cue_name_edit: LineEdit = %CueNameEdit
func _ready() -> void:
confirm_cue_name_dialog.register_text_enter(cue_name_edit)
_update()
button.get_popup().index_pressed.connect(_on_index_pressed)
button.get_popup().about_to_popup.connect(_on_menu_about_to_popup)
DMPlugin.instance.import_plugin.compiled_resource.connect(_on_dialogue_compiled)
func _update() -> void:
var resource: DialogueResource = _get_resource()
var cues: PackedStringArray = []
if is_instance_valid(resource):
cues = Array(resource.get_cues()).filter(func(l: String) -> bool: return not l.contains("/"))
link_button.disabled = not is_instance_valid(resource)
var popup: PopupMenu = button.get_popup()
popup.clear()
var cue_icon: Texture2D = DMThemeValues.get_icon_with_color(CUE_ICON, DMThemeValues.get_values_from_editor().cues_color)
if cues.is_empty() or not is_instance_valid(resource):
popup.add_item(DMConstants.translate("<empty>"))
popup.set_item_disabled(0, true)
else:
for existing_cue: String in cues:
popup.add_icon_item(cue_icon, existing_cue)
if not cue.is_empty() and not cues.has(cue):
popup.add_icon_item(CUE_ICON, cue)
if cue.is_empty():
button.text = DMConstants.translate("<empty>")
button.icon = null
link_button.icon = get_theme_icon("New", "EditorIcons")
link_action = "create"
elif cues.has(cue):
button.select(-1)
button.select(cues.find(cue))
link_button.icon = get_theme_icon("ExternalLink", "EditorIcons")
link_action = "show"
else:
button.select(cues.size())
link_button.icon = get_theme_icon("New", "EditorIcons")
link_action = "create"
func show_cue_in_editor(next_cue: String) -> void:
var resource: DialogueResource = _get_resource()
if is_instance_valid(resource):
DMPlugin.open_file_at_cue(resource, next_cue, true)
func _get_resource() -> DialogueResource:
if not is_instance_valid(actionable): return null
var resource: DialogueResource
for property: Dictionary in actionable.get_property_list():
if "dialogue_resource" in property.name or "DialogueResource" in property.name or (property.class_name == "Resource" and actionable.get(property.name) is DialogueResource):
resource = actionable.get(property.name)
if is_instance_valid(resource):
return ResourceLoader.load(resource.resource_path, "", ResourceLoader.CACHE_MODE_REPLACE)
return null
#region Signals
func _on_dialogue_compiled(_resource: DialogueResource) -> void:
_update.call_deferred()
func _on_menu_about_to_popup() -> void:
_update()
func _on_index_pressed(index: int) -> void:
cue = button.get_popup().get_item_text(index)
cue_changed.emit(cue)
_update()
func _on_link_button_pressed() -> void:
match link_action:
"create":
if cue.is_empty():
cue_name_edit.text = actionable.name.to_snake_case()
else:
cue_name_edit.text = cue
cue_name_label.text = DMConstants.translate("Cue:")
confirm_cue_name_dialog.popup_centered()
cue_name_edit.grab_focus.call_deferred()
cue_name_edit.select_all.call_deferred()
"show":
show_cue_in_editor.call_deferred(cue)
_update.call_deferred()
func _on_confirm_cue_name_dialog_confirmed() -> void:
cue = cue_name_edit.text.to_snake_case()
cue_changed.emit(cue)
show_cue_in_editor.call_deferred(cue)
_update.call_deferred()
#endregion
@@ -0,0 +1 @@
uid://cn5hcy57m088v
@@ -0,0 +1,49 @@
[gd_scene format=3 uid="uid://molgra7vqxts"]
[ext_resource type="Script" uid="uid://cn5hcy57m088v" path="res://addons/dialogue_manager/components/cue_editor_property/editor_property_control.gd" id="1_4prea"]
[node name="EditorPropertyControl" type="HBoxContainer" unique_id=1721562088]
offset_right = 40.0
offset_bottom = 40.0
script = ExtResource("1_4prea")
[node name="Button" type="OptionButton" parent="." unique_id=1093477450]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
flat = true
alignment = 1
[node name="LinkButton" type="Button" parent="." unique_id=713900927]
unique_name_in_owner = true
layout_mode = 2
flat = true
[node name="ConfirmCueNameDialog" type="ConfirmationDialog" parent="." unique_id=967805543]
unique_name_in_owner = true
oversampling_override = 1.0
size = Vector2i(200, 115)
[node name="VBoxContainer" type="VBoxContainer" parent="ConfirmCueNameDialog" unique_id=151160442]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 8.0
offset_top = 8.0
offset_right = -8.0
offset_bottom = -49.0
grow_horizontal = 2
grow_vertical = 2
[node name="CueNameLabel" type="Label" parent="ConfirmCueNameDialog/VBoxContainer" unique_id=1635294933]
unique_name_in_owner = true
layout_mode = 2
text = "Cue:"
[node name="CueNameEdit" type="LineEdit" parent="ConfirmCueNameDialog/VBoxContainer" unique_id=830071500]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
[connection signal="pressed" from="LinkButton" to="." method="_on_link_button_pressed"]
[connection signal="confirmed" from="ConfirmCueNameDialog" to="." method="_on_confirm_cue_name_dialog_confirmed"]