Skip to content

Commit

Permalink
Add Save Event Options (#568)
Browse files Browse the repository at this point in the history
You can now decide to use a custom slot. This can also be a variable.
  • Loading branch information
Jowan-Spooner authored Oct 7, 2021
1 parent c41ecf6 commit 1a709de
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 8 deletions.
42 changes: 42 additions & 0 deletions addons/dialogic/Editor/Events/Parts/Logic/EventPart_Save.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
tool
extends "res://addons/dialogic/Editor/Events/Parts/EventPart.gd"

# has an event_data variable that stores the current data!!!

## node references
onready var default_slot = $DefaultSlot
onready var custom_slot = $CustomSlot

# used to connect the signals
func _ready():
default_slot.connect("toggled", self, "_on_DefaultSlot_toggled")
custom_slot.connect("text_changed", self, '_on_CustomSlot_text_changed')


# called by the event block
func load_data(data:Dictionary):
# First set the event_data
.load_data(data)

# Now update the ui nodes to display the data.
default_slot.pressed = event_data.get('use_default_slot', true)
custom_slot.text = event_data.get('custom_slot', '')

custom_slot.visible = not default_slot.pressed
$Label.visible = not default_slot.pressed


func _on_DefaultSlot_toggled(pressed):
event_data['use_default_slot'] = pressed

custom_slot.visible = not pressed
$Label.visible = not pressed

# informs the parent about the changes!
data_changed()

func _on_CustomSlot_text_changed(text):
event_data['custom_slot'] = text

# informs the parent about the changes!
data_changed()
36 changes: 36 additions & 0 deletions addons/dialogic/Editor/Events/Parts/Logic/EventPart_Save.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[gd_scene load_steps=3 format=2]

[ext_resource path="res://addons/dialogic/Editor/Events/Parts/Text/CustomLineEdit.tscn" type="PackedScene" id=1]
[ext_resource path="res://addons/dialogic/Editor/Events/Parts/Logic/EventPart_Save.gd" type="Script" id=2]

[node name="EventPart_Save" type="HBoxContainer"]
margin_right = 40.0
margin_bottom = 40.0
custom_constants/separation = 9
script = ExtResource( 2 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="DefaultSlot" type="CheckBox" parent="."]
margin_right = 129.0
margin_bottom = 40.0
pressed = true
text = "Use default slot"

[node name="Label" type="Label" parent="."]
margin_left = 138.0
margin_top = 13.0
margin_right = 219.0
margin_bottom = 27.0
text = "Custom slot:"
__meta__ = {
"_edit_use_anchors_": false
}

[node name="CustomSlot" parent="." instance=ExtResource( 1 )]
margin_left = 228.0
margin_top = 6.0
margin_right = 276.0
margin_bottom = 33.0
hint_tooltip = "Also allows for value definitions like this: [my_value_name]"
16 changes: 10 additions & 6 deletions addons/dialogic/Editor/Events/SaveEvent.tscn
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[gd_scene load_steps=6 format=2]
[gd_scene load_steps=7 format=2]

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

[sub_resource type="Image" id=5]
[sub_resource type="Image" id=3]
data = {
"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, 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 ),
"format": "LumAlpha8",
Expand All @@ -13,19 +14,22 @@ data = {
"width": 16
}

[sub_resource type="ImageTexture" id=4]
[sub_resource type="ImageTexture" id=2]
flags = 4
flags = 4
image = SubResource( 5 )
image = SubResource( 3 )
size = Vector2( 16, 16 )

[node name="SaveEvent" instance=ExtResource( 1 )]
event_name = "Save"
event_data = {
"event_id": "dialogic_026"
"custom_slot": "",
"event_id": "dialogic_026",
"use_default_slot": true
}
event_icon = ExtResource( 2 )
event_style = ExtResource( 4 )
header_scene = ExtResource( 3 )
expand_on_default = false
help_page_path = "res://addons/dialogic/Documentation/Content/Tutorials/Saving.md"

Expand All @@ -52,7 +56,7 @@ margin_right = 91.0
margin_left = 101.0

[node name="HelpButton" parent="PanelContainer/MarginContainer/VBoxContainer/Header" index="6"]
icon = SubResource( 4 )
icon = SubResource( 2 )

[node name="OptionsControl" parent="PanelContainer/MarginContainer/VBoxContainer/Header" index="7"]
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 ]
18 changes: 16 additions & 2 deletions addons/dialogic/Nodes/DialogNode.gd
Original file line number Diff line number Diff line change
Expand Up @@ -966,10 +966,24 @@ func event_handler(event: Dictionary):
# Save event
'dialogic_026':
emit_signal('event_start', 'save', event)
Dialogic.save()
var custom_slot :String = event.get('custom_slot', '').strip_edges()
if event.get('use_default_slot', true) or custom_slot == '':
Dialogic.save()
else:
if custom_slot.begins_with("[") and custom_slot.ends_with("]"):
custom_slot = custom_slot.trim_prefix("[").trim_suffix("]")
var saved = false
for definition in definitions['variables']:
if definition['name'] == custom_slot:
Dialogic.save(definition['value'])
saved = true
if not saved:
print("[D] Tried to access value definition '"+custom_slot+"' for saving, but it didn't exist.")
else:
Dialogic.save(custom_slot)

_load_next_event()


# AUDIO EVENTS
# Audio event
'dialogic_030':
Expand Down

0 comments on commit 1a709de

Please sign in to comment.