From 7300bdc573c2da157aef44076f8126d7dcdc7587 Mon Sep 17 00:00:00 2001 From: Jowan-Spooner Date: Thu, 11 Jan 2024 11:45:14 +0100 Subject: [PATCH] Fix boolean condition not saving the bool state --- .../Editor/Events/Fields/field_bool_check.gd | 2 +- .../Editor/Events/Fields/field_condition.gd | 56 ++++++++++--------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/addons/dialogic/Editor/Events/Fields/field_bool_check.gd b/addons/dialogic/Editor/Events/Fields/field_bool_check.gd index 98cfd32df..d01a1163d 100644 --- a/addons/dialogic/Editor/Events/Fields/field_bool_check.gd +++ b/addons/dialogic/Editor/Events/Fields/field_bool_check.gd @@ -16,7 +16,7 @@ func _load_display_info(info:Dictionary) -> void: func _set_value(value:Variant) -> void: match DialogicUtil.get_variable_value_type(value): DialogicUtil.VarTypes.STRING: - self.button_pressed = value and not value == "false" + self.button_pressed = value and not value.strip_edges() == "false" _: self.button_pressed = value and true #endregion diff --git a/addons/dialogic/Editor/Events/Fields/field_condition.gd b/addons/dialogic/Editor/Events/Fields/field_condition.gd index cf547a1fe..767e4c5da 100644 --- a/addons/dialogic/Editor/Events/Fields/field_condition.gd +++ b/addons/dialogic/Editor/Events/Fields/field_condition.gd @@ -6,7 +6,6 @@ extends DialogicVisualEditorField var _current_value1 :Variant = "" var _current_value2 :Variant = "" - #region MAIN METHODS ################################################################################ @@ -21,6 +20,7 @@ func _set_value(value:Variant) -> void: load_simple_editor(value) + func _autofocus(): %Value1Variable.grab_focus() @@ -63,6 +63,8 @@ func _ready() -> void: %Value2Number.value_changed.connect(something_changed) %Value1Text.value_changed.connect(something_changed) %Value2Text.value_changed.connect(something_changed) + %Value1Bool.value_changed.connect(something_changed) + %Value2Bool.value_changed.connect(something_changed) %ToggleComplex.icon = get_theme_icon("Enum", "EditorIcons") @@ -77,7 +79,6 @@ func _ready() -> void: ] - func load_simple_editor(condition_string:String) -> void: var data := complex2simple(condition_string) %Value1Type.set_value(get_value_type(data[0], 2)) @@ -150,34 +151,41 @@ func trim_value(value:Variant, value_type:int) -> String: match value_type: 0: return value.trim_prefix('"').trim_suffix('"').replace('\\"', '"') 2: return value.trim_prefix('{').trim_suffix('}') - 3: return "true" if value else "false" + 3: + if value == "true" or (value and (typeof(value) != TYPE_STRING or value != "false")): + return "true" + else: + return "false" _: return value func something_changed(fake_arg1=null, fake_arg2 = null): if %ComplexEditor.visible: value_changed.emit(property_name, %ComplexEditor.text) + return + + + match %Value1Type.current_value: + 0: _current_value1 = prep_value(%Value1Text.text, %Value1Type.current_value) + 1: _current_value1 = str(%Value1Number.get_value()) + 2: _current_value1 = prep_value(%Value1Variable.current_value, %Value1Type.current_value) + 3: _current_value1 = prep_value(%Value1Bool.button_pressed, %Value1Type.current_value) + _: _current_value1 = prep_value(%Value1Text.text, %Value1Type.current_value) + + match %Value2Type.current_value: + 0: _current_value2 = prep_value(%Value2Text.text, %Value2Type.current_value) + 1: _current_value2 = str(%Value2Number.get_value()) + 2: _current_value2 = prep_value(%Value2Variable.current_value, %Value2Type.current_value) + 3: _current_value2 = prep_value(%Value2Bool.button_pressed, %Value2Type.current_value) + _: _current_value2 = prep_value(%Value2Text.text, %Value2Type.current_value) + + if event_resource: + if not %Operator.text in ['==', '!='] and get_value_type(_current_value2, 0) in [0, 3]: + event_resource.ui_update_warning.emit("This operator doesn't work with strings and booleans.") + else: + event_resource.ui_update_warning.emit("") - else: - match %Value1Type.current_value: - 0: _current_value1 = prep_value(%Value1Text.text, %Value1Type.current_value) - 1: _current_value1 = str(%Value1Number.get_value()) - 2: _current_value1 = prep_value(%Value1Variable.current_value, %Value1Type.current_value) - _: _current_value1 = prep_value(%Value1Text.text, %Value1Type.current_value) - - match %Value2Type.current_value: - 0: _current_value2 = prep_value(%Value2Text.text, %Value2Type.current_value) - 1: _current_value2 = str(%Value2Number.get_value()) - 2: _current_value2 = prep_value(%Value2Variable.current_value, %Value2Type.current_value) - _: _current_value2 = prep_value(%Value2Text.text, %Value2Type.current_value) - - if event_resource: - if not %Operator.text in ['==', '!='] and get_value_type(_current_value2, 0) in [0, 3]: - event_resource.ui_update_warning.emit("This operator doesn't work with strings and booleans.") - else: - event_resource.ui_update_warning.emit("") - - value_changed.emit(property_name, get_simple_condition()) + value_changed.emit(property_name, get_simple_condition()) func is_too_complex(condition:String) -> bool: @@ -237,7 +245,6 @@ func get_variable_suggestions(filter:String) -> Dictionary: func _on_value_1_variable_value_changed(property_name: Variant, value: Variant) -> void: var type := DialogicUtil.get_variable_type(value) - print(get_value_type(_current_value2, -1)) match type: DialogicUtil.VarTypes.BOOL: if not %Operator.text in ["==", "!="]: @@ -252,7 +259,6 @@ func _on_value_1_variable_value_changed(property_name: Variant, value: Variant) %Value2Type.insert_options() %Value2Type.index_pressed(0) DialogicUtil.VarTypes.FLOAT, DialogicUtil.VarTypes.INT: - print("lol") if get_value_type(_current_value2, 1) in [0,3]: %Value2Type.insert_options() %Value2Type.index_pressed(1)