Skip to content

Commit

Permalink
Added Condition functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
nagidev committed Feb 13, 2022
1 parent d50a9b5 commit 29cdea6
Show file tree
Hide file tree
Showing 13 changed files with 239 additions and 97 deletions.
6 changes: 3 additions & 3 deletions addons/dialogue_nodes/NodeEditor.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ margin_right = 114.0
margin_bottom = 22.0
keep_pressed_outside = true
text = "Add Node"
items = [ "StartNode", null, 0, false, false, 0, 0, null, "", false, "DialogueNode", null, 0, false, false, 1, 0, null, "", false, "CommentNode", null, 0, false, false, 2, 0, null, "", false, "SignalNode", null, 0, false, false, 3, 0, null, "", false, "SetNode", null, 0, false, false, 4, 0, null, "", false ]
items = [ "StartNode", null, 0, false, false, 0, 0, null, "", false, "DialogueNode", null, 0, false, false, 1, 0, null, "", false, "CommentNode", null, 0, false, false, 2, 0, null, "", false, "SignalNode", null, 0, false, false, 3, 0, null, "", false, "SetNode", null, 0, false, false, 4, 0, null, "", false, "ConditionNode", null, 0, false, false, 5, 0, null, "", false ]
switch_on_hover = true

[node name="RunMenu" type="MenuButton" parent="Main/ToolBar"]
Expand All @@ -76,7 +76,7 @@ script = ExtResource( 7 )
__meta__ = {
"_edit_use_anchors_": false
}
nodeScenes = [ "res://addons/dialogue_nodes/nodes/StartNode.tscn", "res://addons/dialogue_nodes/nodes/DialogueNode.tscn", "res://addons/dialogue_nodes/nodes/CommentNode.tscn", "res://addons/dialogue_nodes/nodes/SignalNode.tscn", "res://addons/dialogue_nodes/nodes/SetNode.tscn" ]
nodeScenes = [ "res://addons/dialogue_nodes/nodes/StartNode.tscn", "res://addons/dialogue_nodes/nodes/DialogueNode.tscn", "res://addons/dialogue_nodes/nodes/CommentNode.tscn", "res://addons/dialogue_nodes/nodes/SignalNode.tscn", "res://addons/dialogue_nodes/nodes/SetNode.tscn", "res://addons/dialogue_nodes/nodes/ConditionNode.tscn" ]

[node name="SidePanel" type="VSplitContainer" parent="Main/Workspace"]
margin_right = 1016.0
Expand Down Expand Up @@ -134,7 +134,7 @@ __meta__ = {
[node name="PopupMenu" type="PopupMenu" parent="Main/Workspace/Graph"]
margin_right = 16.0
margin_bottom = 16.0
items = [ "StartNode", null, 0, false, false, 0, 0, null, "", false, "DialogueNode", null, 0, false, false, 1, 0, null, "", false, "CommentNode", null, 0, false, false, 2, 0, null, "", false, "SignalNode", null, 0, false, false, 3, 0, null, "", false, "SetNode", null, 0, false, false, 4, 0, null, "", false ]
items = [ "StartNode", null, 0, false, false, 0, 0, null, "", false, "DialogueNode", null, 0, false, false, 1, 0, null, "", false, "CommentNode", null, 0, false, false, 2, 0, null, "", false, "SignalNode", null, 0, false, false, 3, 0, null, "", false, "SetNode", null, 0, false, false, 4, 0, null, "", false, "ConditionNode", null, 0, false, false, 5, 0, null, "", false ]
allow_search = true
__meta__ = {
"_edit_use_anchors_": false
Expand Down
80 changes: 80 additions & 0 deletions addons/dialogue_nodes/nodes/ConditionNode.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
[gd_scene load_steps=2 format=2]

[ext_resource path="res://addons/dialogue_nodes/nodes/conditionNode.gd" type="Script" id=1]

[node name="ConditionNode" type="GraphNode"]
margin_right = 240.0
margin_bottom = 110.0
title = "ConditionNode"
show_close = true
slot/0/left_enabled = true
slot/0/left_type = 0
slot/0/left_color = Color( 1, 1, 1, 1 )
slot/0/right_enabled = false
slot/0/right_type = 0
slot/0/right_color = Color( 1, 1, 1, 1 )
slot/1/left_enabled = false
slot/1/left_type = 0
slot/1/left_color = Color( 1, 1, 1, 1 )
slot/1/right_enabled = true
slot/1/right_type = 0
slot/1/right_color = Color( 0.647059, 0.937255, 0.67451, 1 )
slot/2/left_enabled = false
slot/2/left_type = 0
slot/2/left_color = Color( 1, 1, 1, 1 )
slot/2/right_enabled = true
slot/2/right_type = 0
slot/2/right_color = Color( 1, 0.364706, 0.364706, 1 )
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="HBoxContainer" type="HBoxContainer" parent="."]
margin_left = 16.0
margin_top = 24.0
margin_right = 224.0
margin_bottom = 48.0

[node name="Value1" type="LineEdit" parent="HBoxContainer"]
margin_right = 77.0
margin_bottom = 24.0
hint_tooltip = "The property to set the value of."
size_flags_horizontal = 3
placeholder_text = "Value"

[node name="Operator" type="OptionButton" parent="HBoxContainer"]
margin_left = 81.0
margin_right = 126.0
margin_bottom = 24.0
hint_tooltip = "The type of the value to set."
text = "=="
items = [ "==", null, false, 0, null, "!=", null, false, 1, null, ">", null, false, 2, null, "<", null, false, 3, null, ">=", null, false, 4, null, "<=", null, false, 5, null ]
selected = 0

[node name="Value2" type="LineEdit" parent="HBoxContainer"]
margin_left = 130.0
margin_right = 208.0
margin_bottom = 24.0
hint_tooltip = "The value to set the property to.
Eg: Bob, 12, 0.5, false, etc."
size_flags_horizontal = 3
placeholder_text = "Value"

[node name="TrueLabel" type="ItemList" parent="."]
margin_left = 16.0
margin_top = 49.0
margin_right = 224.0
margin_bottom = 76.0
mouse_filter = 2
items = [ "True", null, false ]
auto_height = true

[node name="FalseLabel" type="ItemList" parent="."]
margin_left = 16.0
margin_top = 77.0
margin_right = 224.0
margin_bottom = 104.0
mouse_filter = 2
items = [ "False", null, false ]
auto_height = true
88 changes: 22 additions & 66 deletions addons/dialogue_nodes/nodes/SetNode.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -3,96 +3,52 @@
[ext_resource path="res://addons/dialogue_nodes/nodes/setNode.gd" type="Script" id=1]

[node name="SetNode" type="GraphNode"]
margin_right = 160.0
margin_bottom = 100.0
title = "Set Value"
margin_right = 240.0
margin_bottom = 60.0
title = "SetNode"
show_close = true
slot/0/left_enabled = true
slot/0/left_type = 0
slot/0/left_color = Color( 1, 1, 1, 1 )
slot/0/right_enabled = true
slot/0/right_type = 0
slot/0/right_color = Color( 1, 1, 1, 1 )
slot/1/left_enabled = false
slot/1/left_type = 0
slot/1/left_color = Color( 1, 1, 1, 1 )
slot/1/right_enabled = false
slot/1/right_type = 0
slot/1/right_color = Color( 1, 1, 1, 1 )
slot/2/left_enabled = false
slot/2/left_type = 0
slot/2/left_color = Color( 1, 1, 1, 1 )
slot/2/right_enabled = false
slot/2/right_type = 0
slot/2/right_color = Color( 1, 1, 1, 1 )
slot/3/left_enabled = false
slot/3/left_type = 0
slot/3/left_color = Color( 1, 1, 1, 1 )
slot/3/right_enabled = false
slot/3/right_type = 0
slot/3/right_color = Color( 1, 1, 1, 1 )
slot/4/left_enabled = false
slot/4/left_type = 0
slot/4/left_color = Color( 1, 1, 1, 1 )
slot/4/right_enabled = false
slot/4/right_type = 0
slot/4/right_color = Color( 1, 1, 1, 1 )
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="VariableLabel" type="Label" parent="."]
[node name="HBoxContainer" type="HBoxContainer" parent="."]
margin_left = 16.0
margin_top = 24.0
margin_right = 144.0
margin_bottom = 38.0
text = "Variable"
margin_right = 224.0
margin_bottom = 48.0

[node name="Variable" type="LineEdit" parent="."]
margin_left = 16.0
margin_top = 39.0
margin_right = 144.0
margin_bottom = 63.0
[node name="Variable" type="LineEdit" parent="HBoxContainer"]
margin_right = 81.0
margin_bottom = 24.0
hint_tooltip = "The property to set the value of."

[node name="HBoxContainer" type="HBoxContainer" parent="."]
margin_left = 16.0
margin_top = 64.0
margin_right = 144.0
margin_bottom = 84.0

[node name="OperatorLabel" type="Label" parent="HBoxContainer"]
margin_top = 3.0
margin_right = 61.0
margin_bottom = 17.0
text = "Operator "
size_flags_horizontal = 3
placeholder_text = "Variable"

[node name="Type" type="OptionButton" parent="HBoxContainer"]
margin_left = 65.0
margin_right = 128.0
margin_bottom = 20.0
margin_left = 85.0
margin_right = 122.0
margin_bottom = 24.0
hint_tooltip = "The type of the value to set."
size_flags_horizontal = 3
text = "="
items = [ "=", null, false, 0, null, "+=", null, false, 1, null, "-=", null, false, 2, null, "*=", null, false, 3, null, "/=", null, false, 4, null ]
selected = 0

[node name="ValueLabel" type="Label" parent="."]
margin_left = 16.0
margin_top = 85.0
margin_right = 144.0
margin_bottom = 99.0
text = "Value:"

[node name="Value" type="LineEdit" parent="."]
margin_left = 16.0
margin_top = 100.0
margin_right = 144.0
margin_bottom = 124.0
[node name="Value" type="LineEdit" parent="HBoxContainer"]
margin_left = 126.0
margin_right = 208.0
margin_bottom = 24.0
hint_tooltip = "The value to set the property to.
Eg: Bob, 12, 0.5, false, etc."
size_flags_horizontal = 3
placeholder_text = "Value"

[connection signal="text_changed" from="Variable" to="." method="set_variable"]
[connection signal="text_changed" from="HBoxContainer/Variable" to="." method="set_variable"]
[connection signal="item_selected" from="HBoxContainer/Type" to="." method="set_type"]
[connection signal="text_changed" from="Value" to="." method="set_value"]
[connection signal="text_changed" from="HBoxContainer/Value" to="." method="set_value"]
24 changes: 6 additions & 18 deletions addons/dialogue_nodes/nodes/SignalNode.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
[ext_resource path="res://addons/dialogue_nodes/nodes/signalNode.gd" type="Script" id=1]

[node name="SignalNode" type="GraphNode"]
margin_right = 160.0
margin_bottom = 80.0
margin_right = 200.0
margin_bottom = 60.0
title = "Signal"
show_close = true
slot/0/left_enabled = true
Expand All @@ -13,29 +13,17 @@ slot/0/left_color = Color( 1, 1, 1, 1 )
slot/0/right_enabled = true
slot/0/right_type = 0
slot/0/right_color = Color( 1, 1, 1, 1 )
slot/1/left_enabled = false
slot/1/left_type = 0
slot/1/left_color = Color( 1, 1, 1, 1 )
slot/1/right_enabled = false
slot/1/right_type = 0
slot/1/right_color = Color( 1, 1, 1, 1 )
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Label" type="Label" parent="."]
margin_left = 16.0
margin_top = 24.0
margin_right = 144.0
margin_bottom = 38.0
text = "Value:"

[node name="SignalValue" type="LineEdit" parent="."]
margin_left = 16.0
margin_top = 39.0
margin_right = 144.0
margin_bottom = 63.0
margin_top = 24.0
margin_right = 184.0
margin_bottom = 48.0
hint_tooltip = "The String value passed in the signal parameter."
placeholder_text = "Value"

[connection signal="text_changed" from="SignalValue" to="." method="_on_node_modified"]
53 changes: 53 additions & 0 deletions addons/dialogue_nodes/nodes/conditionNode.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
tool
extends GraphNode

enum {EQUAL, NEQUAL, GREATER, LESS, GEQUAL, LEQUAL}

signal modified

onready var value1 = $HBoxContainer/Value1
onready var operator = $HBoxContainer/Operator
onready var value2 = $HBoxContainer/Value2

onready var trueLabel = $TrueLabel
onready var falseLabel = $FalseLabel


func _to_dict(graph):
var dict = {}
dict['value1'] = value1.text
dict['operator'] = operator.selected
dict['value2'] = value2.text

dict['true'] = 'END'
dict['false'] = 'END'

for connection in graph.get_connection_list():
if connection['from'] == name:
if connection['from_port'] == 0:
dict['true'] = connection['to']
elif connection['from_port'] == 1:
dict['false'] = connection['to']

return dict


func _from_dict(_graph, dict):
value1.text = dict['value1']
operator.selected = dict['operator']
value2.text = dict['value2']


return [dict['true'], dict['false']]


func set_type(_new_type):
_on_modified()


func set_value(_new_val):
_on_modified()


func _on_modified():
emit_signal("modified")
6 changes: 3 additions & 3 deletions addons/dialogue_nodes/nodes/setNode.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ enum {STRING, INT, FLOAT, BOOL}

signal modified

onready var variable = $Variable
onready var variable = $HBoxContainer/Variable
onready var type = $HBoxContainer/Type
onready var value = $Value
onready var value = $HBoxContainer/Value


func _to_dict(graph):
Expand All @@ -19,7 +19,7 @@ func _to_dict(graph):
var next_nodes = graph.get_next(name)

if len(next_nodes) > 0:
dict['link'] = graph.get_next(name)[0]
dict['link'] = next_nodes[0]
else:
dict['link'] = 'END'

Expand Down
2 changes: 1 addition & 1 deletion addons/dialogue_nodes/nodes/signalNode.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func _to_dict(graph):
var next_nodes = graph.get_next(name)

if len(next_nodes) > 0:
dict['link'] = graph.get_next(name)[0]
dict['link'] = next_nodes[0]
else:
dict['link'] = 'END'

Expand Down
Loading

0 comments on commit 29cdea6

Please sign in to comment.