Skip to content

Commit 1a709de

Browse files
Add Save Event Options (#568)
You can now decide to use a custom slot. This can also be a variable.
1 parent c41ecf6 commit 1a709de

File tree

4 files changed

+104
-8
lines changed

4 files changed

+104
-8
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
tool
2+
extends "res://addons/dialogic/Editor/Events/Parts/EventPart.gd"
3+
4+
# has an event_data variable that stores the current data!!!
5+
6+
## node references
7+
onready var default_slot = $DefaultSlot
8+
onready var custom_slot = $CustomSlot
9+
10+
# used to connect the signals
11+
func _ready():
12+
default_slot.connect("toggled", self, "_on_DefaultSlot_toggled")
13+
custom_slot.connect("text_changed", self, '_on_CustomSlot_text_changed')
14+
15+
16+
# called by the event block
17+
func load_data(data:Dictionary):
18+
# First set the event_data
19+
.load_data(data)
20+
21+
# Now update the ui nodes to display the data.
22+
default_slot.pressed = event_data.get('use_default_slot', true)
23+
custom_slot.text = event_data.get('custom_slot', '')
24+
25+
custom_slot.visible = not default_slot.pressed
26+
$Label.visible = not default_slot.pressed
27+
28+
29+
func _on_DefaultSlot_toggled(pressed):
30+
event_data['use_default_slot'] = pressed
31+
32+
custom_slot.visible = not pressed
33+
$Label.visible = not pressed
34+
35+
# informs the parent about the changes!
36+
data_changed()
37+
38+
func _on_CustomSlot_text_changed(text):
39+
event_data['custom_slot'] = text
40+
41+
# informs the parent about the changes!
42+
data_changed()
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[gd_scene load_steps=3 format=2]
2+
3+
[ext_resource path="res://addons/dialogic/Editor/Events/Parts/Text/CustomLineEdit.tscn" type="PackedScene" id=1]
4+
[ext_resource path="res://addons/dialogic/Editor/Events/Parts/Logic/EventPart_Save.gd" type="Script" id=2]
5+
6+
[node name="EventPart_Save" type="HBoxContainer"]
7+
margin_right = 40.0
8+
margin_bottom = 40.0
9+
custom_constants/separation = 9
10+
script = ExtResource( 2 )
11+
__meta__ = {
12+
"_edit_use_anchors_": false
13+
}
14+
15+
[node name="DefaultSlot" type="CheckBox" parent="."]
16+
margin_right = 129.0
17+
margin_bottom = 40.0
18+
pressed = true
19+
text = "Use default slot"
20+
21+
[node name="Label" type="Label" parent="."]
22+
margin_left = 138.0
23+
margin_top = 13.0
24+
margin_right = 219.0
25+
margin_bottom = 27.0
26+
text = "Custom slot:"
27+
__meta__ = {
28+
"_edit_use_anchors_": false
29+
}
30+
31+
[node name="CustomSlot" parent="." instance=ExtResource( 1 )]
32+
margin_left = 228.0
33+
margin_top = 6.0
34+
margin_right = 276.0
35+
margin_bottom = 33.0
36+
hint_tooltip = "Also allows for value definitions like this: [my_value_name]"

addons/dialogic/Editor/Events/SaveEvent.tscn

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
[gd_scene load_steps=6 format=2]
1+
[gd_scene load_steps=7 format=2]
22

33
[ext_resource path="res://addons/dialogic/Editor/Events/Templates/EventTemplate.tscn" type="PackedScene" id=1]
44
[ext_resource path="res://addons/dialogic/Images/Event Icons/Main Icons/save-icon.svg" type="Texture" id=2]
5+
[ext_resource path="res://addons/dialogic/Editor/Events/Parts/Logic/EventPart_Save.tscn" type="PackedScene" id=3]
56
[ext_resource path="res://addons/dialogic/Editor/Events/styles/Timeline.tres" type="StyleBox" id=4]
67

7-
[sub_resource type="Image" id=5]
8+
[sub_resource type="Image" id=3]
89
data = {
910
"data": PoolByteArray( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
1011
"format": "LumAlpha8",
@@ -13,19 +14,22 @@ data = {
1314
"width": 16
1415
}
1516

16-
[sub_resource type="ImageTexture" id=4]
17+
[sub_resource type="ImageTexture" id=2]
1718
flags = 4
1819
flags = 4
19-
image = SubResource( 5 )
20+
image = SubResource( 3 )
2021
size = Vector2( 16, 16 )
2122

2223
[node name="SaveEvent" instance=ExtResource( 1 )]
2324
event_name = "Save"
2425
event_data = {
25-
"event_id": "dialogic_026"
26+
"custom_slot": "",
27+
"event_id": "dialogic_026",
28+
"use_default_slot": true
2629
}
2730
event_icon = ExtResource( 2 )
2831
event_style = ExtResource( 4 )
32+
header_scene = ExtResource( 3 )
2933
expand_on_default = false
3034
help_page_path = "res://addons/dialogic/Documentation/Content/Tutorials/Saving.md"
3135

@@ -52,7 +56,7 @@ margin_right = 91.0
5256
margin_left = 101.0
5357

5458
[node name="HelpButton" parent="PanelContainer/MarginContainer/VBoxContainer/Header" index="6"]
55-
icon = SubResource( 4 )
59+
icon = SubResource( 2 )
5660

5761
[node name="OptionsControl" parent="PanelContainer/MarginContainer/VBoxContainer/Header" index="7"]
5862
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, "", false, "Remove", null, 0, false, false, 3, 0, null, "", false ]

addons/dialogic/Nodes/DialogNode.gd

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -966,10 +966,24 @@ func event_handler(event: Dictionary):
966966
# Save event
967967
'dialogic_026':
968968
emit_signal('event_start', 'save', event)
969-
Dialogic.save()
969+
var custom_slot :String = event.get('custom_slot', '').strip_edges()
970+
if event.get('use_default_slot', true) or custom_slot == '':
971+
Dialogic.save()
972+
else:
973+
if custom_slot.begins_with("[") and custom_slot.ends_with("]"):
974+
custom_slot = custom_slot.trim_prefix("[").trim_suffix("]")
975+
var saved = false
976+
for definition in definitions['variables']:
977+
if definition['name'] == custom_slot:
978+
Dialogic.save(definition['value'])
979+
saved = true
980+
if not saved:
981+
print("[D] Tried to access value definition '"+custom_slot+"' for saving, but it didn't exist.")
982+
else:
983+
Dialogic.save(custom_slot)
984+
970985
_load_next_event()
971986

972-
973987
# AUDIO EVENTS
974988
# Audio event
975989
'dialogic_030':

0 commit comments

Comments
 (0)