Skip to content

Commit d04c725

Browse files
committed
Adding inspector plugin to handle timeline selection from the dialog node :)
1 parent 15b2e96 commit d04c725

File tree

5 files changed

+91
-6
lines changed

5 files changed

+91
-6
lines changed

addons/dialogic/Editor/Pieces/ChangeTimeline.tscn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,4 @@ size_flags_horizontal = 3
9090
items = [ "Move Up", null, 0, false, false, 0, 0, null, "", false, "Move Down", null, 0, false, false, 1, 0, null, "", false, "", null, 0, false, false, 2, 0, null, "", true, "Remove", null, 0, false, false, 3, 0, null, "", false ]
9191

9292
[node name="DragController" parent="." instance=ExtResource( 5 )]
93-
9493
[connection signal="about_to_show" from="PanelContainer/VBoxContainer/Header/MenuButton" to="." method="_on_MenuButton_about_to_show"]

addons/dialogic/Nodes/dialog_node.gd

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ var waiting_for_answer: bool = false
99
var waiting_for_input: bool = false
1010
var settings
1111

12-
export(String) var timeline_id: String # Timeline-var-replace
12+
#export(String) var timeline: String # Timeline-var-replace
1313

14+
export(String, "TimelineDropdown") var timeline: String
1415

1516
var dialog_resource
1617
var characters
@@ -23,8 +24,8 @@ var questions #for keeping track of the questions answered
2324

2425
func _ready():
2526
# Checking if the dialog should read the code from a external file
26-
if timeline_id != '':
27-
dialog_script = set_current_dialog('/' + timeline_id + '.json')
27+
if timeline != '':
28+
dialog_script = set_current_dialog('/' + timeline + '.json')
2829

2930
# Connecting resize signal
3031
get_viewport().connect("size_changed", self, "resize_main")
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
extends EditorInspectorPlugin
2+
3+
var TimelinePicker = preload("res://addons/dialogic/Other/timeline_picker.gd")
4+
5+
6+
func can_handle(object):
7+
# We support all objects in this example.
8+
return true
9+
10+
11+
func parse_property(object, type, path, hint, hint_text, usage):
12+
# We check for this hint text. It would look like: export(String, "TimelineDropdown")
13+
if hint_text == "TimelineDropdown":
14+
# We handle properties of type string.
15+
if type == TYPE_STRING:
16+
# Create an instance of the custom property editor and register
17+
# it to a specific property path.
18+
add_property_editor(path, TimelinePicker.new())
19+
# Inform the editor to remove the default property editor for
20+
# this property type.
21+
return true
22+
return false
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
tool
2+
extends EditorProperty
3+
4+
5+
# The main control for editing the property.
6+
var timelines_dropdown = MenuButton.new()
7+
# An internal value of the property.
8+
var current_value = ''
9+
# A guard against internal changes when the property is updated.
10+
var updating = false
11+
12+
13+
func _init():
14+
# Add the control as a direct child of EditorProperty node.
15+
add_child(timelines_dropdown)
16+
# Make sure the control is able to retain the focus.
17+
add_focusable(timelines_dropdown)
18+
# Setup the initial state and connect to the signal to track changes.
19+
timelines_dropdown.connect("about_to_show", self, "_about_to_show_menu")
20+
timelines_dropdown.get_popup().connect("index_pressed", self, '_on_timeline_selected')
21+
22+
23+
func _about_to_show_menu():
24+
# Ignore the signal if the property is currently being updated.
25+
if (updating):
26+
return
27+
28+
# Adding timelines
29+
timelines_dropdown.get_popup().clear()
30+
var index = 0
31+
for c in DialogicUtil.get_timeline_list():
32+
timelines_dropdown.get_popup().add_item(c['name'])
33+
timelines_dropdown.get_popup().set_item_metadata(index, {'file': c['file'], 'color': c['color']})
34+
index += 1
35+
36+
func _on_timeline_selected(index):
37+
var text = timelines_dropdown.get_popup().get_item_text(index)
38+
var metadata = timelines_dropdown.get_popup().get_item_metadata(index)
39+
current_value = metadata['file'].replace('.json', '')
40+
timelines_dropdown.text = text
41+
emit_changed(get_edited_property(), current_value)
42+
43+
44+
func update_property():
45+
# Read the current value from the property.
46+
var new_value = get_edited_object()[get_edited_property()]
47+
if (new_value == current_value):
48+
return
49+
50+
# Update the control with the new value.
51+
updating = true
52+
current_value = new_value
53+
# Checking for the display name
54+
for c in DialogicUtil.get_timeline_list():
55+
if c['file'].replace('.json', '') == current_value:
56+
timelines_dropdown.text = c['name']
57+
updating = false

addons/dialogic/dialogic.gd

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,21 @@ var _editor_view # This is the plugin Scene
55
var _panel_button: Button
66
var _editor_selection: EditorSelection
77

8-
func _enter_tree():
8+
var _parts_inspector
9+
10+
func _enter_tree() -> void:
11+
_parts_inspector = preload("res://addons/dialogic/Other/inspector_timeline_picker.gd").new()
12+
add_inspector_plugin(_parts_inspector)
13+
914
_add_custom_editor_view()
1015

1116
get_editor_interface().get_editor_viewport().add_child(_editor_view)
1217
# Hide the main panel. Very much required.
1318
make_visible(false)
1419

15-
func _exit_tree():
20+
func _exit_tree() -> void:
1621
_remove_custom_editor_view()
22+
remove_inspector_plugin(_parts_inspector)
1723

1824
func has_main_screen():
1925
return true

0 commit comments

Comments
 (0)