Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 9e1b459

Browse files
authored
Merge branch 'main' into improve-goto
2 parents 414fabc + 838aad3 commit 9e1b459

File tree

9 files changed

+265
-44
lines changed

9 files changed

+265
-44
lines changed

addons/event_system_plugin/core/event_inspector.gd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,9 @@ func parse_property(object: Object, type: int, path: String, hint: int, hint_tex
3434
if (path_ignore in object):
3535
return true
3636

37+
if path == "next_event":
38+
var node = InspectorTools.InspectorEventSelector.new()
39+
add_property_editor(path, node)
40+
return true
41+
3742
return false

addons/event_system_plugin/core/inspector_tools.gd

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
tool
2-
extends EditorInspector
32

43
class InspectorCategory extends Control:
54
var icon:Texture
@@ -52,5 +51,77 @@ class InspectorCategory extends Control:
5251
bg_color = get_color("prop_category", "Editor")
5352
update()
5453

55-
func get_category_instance() -> InspectorCategory:
56-
return InspectorCategory.new()
54+
55+
class InspectorEventSelector extends EditorProperty:
56+
var event_selector:Button
57+
var popup:ConfirmationDialog
58+
var reset_button:Button
59+
var updating:bool = false
60+
func _init() -> void:
61+
event_selector = Button.new()
62+
event_selector.text = "Select event"
63+
event_selector.connect("pressed",self,"_on_button_pressed")
64+
event_selector.size_flags_horizontal = SIZE_EXPAND_FILL
65+
66+
reset_button = Button.new()
67+
reset_button.connect("pressed", self, "_on_reset_pressed")
68+
69+
var hb = HBoxContainer.new()
70+
add_child(hb)
71+
hb.add_child(event_selector)
72+
hb.add_child(reset_button)
73+
74+
popup = load("res://addons/event_system_plugin/nodes/editor/event_selector/event_selector.tscn").instance()
75+
popup.connect("event_selected", self, "_on_event_selected")
76+
add_child(popup)
77+
78+
func _ready():
79+
reset_button.icon = get_icon("Remove", "EditorIcons")
80+
update_property()
81+
82+
83+
func update_property():
84+
var data:Array = str(get_edited_object()[get_edited_property()]).split(";", false)
85+
if data.empty():
86+
return
87+
88+
var event_idx = data[0]
89+
var timeline_path = ""
90+
if data.size() >= 2:
91+
timeline_path = data[1]
92+
93+
var timeline = null
94+
if timeline_path != "":
95+
timeline = load(timeline_path)
96+
97+
if not timeline:
98+
timeline = Engine.get_meta("EventSystem").timeline_editor._edited_sequence
99+
100+
if not timeline:
101+
return
102+
103+
var event = timeline.get("event/"+event_idx)
104+
updating = true
105+
if event:
106+
event_selector.text = event.get("event_name")
107+
updating = false
108+
109+
110+
func _on_button_pressed() -> void:
111+
var timeline = Engine.get_meta("EventSystem").timeline_editor._edited_sequence
112+
if timeline:
113+
popup.build_timeline(timeline)
114+
popup.call_deferred("popup_centered_ratio", 0.45)
115+
116+
117+
func _on_event_selected(event_idx, path) -> void:
118+
if updating:
119+
return
120+
var value = "{idx};{path}".format({"idx":event_idx, "path":path})
121+
emit_changed(get_edited_property(), value)
122+
123+
func _on_reset_pressed() -> void:
124+
if updating:
125+
return
126+
127+
emit_changed(get_edited_property(), null)

addons/event_system_plugin/events/goto.gd

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ tool
22
extends Event
33
class_name EventGoTo
44

5+
# The next event hint of this event. "<index>;<timeline>"
6+
var next_event:String = "" setget set_next_event
7+
58
func _init() -> void:
69
event_name = "Go to Event"
710
event_color = Color("#FBB13C")
@@ -11,6 +14,12 @@ func _init() -> void:
1114
event_category = "Logic"
1215
event_hint = "Helper event to define the next event after this event"
1316

17+
func set_next_event(value:String) -> void:
18+
next_event = value
19+
emit_changed()
20+
property_list_changed_notify()
21+
22+
1423
func _get(property):
1524
if property == "event_node_path_ignore":
1625
return true

addons/event_system_plugin/events/new_condition.gd

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@ var events_else:String setget _set_else_timeline
1111
var _events_if:Resource setget set_if_timeline, get_if_timeline
1212
var _events_else:Resource setget set_else_timeline, get_else_timeline
1313

14+
var next_event
15+
1416
func _execute() -> void:
1517
var variables:Dictionary = _Utils.get_property_values_from(get_event_node())
1618

1719
var evaluated_condition = _Utils.evaluate(condition, get_event_node(), variables)
1820

1921
if evaluated_condition and (str(evaluated_condition) != condition):
20-
next_event = get_if_timeline().get("event/0")
22+
get_event_manager_node().set("timeline", get_if_timeline())
2123
else:
22-
next_event = get_else_timeline().get("event/0")
24+
get_event_manager_node().set("timeline", get_else_timeline())
25+
26+
next_event = "0"
2327

2428
finish()
2529

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
tool
2+
extends ConfirmationDialog
3+
4+
signal event_selected(event, timeline_path)
5+
6+
var tree:Tree
7+
var root:TreeItem
8+
9+
var last_selected_item = null
10+
var external_path:String = ""
11+
var used_timeline:Resource = null
12+
13+
func _notification(what):
14+
if what == NOTIFICATION_POPUP_HIDE:
15+
if not visible:
16+
set_deferred("external_path", "")
17+
set_deferred("used_timeline", null)
18+
19+
func build_timeline(timeline) -> void:
20+
external_path = ""
21+
if root:
22+
root.free()
23+
24+
tree = $VBoxContainer/Tree
25+
root = tree.create_item()
26+
root.set_text(0, "Timeline")
27+
root.disable_folding = true
28+
get_ok().disabled = true
29+
30+
for event in timeline.get_events():
31+
var item:TreeItem = tree.create_item(root)
32+
item.set_text(0, str(event.get("event_name")))
33+
item.set_icon(0, event.get("event_icon"))
34+
item.set_meta("event", event)
35+
36+
used_timeline = timeline
37+
38+
39+
func get_selected_event() -> Resource:
40+
var item:TreeItem = tree.get_selected()
41+
var selected_event:Resource = null
42+
43+
if item.has_meta("event"):
44+
selected_event = item.get_meta("event")
45+
46+
return selected_event
47+
48+
49+
func _on_Tree_item_selected():
50+
get_ok().disabled = false
51+
52+
if last_selected_item == get_selected_event():
53+
_on_Tree_item_double_clicked()
54+
return
55+
56+
last_selected_item = get_selected_event()
57+
58+
59+
func _on_Tree_item_double_clicked():
60+
get_ok().grab_click_focus()
61+
62+
63+
func _on_ConfirmationDialog_confirmed():
64+
var event = get_selected_event()
65+
var events:Array = used_timeline.get_events()
66+
var event_idx = events.find(event)
67+
68+
emit_signal("event_selected", event_idx, external_path)
69+
70+
71+
func _on_External_pressed():
72+
if Engine.editor_hint:
73+
var popup:EditorFileDialog = EditorFileDialog.new()
74+
popup.display_mode = EditorFileDialog.DISPLAY_LIST
75+
popup.mode = EditorFileDialog.MODE_OPEN_FILE
76+
popup.add_filter("*.tres; Timeline")
77+
popup.connect("file_selected", self, "_on_external_file_selected")
78+
79+
add_child(popup)
80+
popup.popup_exclusive = true
81+
popup.popup_centered_ratio()
82+
83+
84+
const TimelineClass = preload("res://addons/event_system_plugin/resources/timeline_class/timeline_class.gd")
85+
func _on_external_file_selected(path:String) -> void:
86+
var res:TimelineClass = load(path) as TimelineClass
87+
if not res:
88+
push_warning("Invalid resource!")
89+
return
90+
91+
build_timeline(res)
92+
external_path = path
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
[gd_scene load_steps=2 format=2]
2+
3+
[ext_resource path="res://addons/event_system_plugin/nodes/editor/event_selector/event_selector.gd" type="Script" id=1]
4+
5+
[node name="ConfirmationDialog" type="ConfirmationDialog"]
6+
anchor_right = 1.0
7+
anchor_bottom = 1.0
8+
rect_min_size = Vector2( 150, 52.5 )
9+
popup_exclusive = true
10+
window_title = "Event Selector"
11+
script = ExtResource( 1 )
12+
__meta__ = {
13+
"_edit_use_anchors_": false
14+
}
15+
16+
[node name="VBoxContainer" type="VBoxContainer" parent="."]
17+
anchor_right = 1.0
18+
anchor_bottom = 1.0
19+
margin_left = 8.0
20+
margin_top = 8.0
21+
margin_right = -8.0
22+
margin_bottom = -36.0
23+
__meta__ = {
24+
"_edit_use_anchors_": false
25+
}
26+
27+
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
28+
margin_right = 1008.0
29+
margin_bottom = 20.0
30+
31+
[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer"]
32+
margin_top = 3.0
33+
margin_right = 152.0
34+
margin_bottom = 17.0
35+
text = "Please, select an event:"
36+
37+
[node name="External" type="Button" parent="VBoxContainer/HBoxContainer"]
38+
margin_left = 844.0
39+
margin_right = 1008.0
40+
margin_bottom = 20.0
41+
size_flags_horizontal = 10
42+
text = "Use a different timeline"
43+
44+
[node name="Tree" type="Tree" parent="VBoxContainer"]
45+
margin_top = 24.0
46+
margin_right = 1008.0
47+
margin_bottom = 556.0
48+
size_flags_vertical = 3
49+
allow_reselect = true
50+
51+
[connection signal="confirmed" from="." to="." method="_on_ConfirmationDialog_confirmed"]
52+
[connection signal="pressed" from="VBoxContainer/HBoxContainer/External" to="." method="_on_External_pressed"]
53+
[connection signal="item_double_clicked" from="VBoxContainer/Tree" to="." method="_on_Tree_item_double_clicked"]
54+
[connection signal="item_selected" from="VBoxContainer/Tree" to="." method="_on_Tree_item_selected"]

addons/event_system_plugin/nodes/event_manager/event_manager.gd

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export(bool) var start_on_ready:bool = false
1515

1616
var timeline
1717
var current_event
18+
var current_idx:int = -1
1819

1920
func _ready() -> void:
2021
if Engine.editor_hint:
@@ -37,23 +38,38 @@ func start_timeline(timeline_resource:Timeline=timeline) -> void:
3738

3839
func go_to_next_event() -> void:
3940
var event
40-
if not current_event:
41-
if not timeline:
42-
_notify_timeline_end()
43-
return
44-
event = timeline.get("event/0")
45-
else:
46-
event = current_event.get("next_event")
47-
if not event:
48-
_notify_timeline_end()
4941

42+
if current_event:
43+
if "next_event" in current_event and current_event["next_event"] != "":
44+
var data = current_event.get("next_event").split(";")
45+
current_idx = int(data[0])
46+
var new_timeline = ""
47+
if data.size() > 1:
48+
new_timeline = data[1]
49+
50+
if new_timeline != "":
51+
new_timeline = load(new_timeline) as Timeline
52+
if new_timeline:
53+
timeline = new_timeline
54+
else:
55+
current_idx += 1
56+
57+
if current_idx < 0:
58+
current_idx = 0
59+
60+
event = timeline.get("event/{idx}".format({"idx":current_idx}))
5061
current_event = event
5162

63+
if current_event == null:
64+
_notify_timeline_end()
65+
return
66+
5267
_execute_event(event)
5368

5469

5570
func _execute_event(event:Event) -> void:
5671
if event == null:
72+
assert(false)
5773
return
5874

5975
var node:Node = self if event_node_fallback_path == @"." else get_node(event_node_fallback_path)

addons/event_system_plugin/resources/event_class/event_class.gd

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ export(bool) var continue_at_end:bool = true setget _set_continue
2828

2929
var event_node_path:NodePath setget _set_event_node_path
3030

31-
var next_event:Resource setget set_next_event, get_next_event
32-
3331
# deprecated. Use get_event_node() instead
3432
var event_node
3533

@@ -80,25 +78,6 @@ func finish() -> void:
8078
func _execute() -> void:
8179
finish()
8280

83-
func set_next_event(event:Resource) -> void:
84-
if event:
85-
var other:Resource = event.get("next_event")
86-
if other == self:
87-
push_error("Can't cross reference events. Make a new event as pointer and use that instead.")
88-
next_event = null
89-
emit_changed()
90-
property_list_changed_notify()
91-
return
92-
93-
next_event = event
94-
emit_changed()
95-
property_list_changed_notify()
96-
97-
98-
99-
func get_next_event() -> Resource:
100-
return next_event
101-
10281

10382
func get_event_name() -> String:
10483
if event_name != resource_name and resource_name != "":

addons/event_system_plugin/resources/timeline_class/timeline_class.gd

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,6 @@ func _set(property:String, value) -> bool:
9999
else:
100100
_events.insert(event_idx, value)
101101

102-
var prev_idx:int = event_idx-1
103-
104-
if prev_idx > -1:
105-
var prev_ev:Resource = _events[prev_idx]
106-
var ev_next_pointer:Resource = null
107-
if prev_ev:
108-
ev_next_pointer = prev_ev.get("next_event")
109-
if not ev_next_pointer:
110-
prev_ev.set("next_event", value)
111102
has_property = true
112103
emit_changed()
113104

0 commit comments

Comments
 (0)