Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QuickFix for ConditionPicker #1079

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions addons/dialogic/Editor/Events/EventNode/EventNode.gd
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,14 @@ func build_editor():
editor_node.text = p.name

### --------------------------------------------------------------------
### 2. FILL THE NEW NODE WITH INFORMATION AND LISTEN TO CHANGES
### 2. ADD IT TO THE RIGHT PLACE (HEADER/BODY)
var location = %HeaderContent
if p.location == 1:
location = current_body_container
location.add_child(editor_node)

### --------------------------------------------------------------------
### 3. FILL THE NEW NODE WITH INFORMATION AND LISTEN TO CHANGES
if "event_resource" in editor_node:
editor_node.event_resource = resource
if 'property_name' in editor_node:
Expand All @@ -257,12 +264,6 @@ func build_editor():
edit_conditions_list.append([editor_node, p.condition])


### --------------------------------------------------------------------
### 3. ADD IT TO THE RIGHT PLACE (HEADER/BODY)
var location = %HeaderContent
if p.location == 1:
location = current_body_container
location.add_child(editor_node)
content_changed.connect(recalculate_edit_visibility.bind(edit_conditions_list))
recalculate_edit_visibility(edit_conditions_list)

Expand Down
2 changes: 2 additions & 0 deletions addons/dialogic/Editor/Events/Fields/ComplexPicker.gd
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ func _ready():
%Suggestions.item_selected.connect(suggestion_selected)
if resource_icon == null:
self.resource_icon = null
set_left_text('')
set_right_text('')


################################################################################
Expand Down
14 changes: 7 additions & 7 deletions addons/dialogic/Editor/Events/Fields/ConditionPicker.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ func _ready():
'background': Color('#1D1F25'),
'padding': [5, 5],
})
%OptionSelector.options = {'==':'==', '>':'>', '<':'<', '<=': '<=', '>=':'>=', '!=':'!='}
%Operator.options = {'==':'==', '>':'>', '<':'<', '<=': '<=', '>=':'>=', '!=':'!='}
%ToggleComplex.icon = get_theme_icon("Enum", "EditorIcons")

%Value1.resource_icon = get_theme_icon("ClassList", "EditorIcons")
%Value1.get_suggestions_func = [self, 'get_value1_suggestions']
%Value1.value_changed.connect(something_changed)

%Operator.item_selected.connect(something_changed)
%Operator.value_changed.connect(something_changed)

%Value2.resource_icon = get_theme_icon("Variant", "EditorIcons")
%Value2.get_suggestions_func = [self, 'get_value2_suggestions']
Expand Down Expand Up @@ -50,13 +50,13 @@ func something_changed(fake_arg1=null, fake_arg2 = null):
if %ComplexEditor.visible:
value_changed.emit(property_name, %ComplexEditor.text)
elif %SimpleEditor.visible:
value_changed.emit(property_name, simple2complex(%Value1.current_value, %Operator.get_item_text(%Operator.selected), %Value2.current_value))
value_changed.emit(property_name, simple2complex(%Value1.current_value, %Operator.get_value(), %Value2.current_value))

func is_too_complex(condition:String) -> bool:
return !condition.is_empty() and len(condition.split(' ', false)) != 3 or not condition.split(' ', false)[1] in %Operator.options
return !condition.is_empty() and len(condition.split(' ', false)) != 3

func complex2simple(condition:String) -> Array:
if is_too_complex(condition) or condition.is_empty():
if is_too_complex(condition) or condition.strip_edges().is_empty():
return ['', '==','']
return Array(condition.split(' ', false))

Expand All @@ -71,14 +71,14 @@ func _on_toggle_complex_toggled(button_pressed) -> void:
if button_pressed:
%ComplexEditor.show()
%SimpleEditor.hide()
%ComplexEditor.text = simple2complex(%Value1.current_value, %Operator.get_item_text(%Operator.selected), %Value2.current_value)
%ComplexEditor.text = simple2complex(%Value1.current_value, %Operator.get_value(), %Value2.current_value)
else:
if !is_too_complex(%ComplexEditor.text):
%ComplexEditor.hide()
%SimpleEditor.show()
var data = complex2simple(%ComplexEditor.text)
%Value1.set_value(data[0], data[0].trim_prefix("{").trim_suffix('}'))
%Operator.select(data[1].strip_edges())
%Operator.set_value(data[1].strip_edges())
%Value2.set_value(data[2], data[2].trim_prefix("{").trim_suffix('}'))

func _on_complex_editor_text_changed(new_text):
Expand Down
63 changes: 36 additions & 27 deletions addons/dialogic/Editor/Events/Fields/ConditionPicker.tscn
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
[gd_scene load_steps=6 format=3 uid="uid://ir6334lqtuwt"]
[gd_scene load_steps=8 format=3 uid="uid://ir6334lqtuwt"]

[ext_resource type="Theme" uid="uid://d3g4i4dshtdpu" path="res://addons/dialogic/Editor/Events/styles/InputFieldsStyle.tres" id="1_l2tpu"]
[ext_resource type="Script" path="res://addons/dialogic/Editor/Events/Fields/ConditionPicker.gd" id="1_q5p62"]
[ext_resource type="PackedScene" uid="uid://dpwhshre1n4t6" path="res://addons/dialogic/Editor/Events/Fields/ComplexPicker.tscn" id="1_rr7mq"]
[ext_resource type="PackedScene" uid="uid://d3bhehatwoio" path="res://addons/dialogic/Editor/Events/Fields/OptionSelector.tscn" id="4_27ir8"]

[sub_resource type="Image" id="Image_j4joa"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_jxa1q"]
content_margin_left = 5.0
content_margin_top = 5.0
content_margin_right = 5.0
content_margin_bottom = 5.0
bg_color = Color(0.113725, 0.121569, 0.145098, 1)
border_width_left = 1
border_width_top = 1
border_width_right = 1
border_width_bottom = 1
border_color = Color(0.0784314, 0.0862745, 0.101961, 1)
corner_radius_top_left = 3
corner_radius_top_right = 3
corner_radius_bottom_right = 3
corner_radius_bottom_left = 3

[sub_resource type="Image" id="Image_8s7rc"]
data = {
"data": PackedByteArray(255, 255, 255, 0, 255, 255, 255, 0, 255, 128, 128, 4, 255, 128, 128, 4, 255, 128, 128, 4, 255, 128, 128, 4, 255, 128, 128, 4, 255, 128, 128, 4, 255, 128, 128, 4, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 131, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 131, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 131, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 252, 255, 93, 93, 252, 255, 93, 93, 252, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 128, 128, 4, 255, 128, 128, 4, 255, 128, 128, 4, 255, 128, 128, 4, 255, 128, 128, 4, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 231, 255, 93, 93, 55, 255, 97, 97, 58, 255, 93, 93, 233, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 231, 255, 94, 94, 54, 255, 94, 94, 57, 255, 93, 93, 233, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 93, 93, 233, 255, 93, 93, 232, 255, 93, 93, 41, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 93, 93, 233, 255, 93, 93, 232, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 97, 97, 42, 255, 255, 255, 0, 255, 97, 97, 42, 255, 97, 97, 42, 255, 255, 255, 0, 255, 98, 98, 47, 255, 97, 97, 42, 255, 255, 255, 0, 255, 97, 97, 42, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 235, 255, 93, 93, 233, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 94, 94, 46, 255, 93, 93, 236, 255, 93, 93, 233, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 235, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 233, 255, 95, 95, 59, 255, 96, 96, 61, 255, 93, 93, 235, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 233, 255, 95, 95, 59, 255, 96, 96, 61, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 252, 255, 93, 93, 252, 255, 93, 93, 252, 255, 93, 93, 252, 255, 93, 93, 252, 255, 93, 93, 252, 255, 93, 93, 252, 255, 93, 93, 252, 255, 93, 93, 252, 255, 93, 93, 252, 255, 93, 93, 252, 255, 93, 93, 252, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0),
"format": "RGBA8",
Expand All @@ -14,7 +31,7 @@ data = {
}

[sub_resource type="ImageTexture" id="ImageTexture_ufu73"]
image = SubResource("Image_j4joa")
image = SubResource("Image_8s7rc")

[node name="ConditionPicker" type="HBoxContainer"]
offset_right = 77.0
Expand All @@ -30,8 +47,9 @@ offset_bottom = 28.0
[node name="SimpleEditor" type="HBoxContainer" parent="."]
unique_name_in_owner = true
offset_left = 5.0
offset_right = 475.0
offset_right = 468.0
offset_bottom = 33.0
theme_override_constants/separation = 0

[node name="Value1" parent="SimpleEditor" instance=ExtResource("1_rr7mq")]
unique_name_in_owner = true
Expand All @@ -41,32 +59,20 @@ offset_right = 200.0
offset_bottom = 33.0
disable_pretty_name = true

[node name="Operator" type="OptionButton" parent="SimpleEditor"]
[node name="Operator" parent="SimpleEditor" instance=ExtResource("4_27ir8")]
unique_name_in_owner = true
offset_left = 204.0
offset_right = 266.0
anchor_right = 0.0
anchor_bottom = 0.0
offset_left = 200.0
offset_right = 263.0
offset_bottom = 33.0
item_count = 6
selected = 0
popup/item_0/text = "=="
popup/item_0/id = 0
popup/item_1/text = ">"
popup/item_1/id = 1
popup/item_2/text = "<"
popup/item_2/id = 2
popup/item_3/text = "<="
popup/item_3/id = 3
popup/item_4/text = ">="
popup/item_4/id = 4
popup/item_5/text = "not =="
popup/item_5/id = 5

[node name="Value2" parent="SimpleEditor" instance=ExtResource("1_rr7mq")]
unique_name_in_owner = true
anchor_right = 0.0
anchor_bottom = 0.0
offset_left = 270.0
offset_right = 470.0
offset_left = 263.0
offset_right = 463.0
offset_bottom = 33.0
disable_pretty_name = true

Expand All @@ -78,22 +84,25 @@ offset_left = 479.0
offset_right = 986.0
offset_bottom = 33.0
mouse_filter = 1
theme_override_styles/normal = SubResource("StyleBoxFlat_jxa1q")
theme_override_styles/focus = SubResource("StyleBoxFlat_jxa1q")
theme_override_styles/read_only = SubResource("StyleBoxFlat_jxa1q")
text = "VAR.Player.Health > 20 and VAR.Counter < 3 and randi()%3 == 2"
placeholder_text = "Enter condition"
expand_to_text_length = true

[node name="ToggleComplex" type="Button" parent="."]
unique_name_in_owner = true
offset_left = 479.0
offset_right = 503.0
offset_left = 472.0
offset_right = 496.0
offset_bottom = 33.0
toggle_mode = true
icon = SubResource("ImageTexture_ufu73")

[node name="RightText" type="Label" parent="."]
offset_left = 507.0
offset_left = 500.0
offset_top = 5.0
offset_right = 508.0
offset_right = 501.0
offset_bottom = 28.0

[connection signal="text_changed" from="ComplexEditor" to="." method="_on_complex_editor_text_changed"]
Expand Down
4 changes: 4 additions & 0 deletions addons/dialogic/Editor/Events/Fields/OptionSelector.gd
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func _ready():
})
$MenuButton.about_to_popup.connect(insert_options)
$MenuButton.get_popup().index_pressed.connect(index_pressed)
set_left_text('')
set_right_text('')
# TODOT godot4 figure this out (popup background panel style)
# $MenuButton.get_popup().add_theme_stylebox_override('panel', load("res://addons/dialogic/Editor/Events/styles/ResourceMenuPanelBackground.tres"))

Expand All @@ -38,6 +40,8 @@ func set_value(value):
if options[element] == value:
$MenuButton.text = element

func get_value():
return $MenuButton.text

func insert_options():
$MenuButton.get_popup().clear()
Expand Down