]> Untitled Git - wolf-seeking-sheep.git/blob - addons/dialogic/Editor/Inspector/timeline_inspector_field.gd
Updated export config options
[wolf-seeking-sheep.git] / addons / dialogic / Editor / Inspector / timeline_inspector_field.gd
1 @tool
2 extends EditorProperty
3
4 var field: Control = null
5 var button: Button = null
6 # An internal value of the property.
7 var current_value: DialogicTimeline = null
8 # A guard against internal changes when the property is updated.
9 var updating = false
10
11
12 func _init() -> void:
13         var hbox := HBoxContainer.new()
14         add_child(hbox)
15
16         field = load("res://addons/dialogic/Editor/Events/Fields/field_options_dynamic.tscn").instantiate()
17         hbox.add_child(field)
18         field.placeholder_text = "No Timeline"
19         field.size_flags_horizontal = Control.SIZE_EXPAND_FILL
20         field.size_flags_vertical = Control.SIZE_SHRINK_CENTER
21         field.mode = field.Modes.IDENTIFIER
22         field.fit_text_length = false
23         field.valid_file_drop_extension = ".dtl"
24         field.value_changed.connect(_on_field_value_changed)
25         field.get_suggestions_func = get_timeline_suggestions
26
27         button = Button.new()
28         hbox.add_child(button)
29         button.hide()
30         button.pressed.connect(_on_button_pressed, CONNECT_DEFERRED)
31
32
33 func _on_field_value_changed(property:String, value:Variant) -> void:
34         # Ignore the signal if the property is currently being updated.
35         if updating:
36                 return
37
38         var new_value: DialogicTimeline = null
39         if value:
40                 new_value = DialogicResourceUtil.get_timeline_resource(value)
41
42         if current_value != new_value:
43                 current_value = new_value
44                 if current_value:
45                         button.show()
46                 else:
47                         button.hide()
48                 emit_changed(get_edited_property(), current_value)
49
50
51 func _update_property() -> void:
52         field.resource_icon = get_theme_icon("TripleBar", "EditorIcons")
53         button.icon = get_theme_icon("ExternalLink", "EditorIcons")
54
55         # Read the current value from the property.
56         var new_value = get_edited_object()[get_edited_property()]
57         if (new_value == current_value):
58                 return
59
60         # Update the control with the new value.
61         updating = true
62         current_value = new_value
63         if current_value:
64                 field.set_value(DialogicResourceUtil.get_unique_identifier(current_value.resource_path))
65                 button.show()
66         else:
67                 button.hide()
68                 field.set_value("")
69         updating = false
70
71
72 func get_timeline_suggestions(filter:String) -> Dictionary:
73         var suggestions := {}
74         var timeline_directory := DialogicResourceUtil.get_timeline_directory()
75         for identifier in  timeline_directory.keys():
76                 suggestions[identifier] = {'value': identifier, 'tooltip':timeline_directory[identifier], 'editor_icon': ["TripleBar", "EditorIcons"]}
77         return suggestions
78
79
80 func _on_button_pressed() -> void:
81         if current_value:
82                 EditorInterface.edit_resource(current_value)