From db91c50a9c0318ca4c02ecb6d5971de9c4bf53f9 Mon Sep 17 00:00:00 2001 From: Jowan-Spooner Date: Tue, 21 Mar 2023 20:44:26 +0100 Subject: [PATCH 1/3] HUGE Expression update This update is centered around expressions but it has spiraled into much more. The biggest changes are: - Set Variable now allows use of expressions - Set Variable now expects "" around strings - {Variable Insertion} now allows use of expressions - Set Variable ui changed, there is now a type selector for the value - Set Variable random is now an expression - Condition Picker ui changed, there is now a type selector for both variable and value - Event resources can now request an update and set a warning - Both the Set Variable and the Condition/Choice event show an error when using a string incompatible operator with a string. - The Expression logic in DialogicGameHandler.execute_condition() was generalized and moved into a dedicated subsystem 'Expression'. This one is in a new Core folder together with the End Branch event. - Autoloads can be accessed again in conditions and set/get variables - Multiple Event Node fields have been simplified (except condition picker which got much more complicated) - a bug with condition tangling has been removed - Icons for "Go to Variable Editor" and "Go to character Editor" have been changed. - OptionSelector has now a "icon only" mode. - Warning icon has been better placed. - Removed nodes have been deleted from the game_ui.tscn --- .../Editor/Events/EventBlock/event_block.gd | 61 +++-- .../Editor/Events/EventBlock/event_block.tscn | 22 +- .../Editor/Events/Fields/ComplexPicker.tscn | 16 +- .../Editor/Events/Fields/ConditionPicker.gd | 241 ++++++++++++------ .../Editor/Events/Fields/ConditionPicker.tscn | 58 ++++- .../dialogic/Editor/Events/Fields/Number.tscn | 16 +- .../Editor/Events/Fields/OptionSelector.gd | 76 +++--- .../Editor/Events/Fields/OptionSelector.tscn | 19 +- .../Editor/Events/Fields/SinglelineText.gd | 18 +- .../Editor/Events/Fields/SinglelineText.tscn | 57 +---- .../VisualEditor/timeline_editor_visual.gd | 2 +- .../Events/Character/event_character.gd | 2 +- .../Events/Choice/subsystem_choices.gd | 2 +- .../Events/Condition/event_condition.gd | 15 +- .../{End Branch => Core}/event_end_branch.gd | 2 +- .../Events/{End Branch => Core}/icon.png | Bin .../{End Branch => Core}/icon.png.import | 8 +- addons/dialogic/Events/Core/index.gd | 10 + .../Events/Core/subsystem_expression.gd | 66 +++++ addons/dialogic/Events/End Branch/index.gd | 6 - .../Events/Variable/event_variable.gd | 141 ++++++---- .../Events/Variable/subsystem_variables.gd | 47 ++-- addons/dialogic/Other/DialogicGameHandler.gd | 33 --- addons/dialogic/Resources/event.gd | 3 + game_ui.tscn | 19 +- 25 files changed, 559 insertions(+), 381 deletions(-) rename addons/dialogic/Events/{End Branch => Core}/event_end_branch.gd (96%) rename addons/dialogic/Events/{End Branch => Core}/icon.png (100%) rename addons/dialogic/Events/{End Branch => Core}/icon.png.import (68%) create mode 100644 addons/dialogic/Events/Core/index.gd create mode 100644 addons/dialogic/Events/Core/subsystem_expression.gd delete mode 100644 addons/dialogic/Events/End Branch/index.gd diff --git a/addons/dialogic/Editor/Events/EventBlock/event_block.gd b/addons/dialogic/Editor/Events/EventBlock/event_block.gd index 209aa65c5..4237c86a0 100644 --- a/addons/dialogic/Editor/Events/EventBlock/event_block.gd +++ b/addons/dialogic/Editor/Events/EventBlock/event_block.gd @@ -29,7 +29,7 @@ var body_was_build := false var has_body_content := false # list that stores visibility conditions -var field_conditions_list := [] +var field_list := [] # for choice and condition var end_node:Node = null: @@ -75,13 +75,11 @@ func load_data(data:DialogicEvent) -> void: resource = data -func set_warning(text:String) -> void: - warning.show() - warning.tooltip_text = text - - -func remove_warning(text := '') -> void: - if warning.tooltip_text == text or text == '': +func set_warning(text:String= "") -> void: + if !text.is_empty(): + warning.show() + warning.tooltip_text = text + else: warning.hide() @@ -206,10 +204,9 @@ func build_editor(build_header:bool = true, build_body:bool = false) -> void: editor_node.use_decibel_mode() elif p.dialogic_type == resource.ValueType.FixedOptionSelector: editor_node = load("res://addons/dialogic/Editor/Events/Fields/OptionSelector.tscn").instantiate() - if p.display_info.has('selector_options'): - editor_node.options = p.display_info.selector_options - if p.display_info.has('disabled'): - editor_node.disabled = p.display_info.disabled + editor_node.options = p.display_info.get('selector_options', []) + editor_node.disabled = p.display_info.get('disabled', false) + editor_node.symbol_only = p.display_info.get('symbol_only', false) elif p.dialogic_type == resource.ValueType.Vector2: editor_node = load("res://addons/dialogic/Editor/Events/Fields/Vector2.tscn").instantiate() @@ -252,13 +249,14 @@ func build_editor(build_header:bool = true, build_body:bool = false) -> void: ### -------------------------------------------------------------------- ### 3. FILL THE NEW NODE WITH INFORMATION AND LISTEN TO CHANGES + field_list.append({'node':editor_node}) if "event_resource" in editor_node: editor_node.event_resource = resource if 'property_name' in editor_node: editor_node.property_name = p.name + field_list[-1]['property'] = p.name if editor_node.has_method('set_value'): - if resource.get(p.name) != null: # Got an error here saying that "Cannot convert argument 1 from Nil to bool." so I'm adding this check - editor_node.set_value(resource.get(p.name)) + editor_node.set_value(resource.get(p.name)) if editor_node.has_signal('value_changed'): editor_node.value_changed.connect(set_property) var left_label :Label = null @@ -275,9 +273,11 @@ func build_editor(build_header:bool = true, build_body:bool = false) -> void: location.move_child(right_label, editor_node.get_index()+1) if p.has('condition'): - field_conditions_list.append([p.condition, [editor_node]]) - if left_label: field_conditions_list[-1][1].append(left_label) - if right_label: field_conditions_list[-1][1].append(right_label) + field_list[-1]['condition'] = p.condition + if left_label: + field_list.append({'node': left_label, 'condition':p.condition}) + if right_label: + field_list.append({'node': right_label, 'condition':p.condition}) if build_body: has_body_content = true @@ -290,20 +290,18 @@ func build_editor(build_header:bool = true, build_body:bool = false) -> void: func recalculate_field_visibility() -> void: - for node_con in field_conditions_list: - if node_con[0].is_empty(): - for node in node_con[1]: node.show() + for p in field_list: + if !p.has('condition') or p.condition.is_empty(): + p.node.show() else: - var expr = Expression.new() - expr.parse(node_con[0]) + var expr := Expression.new() + expr.parse(p.condition) if expr.execute([], resource): - for node in node_con[1]: node.show() + p.node.show() else: - for node in node_con[1]: node.hide() + p.node.hide() if expr.has_execute_failed(): - var name :String= "unnamed" if "property_name" not in node_con[1][0] else node_con[1][0].property_name - printerr("[Dialogic] Failed executing visibility condition for '",name,"': " + expr.get_error_text()) - + printerr("[Dialogic] Failed executing visibility condition for '",p.get('property', 'unnamed'),"': " + expr.get_error_text()) %ExpandButton.visible = false if body_content_container != null: for node in body_content_container.get_children(): @@ -320,6 +318,12 @@ func set_property(property_name:String, value:Variant) -> void: end_node.parent_node_changed() +func _on_resource_ui_update_needed() -> void: + for node_info in field_list: + if node_info.node.has_method('set_value'): + node_info.node.set_value(resource.get(node_info.property)) + + func _update_color() -> void: if resource.dialogic_color_name != '': %IconPanel.self_modulate = DialogicUtil.get_color(resource.dialogic_color_name) @@ -335,6 +339,7 @@ func _ready(): $PanelContainer.self_modulate = get_theme_color("accent_color", "Editor") warning.texture = get_theme_icon("NodeWarning", "EditorIcons") warning.size = Vector2(16 * _scale, 16 * _scale) + warning.position = Vector2(-5 * _scale, -10 * _scale) title_label.add_theme_color_override("font_color", Color(1,1,1,1)) if not get_theme_constant("dark_theme", "Editor"): title_label.add_theme_color_override("font_color", get_theme_color("font_color", "Editor")) @@ -349,6 +354,8 @@ func _ready(): title_label.text = resource.event_name if resource._get_icon() != null: _set_event_icon(resource._get_icon()) + resource.ui_update_needed.connect(_on_resource_ui_update_needed) + resource.ui_update_warning.connect(set_warning) %IconPanel.self_modulate = resource.event_color diff --git a/addons/dialogic/Editor/Events/EventBlock/event_block.tscn b/addons/dialogic/Editor/Events/EventBlock/event_block.tscn index 9fb9faf8d..f2b8a02a6 100644 --- a/addons/dialogic/Editor/Events/EventBlock/event_block.tscn +++ b/addons/dialogic/Editor/Events/EventBlock/event_block.tscn @@ -6,12 +6,12 @@ [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_otutu"] bg_color = Color(1, 1, 1, 1) -corner_radius_top_left = 3 -corner_radius_top_right = 3 -corner_radius_bottom_right = 3 -corner_radius_bottom_left = 3 +corner_radius_top_left = 5 +corner_radius_top_right = 5 +corner_radius_bottom_right = 5 +corner_radius_bottom_left = 5 -[sub_resource type="Image" id="Image_fa8t4"] +[sub_resource type="Image" id="Image_jigoi"] 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", @@ -20,8 +20,8 @@ data = { "width": 16 } -[sub_resource type="ImageTexture" id="ImageTexture_kcwkp"] -image = SubResource("Image_fa8t4") +[sub_resource type="ImageTexture" id="ImageTexture_88cfi"] +image = SubResource("Image_jigoi") [node name="EventNode" type="MarginContainer"] anchors_preset = 10 @@ -71,7 +71,7 @@ grow_vertical = 2 size_flags_horizontal = 3 size_flags_vertical = 3 texture = ExtResource("6") -ignore_texture_size = true +expand_mode = 1 stretch_mode = 5 [node name="Warning" type="TextureRect" parent="PanelContainer/VBoxContainer/Header/IconPanel"] @@ -80,7 +80,7 @@ visible = false layout_mode = 0 offset_right = 16.0 offset_bottom = 16.0 -texture = SubResource("ImageTexture_kcwkp") +texture = SubResource("ImageTexture_88cfi") stretch_mode = 5 [node name="TitleLabel" type="Label" parent="PanelContainer/VBoxContainer/Header"] @@ -99,7 +99,7 @@ unique_name_in_owner = true layout_mode = 2 size_flags_horizontal = 10 toggle_mode = true -icon = SubResource("ImageTexture_kcwkp") +icon = SubResource("ImageTexture_88cfi") flat = true [node name="CollapseButton" type="Button" parent="PanelContainer/VBoxContainer/Header"] @@ -107,7 +107,7 @@ unique_name_in_owner = true visible = false layout_mode = 2 toggle_mode = true -icon = SubResource("ImageTexture_kcwkp") +icon = SubResource("ImageTexture_88cfi") flat = true [node name="Body" type="MarginContainer" parent="PanelContainer/VBoxContainer"] diff --git a/addons/dialogic/Editor/Events/Fields/ComplexPicker.tscn b/addons/dialogic/Editor/Events/Fields/ComplexPicker.tscn index 0c43f88a3..a26d922fc 100644 --- a/addons/dialogic/Editor/Events/Fields/ComplexPicker.tscn +++ b/addons/dialogic/Editor/Events/Fields/ComplexPicker.tscn @@ -2,7 +2,7 @@ [ext_resource type="Script" path="res://addons/dialogic/Editor/Events/Fields/ComplexPicker.gd" id="1"] -[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_tshs1"] +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_x4473"] content_margin_left = 4.0 content_margin_top = 4.0 content_margin_right = 4.0 @@ -18,7 +18,7 @@ corner_detail = 5 [sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_vennf"] -[sub_resource type="Image" id="Image_i8crg"] +[sub_resource type="Image" id="Image_jigoi"] 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", @@ -27,10 +27,10 @@ data = { "width": 16 } -[sub_resource type="ImageTexture" id="ImageTexture_qye6l"] -image = SubResource("Image_i8crg") +[sub_resource type="ImageTexture" id="ImageTexture_88cfi"] +image = SubResource("Image_jigoi") -[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_13uu3"] +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_0kgsn"] content_margin_left = 4.0 content_margin_top = 4.0 content_margin_right = 4.0 @@ -78,7 +78,7 @@ theme_override_constants/margin_bottom = 0 unique_name_in_owner = true layout_mode = 2 mouse_filter = 2 -theme_override_styles/panel = SubResource("StyleBoxFlat_tshs1") +theme_override_styles/panel = SubResource("StyleBoxFlat_x4473") metadata/_edit_use_anchors_ = true [node name="MarginContainer" type="MarginContainer" parent="PanelContainer"] @@ -134,7 +134,7 @@ layout_mode = 2 focus_mode = 0 toggle_mode = true shortcut_in_tooltip = false -icon = SubResource("ImageTexture_qye6l") +icon = SubResource("ImageTexture_88cfi") flat = true [node name="Focus" type="Panel" parent="PanelContainer"] @@ -142,7 +142,7 @@ unique_name_in_owner = true visible = false layout_mode = 2 mouse_filter = 2 -theme_override_styles/panel = SubResource("StyleBoxFlat_13uu3") +theme_override_styles/panel = SubResource("StyleBoxFlat_0kgsn") metadata/_edit_use_anchors_ = true [connection signal="focus_entered" from="." to="." method="_on_focus_entered"] diff --git a/addons/dialogic/Editor/Events/Fields/ConditionPicker.gd b/addons/dialogic/Editor/Events/Fields/ConditionPicker.gd index 4a3de86a7..217c19c90 100644 --- a/addons/dialogic/Editor/Events/Fields/ConditionPicker.gd +++ b/addons/dialogic/Editor/Events/Fields/ConditionPicker.gd @@ -5,48 +5,65 @@ extends Control signal value_changed var property_name : String +var event_resource : DialogicEvent = null +var _current_value1 :Variant = "" +var _current_value2 :Variant = "" func _ready() -> void: %ComplexEditor.add_theme_stylebox_override('normal', get_theme_stylebox('normal', 'LineEdit')) %ComplexEditor.add_theme_stylebox_override('focus', get_theme_stylebox('focus', 'LineEdit')) - %Operator.options = [ - { - 'label': '==', - 'value': '==' - }, - { - 'label': '>', - 'value': '>' - }, - { - 'label': '<', - 'value': '<' - }, - { - 'label': '<=', - 'value': '<=' - }, - { - 'label': '>=', - 'value': '>=' - }, - { - 'label': '!=', - 'value': '!=' - } - ] + for i in [%Value1Type, %Value2Type]: + i.options = [{ + 'label': 'String', + 'icon': ["String", "EditorIcons"], + 'value': 0 + },{ + 'label': 'Number', + 'icon': ["float", "EditorIcons"], + 'value': 1 + },{ + 'label': 'Variable', + 'icon': ["ClassList", "EditorIcons"], + 'value': 2 + },{ + 'label': 'Expression', + 'icon': ["Variant", "EditorIcons"], + 'value': 3 + } +# ,{ +# 'label': 'Random Number', +# 'icon': ["RandomNumberGenerator", "EditorIcons"], +# 'value': 4 +# } + ] + i.symbol_only = true + i.value_changed.connect(value_type_changed.bind(i.name)) + i.value_changed.connect(something_changed) + i.tooltip_text = "Change type" + + + for i in [%Value1Variable, %Value2Variable]: + i.get_suggestions_func = get_variable_suggestions + i.value_changed.connect(something_changed) + + %Value1Number.value_changed.connect(something_changed) + %Value2Number.value_changed.connect(something_changed) + %Value1Text.value_changed.connect(something_changed) + %Value2Text.value_changed.connect(something_changed) + %ToggleComplex.icon = get_theme_icon("Enum", "EditorIcons") - %Value1.resource_icon = get_theme_icon("ClassList", "EditorIcons") - %Value1.get_suggestions_func = get_value1_suggestions - %Value1.value_changed.connect(something_changed) %Operator.value_changed.connect(something_changed) - - %Value2.resource_icon = get_theme_icon("Variant", "EditorIcons") - %Value2.get_suggestions_func = get_value2_suggestions - %Value2.value_changed.connect(something_changed) + %Operator.options = [ + {'label': '==', 'value': '=='}, + {'label': '>', 'value': '>'}, + {'label': '<', 'value': '<'}, + {'label': '<=', 'value': '<='}, + {'label': '>=', 'value': '>='}, + {'label': '!=', 'value': '!='} + ] func set_value(value:String) -> void: @@ -57,54 +74,145 @@ func set_value(value:String) -> void: %SimpleEditor.visible = !too_complex %ComplexEditor.text = value if not too_complex: - var data := complex2simple(value) - %Value1.set_value(data[0], data[0].trim_prefix("{").trim_suffix('}')) - %Operator.set_value(data[1].strip_edges()) - %Value2.set_value(data[2], data[2].trim_prefix("{").trim_suffix('}')) + load_simple_editor(value) + + +func load_simple_editor(condition_string:String) -> void: + var data := complex2simple(condition_string) + %Value1Type.set_value(get_value_type(data[0], 2)) + _current_value1 = data[0] + value_type_changed('', get_value_type(data[0], 2), 'Value1') + %Operator.set_value(data[1].strip_edges()) + %Value2Type.set_value(get_value_type(data[2], 0)) + _current_value2 = data[2] + value_type_changed('', get_value_type(data[2], 0), 'Value2') + + +func value_type_changed(property:String, value_type:int, value_name:String) -> void: + value_name = value_name.trim_suffix('Type') + get_node('%'+value_name+'Variable').hide() + get_node('%'+value_name+'Text').hide() + get_node('%'+value_name+'Number').hide() + var current_val :Variant = "" + if '1' in value_name: + current_val = _current_value1 + else: + current_val = _current_value2 + match value_type: + 0: + get_node('%'+value_name+'Text').show() + get_node('%'+value_name+'Text').set_value(trim_value(current_val, value_type)) + 1: + get_node('%'+value_name+'Number').show() + get_node('%'+value_name+'Number').set_value(float(current_val.strip_edges())) + 2: + get_node('%'+value_name+'Variable').show() + get_node('%'+value_name+'Variable').set_value(trim_value(current_val, value_type)) + 3: + get_node('%'+value_name+'Text').show() + get_node('%'+value_name+'Text').set_value(str(current_val)) + + + +func get_value_type(value:String, default:int) -> int: + value = value.strip_edges() + if value.begins_with('"') and value.ends_with('"') and value.count('"')-value.count('\\"') == 2: + return 0 + elif value.begins_with('{') and value.ends_with('}') and value.count('{') == 1: + return 2 + else: + if value.is_empty(): + return default + if value.is_valid_float(): + return 1 + else: + return 3 + + +func prep_value(value:Variant, value_type:int) -> String: + if value != null: value = str(value) + else: value = "" + value = value.strip_edges() + match value_type: + 0: return '"'+value.replace('"', '\\"')+'"' + 2: return '{'+value+'}' + _: return value + + +func trim_value(value:Variant, value_type:int) -> String: + value = value.strip_edges() + match value_type: + 0: return value.trim_prefix('"').trim_suffix('"').replace('\\"', '"') + 2: return value.trim_prefix('{').trim_suffix('}') + _: return value 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_value(), %Value2.current_value)) + + 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) == 0: + event_resource.ui_update_warning.emit("This operator doesn't work with strings.") + else: + event_resource.ui_update_warning.emit("") + + value_changed.emit(property_name, get_simple_condition()) func is_too_complex(condition:String) -> bool: - return !condition.is_empty() and len(condition.split(' ', false)) != 3 - + return !(condition.is_empty() + or ' and ' in condition + or ' or ' in condition + or ' not ' in condition + or condition.count('==') != 1 + or condition.count('>') != 1 + or condition.count('<') != 1 + or condition.count('<=') != 1 + or condition.count('>=') != 1 + or condition.count('!=') != 1) + + +## Combines the info from the simple editor fields into a string condition +func get_simple_condition() -> String: + return _current_value1 +" "+ %Operator.text +" "+ _current_value2 + func complex2simple(condition:String) -> Array: if is_too_complex(condition) or condition.strip_edges().is_empty(): return ['', '==',''] - var cond_split := Array(condition.split(' ', false)) - if cond_split[2].begins_with('"'): cond_split[2] = cond_split[2].trim_prefix('"').trim_suffix('"') - return cond_split - + + for i in ['==', '!=', '<=', '<', '>', '>=']: + if i in condition: + var cond_split := Array(condition.split(i, false)) + return [cond_split[0], i, cond_split[1]] -func simple2complex(value1, operator, value2) -> String: - if value1 == null: value1 = '' - if value1.is_empty(): - return '' - if value2 == null: value2 = '' - if !value2.is_valid_float() and !value2.begins_with('{'): - value2 = '"'+value2+'"' - return value1 +" "+ operator +" "+ value2 + return ['', '==',''] func _on_toggle_complex_toggled(button_pressed:bool) -> void: if button_pressed: %ComplexEditor.show() %SimpleEditor.hide() - %ComplexEditor.text = simple2complex(%Value1.current_value, %Operator.get_value(), %Value2.current_value) + %ComplexEditor.text = get_simple_condition() 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.set_value(data[1].strip_edges()) - %Value2.set_value(data[2], data[2].trim_prefix("{").trim_suffix('}')) + load_simple_editor(%ComplexEditor.text) func _on_complex_editor_text_changed(new_text:String) -> void: @@ -112,21 +220,10 @@ func _on_complex_editor_text_changed(new_text:String) -> void: something_changed() -func get_value1_suggestions(filter:String) -> Dictionary: +func get_variable_suggestions(filter:String) -> Dictionary: var suggestions := {} - if filter: - suggestions[filter] = {'value':filter, 'editor_icon':["GuiScrollArrowRight", "EditorIcons"]} - var vars = DialogicUtil.get_project_setting('dialogic/variables', {}) + var vars :Dictionary= DialogicUtil.get_project_setting('dialogic/variables', {}) for var_path in DialogicUtil.list_variables(vars): - suggestions[var_path] = {'value':'{'+var_path+"}", 'editor_icon':["ClassList", "EditorIcons"]} + suggestions[var_path] = {'value':var_path, 'editor_icon':["ClassList", "EditorIcons"]} return suggestions - -func get_value2_suggestions(filter:String) -> Dictionary: - var suggestions := {} - if filter: - suggestions[filter] = {'value':filter, 'editor_icon':["GuiScrollArrowRight", "EditorIcons"]} - var vars = DialogicUtil.get_project_setting('dialogic/variables', {}) - for var_path in DialogicUtil.list_variables(vars): - suggestions[var_path] = {'value':'{'+var_path+"}", 'editor_icon':["ClassList", "EditorIcons"]} - return suggestions diff --git a/addons/dialogic/Editor/Events/Fields/ConditionPicker.tscn b/addons/dialogic/Editor/Events/Fields/ConditionPicker.tscn index f25184193..582792915 100644 --- a/addons/dialogic/Editor/Events/Fields/ConditionPicker.tscn +++ b/addons/dialogic/Editor/Events/Fields/ConditionPicker.tscn @@ -1,10 +1,12 @@ -[gd_scene load_steps=9 format=3 uid="uid://ir6334lqtuwt"] +[gd_scene load_steps=11 format=3 uid="uid://ir6334lqtuwt"] [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"] +[ext_resource type="PackedScene" uid="uid://kdpp3mibml33" path="res://addons/dialogic/Editor/Events/Fields/Number.tscn" id="4_al48y"] +[ext_resource type="PackedScene" uid="uid://c0vkcehgjsjy" path="res://addons/dialogic/Editor/Events/Fields/SinglelineText.tscn" id="4_b5vlr"] -[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_0i2t2"] +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_x4473"] content_margin_left = 4.0 content_margin_top = 4.0 content_margin_right = 4.0 @@ -18,7 +20,7 @@ corner_radius_bottom_right = 3 corner_radius_bottom_left = 3 corner_detail = 5 -[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_pxts0"] +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_0kgsn"] content_margin_left = 4.0 content_margin_top = 4.0 content_margin_right = 4.0 @@ -51,7 +53,7 @@ corner_radius_top_right = 2 corner_radius_bottom_right = 2 corner_radius_bottom_left = 2 -[sub_resource type="Image" id="Image_ov00m"] +[sub_resource type="Image" id="Image_jigoi"] 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", @@ -60,8 +62,8 @@ data = { "width": 16 } -[sub_resource type="ImageTexture" id="ImageTexture_oe0il"] -image = SubResource("Image_ov00m") +[sub_resource type="ImageTexture" id="ImageTexture_88cfi"] +image = SubResource("Image_jigoi") [node name="ConditionPicker" type="HBoxContainer"] offset_right = 77.0 @@ -72,7 +74,23 @@ script = ExtResource("1_q5p62") unique_name_in_owner = true layout_mode = 2 -[node name="Value1" parent="SimpleEditor" instance=ExtResource("1_rr7mq")] +[node name="Value1Type" parent="SimpleEditor" instance=ExtResource("4_27ir8")] +unique_name_in_owner = true +layout_mode = 2 +tooltip_text = "Change type" +text = "" + +[node name="Value1Text" parent="SimpleEditor" instance=ExtResource("4_b5vlr")] +unique_name_in_owner = true +layout_mode = 2 +theme_override_styles/normal = SubResource("StyleBoxFlat_x4473") +theme_override_styles/focus = SubResource("StyleBoxFlat_0kgsn") + +[node name="Value1Number" parent="SimpleEditor" instance=ExtResource("4_al48y")] +unique_name_in_owner = true +layout_mode = 2 + +[node name="Value1Variable" parent="SimpleEditor" instance=ExtResource("1_rr7mq")] unique_name_in_owner = true layout_mode = 2 placeholder_text = "Variable" @@ -81,10 +99,26 @@ placeholder_text = "Variable" unique_name_in_owner = true layout_mode = 2 -[node name="Value2" parent="SimpleEditor" instance=ExtResource("1_rr7mq")] +[node name="Value2Type" parent="SimpleEditor" instance=ExtResource("4_27ir8")] unique_name_in_owner = true layout_mode = 2 -placeholder_text = "Value" +tooltip_text = "Change type" +text = "" + +[node name="Value2Text" parent="SimpleEditor" instance=ExtResource("4_b5vlr")] +unique_name_in_owner = true +layout_mode = 2 +theme_override_styles/normal = SubResource("StyleBoxFlat_x4473") +theme_override_styles/focus = SubResource("StyleBoxFlat_0kgsn") + +[node name="Value2Number" parent="SimpleEditor" instance=ExtResource("4_al48y")] +unique_name_in_owner = true +layout_mode = 2 + +[node name="Value2Variable" parent="SimpleEditor" instance=ExtResource("1_rr7mq")] +unique_name_in_owner = true +layout_mode = 2 +placeholder_text = "Variable" [node name="ComplexEditor" type="LineEdit" parent="."] unique_name_in_owner = true @@ -92,8 +126,8 @@ visible = false custom_minimum_size = Vector2(150, 0) layout_mode = 2 mouse_filter = 1 -theme_override_styles/normal = SubResource("StyleBoxFlat_0i2t2") -theme_override_styles/focus = SubResource("StyleBoxFlat_pxts0") +theme_override_styles/normal = SubResource("StyleBoxFlat_x4473") +theme_override_styles/focus = SubResource("StyleBoxFlat_0kgsn") theme_override_styles/read_only = SubResource("StyleBoxFlat_q81pd") text = "VAR.Player.Health > 20 and VAR.Counter < 3 and randi()%3 == 2" placeholder_text = "Enter condition" @@ -104,7 +138,7 @@ unique_name_in_owner = true layout_mode = 2 tooltip_text = "Use complex expression" toggle_mode = true -icon = SubResource("ImageTexture_oe0il") +icon = SubResource("ImageTexture_88cfi") [connection signal="text_changed" from="ComplexEditor" to="." method="_on_complex_editor_text_changed"] [connection signal="toggled" from="ToggleComplex" to="." method="_on_toggle_complex_toggled"] diff --git a/addons/dialogic/Editor/Events/Fields/Number.tscn b/addons/dialogic/Editor/Events/Fields/Number.tscn index 196b1f895..4c95b297f 100644 --- a/addons/dialogic/Editor/Events/Fields/Number.tscn +++ b/addons/dialogic/Editor/Events/Fields/Number.tscn @@ -3,7 +3,7 @@ [ext_resource type="Script" path="res://addons/dialogic/Editor/Events/Fields/Number.gd" id="1"] [ext_resource type="Theme" uid="uid://d3g4i4dshtdpu" path="res://addons/dialogic/Editor/Events/styles/InputFieldsStyle.tres" id="2_u2kma"] -[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_okl7u"] +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_x4473"] content_margin_left = 4.0 content_margin_top = 4.0 content_margin_right = 4.0 @@ -17,7 +17,7 @@ corner_radius_bottom_right = 3 corner_radius_bottom_left = 3 corner_detail = 5 -[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_emw2l"] +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_0kgsn"] content_margin_left = 4.0 content_margin_top = 4.0 content_margin_right = 4.0 @@ -38,7 +38,7 @@ expand_margin_top = 2.0 expand_margin_right = 2.0 expand_margin_bottom = 2.0 -[sub_resource type="Image" id="Image_nh7h1"] +[sub_resource type="Image" id="Image_aennn"] data = { "data": PackedByteArray(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, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 76, 255, 255, 255, 75, 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, 99, 255, 255, 255, 191, 255, 255, 255, 191, 255, 255, 255, 99, 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, 4, 255, 255, 255, 122, 255, 255, 255, 191, 255, 255, 255, 188, 255, 255, 255, 188, 255, 255, 255, 191, 255, 255, 255, 121, 255, 255, 255, 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, 12, 255, 255, 255, 142, 255, 255, 255, 191, 255, 255, 255, 181, 255, 255, 255, 53, 255, 255, 255, 54, 255, 255, 255, 181, 255, 255, 255, 191, 255, 255, 255, 142, 255, 255, 255, 12, 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, 71, 255, 255, 255, 191, 255, 255, 255, 171, 255, 255, 255, 36, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 36, 255, 255, 255, 171, 255, 255, 255, 191, 255, 255, 255, 71, 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, 86, 255, 255, 255, 22, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 22, 255, 255, 255, 86, 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, 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, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 86, 255, 255, 255, 22, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 22, 255, 255, 255, 86, 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, 71, 255, 255, 255, 191, 255, 255, 255, 171, 255, 255, 255, 36, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 36, 255, 255, 255, 171, 255, 255, 255, 191, 255, 255, 255, 71, 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, 12, 255, 255, 255, 142, 255, 255, 255, 191, 255, 255, 255, 181, 255, 255, 255, 54, 255, 255, 255, 54, 255, 255, 255, 182, 255, 255, 255, 191, 255, 255, 255, 142, 255, 255, 255, 12, 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, 4, 255, 255, 255, 121, 255, 255, 255, 191, 255, 255, 255, 188, 255, 255, 255, 188, 255, 255, 255, 191, 255, 255, 255, 121, 255, 255, 255, 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, 255, 255, 0, 255, 255, 255, 98, 255, 255, 255, 191, 255, 255, 255, 191, 255, 255, 255, 98, 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, 75, 255, 255, 255, 75, 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, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0), "format": "RGBA8", @@ -47,8 +47,8 @@ data = { "width": 16 } -[sub_resource type="ImageTexture" id="ImageTexture_tfou8"] -image = SubResource("Image_nh7h1") +[sub_resource type="ImageTexture" id="ImageTexture_3awwm"] +image = SubResource("Image_aennn") [node name="NumberValue" type="HBoxContainer"] anchors_preset = 15 @@ -66,8 +66,8 @@ value = 0.0 layout_mode = 2 theme = ExtResource("2_u2kma") theme_override_constants/minimum_character_width = 0 -theme_override_styles/normal = SubResource("StyleBoxFlat_okl7u") -theme_override_styles/focus = SubResource("StyleBoxFlat_emw2l") +theme_override_styles/normal = SubResource("StyleBoxFlat_x4473") +theme_override_styles/focus = SubResource("StyleBoxFlat_0kgsn") text = "0" expand_to_text_length = true @@ -75,7 +75,7 @@ expand_to_text_length = true layout_mode = 2 size_flags_vertical = 4 focus_mode = 0 -icon = SubResource("ImageTexture_tfou8") +icon = SubResource("ImageTexture_3awwm") flat = true [connection signal="focus_exited" from="Value" to="." method="_on_value_focus_exited"] diff --git a/addons/dialogic/Editor/Events/Fields/OptionSelector.gd b/addons/dialogic/Editor/Events/Fields/OptionSelector.gd index 0e851914e..123951d6f 100644 --- a/addons/dialogic/Editor/Events/Fields/OptionSelector.gd +++ b/addons/dialogic/Editor/Events/Fields/OptionSelector.gd @@ -1,5 +1,5 @@ @tool -extends Control +extends MenuButton ## Event block field for constant options. For varying options use ComplexPicker. @@ -7,45 +7,57 @@ signal value_changed var property_name : String var options : Array = [] -var disabled = false: - get: - return disabled - set(_disabled): - disabled = _disabled - $MenuButton.disabled = disabled - $MenuButton.focus_mode = FOCUS_NONE - -func _ready(): - $MenuButton.add_theme_stylebox_override("normal", get_theme_stylebox("normal", "LineEdit")) - $MenuButton.add_theme_stylebox_override("hover", get_theme_stylebox("normal", "LineEdit")) + +## if true, only the symbol will be displayed. In the dropdown text will be visible. +## Useful for making UI simpler +var symbol_only := false: + set(value): + symbol_only = value + if value: text = "" + +var current_value :Variant = -1 + +func _ready() -> void: + add_theme_stylebox_override("normal", get_theme_stylebox("normal", "LineEdit")) + add_theme_stylebox_override("hover", get_theme_stylebox("normal", "LineEdit")) - $MenuButton.add_theme_stylebox_override("focus", get_theme_stylebox("focus", "LineEdit")) - $MenuButton.add_theme_stylebox_override("disabled", get_theme_stylebox("normal", "LineEdit")) - $MenuButton.add_theme_color_override("font_disabled_color", get_theme_color("font_color", "MenuButton")) - $MenuButton.about_to_popup.connect(insert_options) - $MenuButton.get_popup().index_pressed.connect(index_pressed) + add_theme_stylebox_override("focus", get_theme_stylebox("focus", "LineEdit")) + add_theme_stylebox_override("disabled", get_theme_stylebox("normal", "LineEdit")) + add_theme_color_override("font_disabled_color", get_theme_color("font_color", "MenuButton")) + about_to_popup.connect(insert_options) + get_popup().index_pressed.connect(index_pressed) -func set_value(value): +func set_value(value) -> void: for option in options: if option['value'] == value: - $MenuButton.text = option['label'] - $MenuButton.icon = option.get('icon', load("res://addons/dialogic/Editor/Images/Dropdown/default.svg")) + if typeof(option.get('icon')) == TYPE_ARRAY: + option.icon = callv('get_theme_icon', option.get('icon')) + if !symbol_only: + text = option['label'] + icon = option.get('icon', load("res://addons/dialogic/Editor/Images/Dropdown/default.svg")) + current_value = value + -func get_value(): - return $MenuButton.text +func get_value() -> Variant: + return current_value -func insert_options(): - $MenuButton.get_popup().clear() + +func insert_options() -> void: + get_popup().clear() - var idx = 0 + var idx := 0 for option in options: - $MenuButton.get_popup().add_icon_item(option.get('icon',load("res://addons/dialogic/Editor/Images/Dropdown/default.svg")), option['label']) - $MenuButton.get_popup().set_item_metadata(idx, option['value']) + if typeof(option.get('icon')) == TYPE_ARRAY: + option.icon = callv('get_theme_icon', option.get('icon')) + get_popup().add_icon_item(option.get('icon',load("res://addons/dialogic/Editor/Images/Dropdown/default.svg")), option['label']) + get_popup().set_item_metadata(idx, option['value']) idx += 1 -func index_pressed(idx): - $MenuButton.text = $MenuButton.get_popup().get_item_text(idx) - $MenuButton.icon = $MenuButton.get_popup().get_item_icon(idx) - - emit_signal("value_changed", property_name, $MenuButton.get_popup().get_item_metadata(idx)) + +func index_pressed(idx:int) -> void: + current_value = idx + if !symbol_only: + text = get_popup().get_item_text(idx) + icon = get_popup().get_item_icon(idx) + value_changed.emit(property_name, get_popup().get_item_metadata(idx)) diff --git a/addons/dialogic/Editor/Events/Fields/OptionSelector.tscn b/addons/dialogic/Editor/Events/Fields/OptionSelector.tscn index 56e14bed8..a6d7108fa 100644 --- a/addons/dialogic/Editor/Events/Fields/OptionSelector.tscn +++ b/addons/dialogic/Editor/Events/Fields/OptionSelector.tscn @@ -2,7 +2,7 @@ [ext_resource type="Script" path="res://addons/dialogic/Editor/Events/Fields/OptionSelector.gd" id="1"] -[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_okl7u"] +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_x4473"] content_margin_left = 4.0 content_margin_top = 4.0 content_margin_right = 4.0 @@ -16,7 +16,7 @@ corner_radius_bottom_right = 3 corner_radius_bottom_left = 3 corner_detail = 5 -[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_emw2l"] +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_0kgsn"] content_margin_left = 4.0 content_margin_top = 4.0 content_margin_right = 4.0 @@ -37,18 +37,15 @@ expand_margin_top = 2.0 expand_margin_right = 2.0 expand_margin_bottom = 2.0 -[node name="OptionSelector" type="HBoxContainer"] +[node name="OptionSelector" type="MenuButton"] offset_right = 137.0 offset_bottom = 43.0 -script = ExtResource("1") - -[node name="MenuButton" type="MenuButton" parent="."] -layout_mode = 2 focus_mode = 2 theme_override_colors/font_disabled_color = Color(0.875, 0.875, 0.875, 1) -theme_override_styles/normal = SubResource("StyleBoxFlat_okl7u") -theme_override_styles/hover = SubResource("StyleBoxFlat_okl7u") -theme_override_styles/disabled = SubResource("StyleBoxFlat_okl7u") -theme_override_styles/focus = SubResource("StyleBoxFlat_emw2l") +theme_override_styles/normal = SubResource("StyleBoxFlat_x4473") +theme_override_styles/hover = SubResource("StyleBoxFlat_x4473") +theme_override_styles/disabled = SubResource("StyleBoxFlat_x4473") +theme_override_styles/focus = SubResource("StyleBoxFlat_0kgsn") text = "Placeholder Text" flat = false +script = ExtResource("1") diff --git a/addons/dialogic/Editor/Events/Fields/SinglelineText.gd b/addons/dialogic/Editor/Events/Fields/SinglelineText.gd index 81ab14471..1c60a4555 100644 --- a/addons/dialogic/Editor/Events/Fields/SinglelineText.gd +++ b/addons/dialogic/Editor/Events/Fields/SinglelineText.gd @@ -1,5 +1,5 @@ @tool -extends Control +extends LineEdit ## Event block field for a single line of text. @@ -9,16 +9,18 @@ var property_name : String var placeholder :String= "": set(value): placeholder = value - $TextEdit.placeholder_text = placeholder + placeholder_text = placeholder func _ready() -> void: - $TextEdit.text_changed.connect(text_changed) - $TextEdit.add_theme_stylebox_override('normal', get_theme_stylebox('normal', 'LineEdit')) - $TextEdit.add_theme_stylebox_override('focus', get_theme_stylebox('focus', 'LineEdit')) + text_changed.connect(_on_text_changed) + add_theme_stylebox_override('normal', get_theme_stylebox('normal', 'LineEdit')) + add_theme_stylebox_override('focus', get_theme_stylebox('focus', 'LineEdit')) + + +func _on_text_changed(value := "") -> void: + value_changed.emit(property_name, text) -func text_changed(value := "") -> void: - emit_signal("value_changed", property_name, $TextEdit.text) func set_value(value:String) -> void: - $TextEdit.text = str(value) + text = str(value) diff --git a/addons/dialogic/Editor/Events/Fields/SinglelineText.tscn b/addons/dialogic/Editor/Events/Fields/SinglelineText.tscn index 9b99fdb9e..bda671e83 100644 --- a/addons/dialogic/Editor/Events/Fields/SinglelineText.tscn +++ b/addons/dialogic/Editor/Events/Fields/SinglelineText.tscn @@ -1,56 +1,9 @@ -[gd_scene load_steps=4 format=3 uid="uid://c0vkcehgjsjy"] +[gd_scene load_steps=2 format=3 uid="uid://c0vkcehgjsjy"] [ext_resource type="Script" path="res://addons/dialogic/Editor/Events/Fields/SinglelineText.gd" id="1"] -[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_okl7u"] -content_margin_left = 4.0 -content_margin_top = 4.0 -content_margin_right = 4.0 -content_margin_bottom = 4.0 -bg_color = Color(0.1, 0.1, 0.1, 0.6) -border_width_bottom = 2 -border_color = Color(0, 0, 0, 0.6) -corner_radius_top_left = 3 -corner_radius_top_right = 3 -corner_radius_bottom_right = 3 -corner_radius_bottom_left = 3 -corner_detail = 5 - -[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_emw2l"] -content_margin_left = 4.0 -content_margin_top = 4.0 -content_margin_right = 4.0 -content_margin_bottom = 4.0 -bg_color = Color(1, 1, 1, 0.75) -draw_center = false -border_width_left = 2 -border_width_top = 2 -border_width_right = 2 -border_width_bottom = 2 -corner_radius_top_left = 3 -corner_radius_top_right = 3 -corner_radius_bottom_right = 3 -corner_radius_bottom_left = 3 -corner_detail = 5 -expand_margin_left = 2.0 -expand_margin_top = 2.0 -expand_margin_right = 2.0 -expand_margin_bottom = 2.0 - -[node name="SinglelineText" type="HBoxContainer"] -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -offset_bottom = -567.0 -grow_horizontal = 2 -grow_vertical = 2 -size_flags_horizontal = 0 -script = ExtResource("1") - -[node name="TextEdit" type="LineEdit" parent="."] -layout_mode = 2 -size_flags_horizontal = 3 -size_flags_vertical = 3 -theme_override_styles/normal = SubResource("StyleBoxFlat_okl7u") -theme_override_styles/focus = SubResource("StyleBoxFlat_emw2l") +[node name="SingleLineText" type="LineEdit"] +offset_right = 1152.0 +offset_bottom = 81.0 expand_to_text_length = true +script = ExtResource("1") diff --git a/addons/dialogic/Editor/TimelineEditor/VisualEditor/timeline_editor_visual.gd b/addons/dialogic/Editor/TimelineEditor/VisualEditor/timeline_editor_visual.gd index 877168959..befc86363 100644 --- a/addons/dialogic/Editor/TimelineEditor/VisualEditor/timeline_editor_visual.gd +++ b/addons/dialogic/Editor/TimelineEditor/VisualEditor/timeline_editor_visual.gd @@ -855,7 +855,7 @@ func indent_events() -> void: if current_block_above != null and event.resource.is_expected_parent_event(current_block_above.resource): indent += 1 - event.remove_warning() + event.set_warning() else: event.set_warning('This event needs a specific parent event!') diff --git a/addons/dialogic/Events/Character/event_character.gd b/addons/dialogic/Events/Character/event_character.gd index 2258c4bc7..14dacb97e 100644 --- a/addons/dialogic/Events/Character/event_character.gd +++ b/addons/dialogic/Events/Character/event_character.gd @@ -376,7 +376,7 @@ func build_event_editor() -> void: 'file_extension' : '.dch', 'suggestions_func' : get_character_suggestions, 'icon' : load("res://addons/dialogic/Editor/Images/Resources/character.svg")}) - add_header_button('', _on_character_edit_pressed, 'Edit character', ["Edit", "EditorIcons"], 'character != null and _character_from_directory != "--All--"') + add_header_button('', _on_character_edit_pressed, 'Edit character', ["ExternalLink", "EditorIcons"], 'character != null and _character_from_directory != "--All--"') add_header_edit('portrait', ValueType.ComplexPicker, '', '', {'empty_text' : 'Default', diff --git a/addons/dialogic/Events/Choice/subsystem_choices.gd b/addons/dialogic/Events/Choice/subsystem_choices.gd index 1320e6d10..699f1a4fc 100644 --- a/addons/dialogic/Events/Choice/subsystem_choices.gd +++ b/addons/dialogic/Events/Choice/subsystem_choices.gd @@ -41,7 +41,7 @@ func show_current_choices() -> void: for choice_index in get_current_choice_indexes(): var choice_event :DialogicEvent= dialogic.current_timeline_events[choice_index] # check if condition is false - if not choice_event.condition.is_empty() and not dialogic.execute_condition(choice_event.condition): + if not choice_event.condition.is_empty() and not dialogic.Expression.execute_condition(choice_event.condition): if choice_event.else_action == DialogicChoiceEvent.ElseActions.Default: choice_event.else_action = DialogicUtil.get_project_setting('dialogic/choices/def_false_behaviour', 0) diff --git a/addons/dialogic/Events/Condition/event_condition.gd b/addons/dialogic/Events/Condition/event_condition.gd index b4b268b58..7fc94d576 100644 --- a/addons/dialogic/Events/Condition/event_condition.gd +++ b/addons/dialogic/Events/Condition/event_condition.gd @@ -24,26 +24,23 @@ func _execute() -> void: if condition.is_empty(): condition = "true" - var result = dialogic.execute_condition(condition) + var result :bool= dialogic.Expression.execute_condition(condition) if not result: - var idx = dialogic.current_event_idx - var ignore = 1 + var idx :int= dialogic.current_event_idx + var ignore := 1 while true: idx += 1 - if not dialogic.current_timeline.get_event(idx): + if not dialogic.current_timeline.get_event(idx) or ignore == 0: break - if ignore == 0 and dialogic.current_timeline.get_event(idx) is DialogicConditionEvent: - break - if dialogic.current_timeline.get_event(idx).can_contain_events: + elif dialogic.current_timeline.get_event(idx).can_contain_events: ignore += 1 elif dialogic.current_timeline.get_event(idx) is DialogicEndBranchEvent: ignore -= 1 - elif ignore == 0: - break dialogic.current_event_idx = idx-1 finish() + ## only called if the previous event was an end-branch event ## return true if this event should be executed if the previous event was an end-branch event func should_execute_this_branch() -> bool: diff --git a/addons/dialogic/Events/End Branch/event_end_branch.gd b/addons/dialogic/Events/Core/event_end_branch.gd similarity index 96% rename from addons/dialogic/Events/End Branch/event_end_branch.gd rename to addons/dialogic/Events/Core/event_end_branch.gd index 3bd8d798f..f41bbdd10 100644 --- a/addons/dialogic/Events/End Branch/event_end_branch.gd +++ b/addons/dialogic/Events/Core/event_end_branch.gd @@ -21,7 +21,7 @@ func find_next_index(): var ignore: int = 1 while true: idx += 1 - var event = dialogic.current_timeline.get_event(idx) + var event :DialogicEvent= dialogic.current_timeline.get_event(idx) if not event: return idx if event is DialogicEndBranchEvent: diff --git a/addons/dialogic/Events/End Branch/icon.png b/addons/dialogic/Events/Core/icon.png similarity index 100% rename from addons/dialogic/Events/End Branch/icon.png rename to addons/dialogic/Events/Core/icon.png diff --git a/addons/dialogic/Events/End Branch/icon.png.import b/addons/dialogic/Events/Core/icon.png.import similarity index 68% rename from addons/dialogic/Events/End Branch/icon.png.import rename to addons/dialogic/Events/Core/icon.png.import index 77e1d3712..0466e625c 100644 --- a/addons/dialogic/Events/End Branch/icon.png.import +++ b/addons/dialogic/Events/Core/icon.png.import @@ -3,22 +3,22 @@ importer="texture" type="CompressedTexture2D" uid="uid://b0h5mknqmos7r" -path="res://.godot/imported/icon.png-2770b68f95c6e9b6492f82019c7cb894.ctex" +path="res://.godot/imported/icon.png-b05b573e7ccf7fbc331b3b80a1cfbb36.ctex" metadata={ "vram_texture": false } [deps] -source_file="res://addons/dialogic/Events/End Branch/icon.png" -dest_files=["res://.godot/imported/icon.png-2770b68f95c6e9b6492f82019c7cb894.ctex"] +source_file="res://addons/dialogic/Events/Core/icon.png" +dest_files=["res://.godot/imported/icon.png-b05b573e7ccf7fbc331b3b80a1cfbb36.ctex"] [params] compress/mode=0 +compress/high_quality=false compress/lossy_quality=0.7 compress/hdr_compression=1 -compress/bptc_ldr=0 compress/normal_map=0 compress/channel_pack=0 mipmaps/generate=false diff --git a/addons/dialogic/Events/Core/index.gd b/addons/dialogic/Events/Core/index.gd new file mode 100644 index 000000000..0a2fa4263 --- /dev/null +++ b/addons/dialogic/Events/Core/index.gd @@ -0,0 +1,10 @@ +@tool +extends DialogicIndexer + + +func _get_events() -> Array: + return [this_folder.path_join('event_end_branch.gd')] + + +func _get_subsystems() -> Array: + return [{'name':'Expression', 'script':this_folder.path_join('subsystem_expression.gd')}] diff --git a/addons/dialogic/Events/Core/subsystem_expression.gd b/addons/dialogic/Events/Core/subsystem_expression.gd new file mode 100644 index 000000000..75b5877ab --- /dev/null +++ b/addons/dialogic/Events/Core/subsystem_expression.gd @@ -0,0 +1,66 @@ +extends DialogicSubsystem + +## Subsystem that allows executing strings (with the Expression class). +## This is used by conditions and to allow expresions as variables. + + + +#################################################################################################### +## MAIN METHODS +#################################################################################################### + +func execute_string(string:String, default = null) -> Variant: + # Some methods are not supported by the expression class, but very useful. + # Thus they are recreated below and secretly added. + string = string.replace('range(', 'd_range(') + string = string.replace('len(', 'd_len(') + + + var regex: RegEx = RegEx.create_from_string('{(\\w.*)}') + + for res in regex.search_all(string): + var value: String = dialogic.VAR.get_variable(res.get_string()) + if !value.is_valid_float(): + value = '"'+value+'"' + string = string.replace(res.get_string(), value) + + var expr := Expression.new() + + var autoloads := [] + var autoload_names := [] + for c in get_tree().root.get_children(): + autoloads.append(c) + autoload_names.append(c.name) + + if expr.parse(string, autoload_names) != OK: + printerr('Dialogic: Expression failed to parse: ', expr.get_error_text()) + return default + + var result := expr.execute(autoloads, self) + if expr.has_execute_failed(): + printerr('Dialogic: Expression failed to execute: ', expr.get_error_text()) + return default + return result + + +func execute_condition(condition:String) -> bool: + if execute_string(condition, false): + return true + return false + + +#################################################################################################### +## MAIN METHODS +#################################################################################################### +func d_range(a1, a2=null,a3=null,a4=null) -> Array: + if !a2: + return range(a1) + elif !a3: + return range(a1, a2) + elif !a4: + return range(a1, a2, a3) + else: + return range(a1, a2, a3, a4) + +func d_len(arg:Variant) -> int: + return len(arg) diff --git a/addons/dialogic/Events/End Branch/index.gd b/addons/dialogic/Events/End Branch/index.gd deleted file mode 100644 index 562156c93..000000000 --- a/addons/dialogic/Events/End Branch/index.gd +++ /dev/null @@ -1,6 +0,0 @@ -@tool -extends DialogicIndexer - - -func _get_events() -> Array: - return [this_folder.path_join('event_end_branch.gd')] diff --git a/addons/dialogic/Events/Variable/event_variable.gd b/addons/dialogic/Events/Variable/event_variable.gd index 5fe09fd70..d68e65c2a 100644 --- a/addons/dialogic/Events/Variable/event_variable.gd +++ b/addons/dialogic/Events/Variable/event_variable.gd @@ -12,11 +12,22 @@ enum Operations {Set, Add, Substract, Multiply, Divide} ## Name/Path of the variable that should be changed. var name: String = "" ## The operation to perform. -var operation: int = Operations.Set +var operation: int = Operations.Set: + set(value): + operation = value + if operation != Operations.Set and _value_type == 0: + _value_type = 1 + ui_update_needed.emit() + update_editor_warning() + ## The value that is used. Can be a variable as well. -var value: String = "" +var value: Variant = "" +var _value_type := 0 :# helper for the ui 0 = string, 1= float, 2= variable 3= expression, 4= random int (a special expression) + set(value): + _value_type = value + update_editor_warning() + ## If true, a random number between [random_min] and [random_max] is used instead of [value]. -var random_enabled: bool = false var random_min: int = 0 var random_max: int = 100 @@ -28,14 +39,9 @@ var random_max: int = 100 func _execute() -> void: if name: var orig :Variant= dialogic.VAR.get_variable(name) - var the_value :Variant= value - if value.begins_with("{"): - the_value = dialogic.VAR.get_variable(value) - if random_enabled: - the_value = randi()%(random_max-random_min)+random_min + if value and orig != null: + var the_value :Variant = dialogic.Expression.execute_string(value) - if orig != null: - if operation != Operations.Set and orig.is_valid_float() and value.is_valid_float(): orig = orig.to_float() the_value = value.to_float() @@ -51,7 +57,10 @@ func _execute() -> void: elif operation == Operations.Set: dialogic.VAR.set_variable(name, str(the_value)) else: - printerr("Dialogic: Set Variable event failed because one value wasn't a float!") + printerr("Dialogic: Set Variable event failed because one value wasn't a float! [", orig, ", ",the_value,"]") + else: + printerr("Dialogic: Set Variable event failed because one value wasn't set!") + finish() @@ -86,20 +95,24 @@ func to_text() -> String: string+= " *= " Operations.Divide: string+= " /= " - string += value - if random_enabled: - string += ' [random="True"' - if random_min != 0: - string += ' min="'+str(random_min)+'"' - if random_max != 100: - string += ' max="'+str(random_max)+'"' - string += "]" + + value = str(value) + match _value_type: + 0: # String + string += '"'+value.replace('"', '\\"')+'"' + 1,3: # Float or Expression + string += str(value) + 2: # Variable + string += '{'+value+'}' + 4: + string += 'range('+str(random_min)+','+str(random_max)+').pick_random()' + return string func from_text(string:String) -> void: var reg := RegEx.new() - reg.compile("VAR(?[^=+\\-*\\/]*)(?=|\\+=|-=|\\*=|\\/=)(?[^\\[\\n]*)(?\\[.*)?") + reg.compile("VAR(?[^=+\\-*\\/]*)?(?=|\\+=|-=|\\*=|\\/=)?(?.*)") var result := reg.search(string) if !result: return @@ -115,13 +128,27 @@ func from_text(string:String) -> void: operation = Operations.Multiply '/=': operation = Operations.Divide - value = result.get_string('value').strip_edges() - if !result.get_string('shortcode').is_empty(): - var shortcodeparams := parse_shortcode_parameters(result.get_string('shortcode')) - random_enabled = true if shortcodeparams.get('random', "True") == "True" else false - random_min = DialogicUtil.logical_convert(shortcodeparams.get('min', 0)) - random_max = DialogicUtil.logical_convert(shortcodeparams.get('max', 100)) + if result.get_string('value'): + value = result.get_string('value').strip_edges() + if value.begins_with('"') and value.ends_with('"') and value.count('"')-value.count('\\"') == 2: + value = result.get_string('value').strip_edges().replace('"', '') + _value_type = 0 + elif value.begins_with('{') and value.ends_with('}') and value.count('{') == 1: + value = result.get_string('value').strip_edges().trim_suffix('}').trim_prefix('{') + _value_type = 2 + elif value.begins_with('random('): + _value_type = 4 + var randinf := str(value).trim_prefix('random(').trim_suffix(')').split(',') + random_min = int(randinf[0]) + random_max = int(randinf[1]) + else: + value = result.get_string('value').strip_edges() + if value.is_valid_float(): + _value_type = 1 + else: + _value_type = 3 + func is_valid_event(string:String) -> bool: @@ -142,38 +169,59 @@ func build_event_editor(): 'label': 'to be', 'icon': load("res://addons/dialogic/Editor/Images/Dropdown/set.svg"), 'value': Operations.Set - }, - { + },{ 'label': 'to itself plus', 'icon': load("res://addons/dialogic/Editor/Images/Dropdown/plus.svg"), 'value': Operations.Add - }, - { + },{ 'label': 'to itself minus', 'icon': load("res://addons/dialogic/Editor/Images/Dropdown/minus.svg"), 'value': Operations.Substract - }, - { + },{ 'label': 'to itself multiplied by', 'icon': load("res://addons/dialogic/Editor/Images/Dropdown/multiply.svg"), 'value': Operations.Multiply - }, - { + },{ 'label': 'to itself divided by', 'icon': load("res://addons/dialogic/Editor/Images/Dropdown/divide.svg"), 'value': Operations.Divide } ] }, '!name.is_empty()') + add_header_edit('_value_type', ValueType.FixedOptionSelector, '', '', { + 'selector_options': [ + { + 'label': 'String', + 'icon': ["String", "EditorIcons"], + 'value': 0 + },{ + 'label': 'Number', + 'icon': ["float", "EditorIcons"], + 'value': 1 + },{ + 'label': 'Variable', + 'icon': ["ClassList", "EditorIcons"], + 'value': 2 + },{ + 'label': 'Expression', + 'icon': ["Variant", "EditorIcons"], + 'value': 3 + },{ + 'label': 'Random Number', + 'icon': ["RandomNumberGenerator", "EditorIcons"], + 'value': 4 + }], + 'symbol_only':true}, + '!name.is_empty()') + add_header_edit('value', ValueType.SinglelineText, '', '', {}, '!name.is_empty() and (_value_type == 0 or _value_type == 3) ') + add_header_edit('value', ValueType.Float, '', '', {}, '!name.is_empty() and _value_type == 1') add_header_edit('value', ValueType.ComplexPicker, '', '', - {'suggestions_func' : get_value_suggestions, - 'editor_icon' : ["Variant", "EditorIcons"], }, - '!name.is_empty() and not random_enabled') - add_header_label('a random integer', 'random_enabled') - add_header_button('', _on_variable_editor_pressed, 'Variable Editor', ["EditAddRemove", "EditorIcons"]) - add_body_edit('random_enabled', ValueType.Bool, 'Use Random Integer:', '', {}, '!name.is_empty()') - add_body_edit('random_min', ValueType.Integer, 'Min:', '', {}, '!name.is_empty() and random_enabled') - add_body_edit('random_max', ValueType.Integer, 'Max:', '', {}, '!name.is_empty() and random_enabled') + {'suggestions_func' : get_value_suggestions}, + '!name.is_empty() and _value_type == 2') + add_header_label('an int between', '_value_type == 4') + add_header_edit('random_min', ValueType.Integer, '', 'and', {}, '!name.is_empty() and _value_type == 4') + add_header_edit('random_max', ValueType.Integer, '', '', {}, '!name.is_empty() and _value_type == 4') + add_header_button('', _on_variable_editor_pressed, 'Variable Editor', ["ExternalLink", "EditorIcons"]) func get_var_suggestions(filter:String) -> Dictionary: var suggestions := {} @@ -189,8 +237,6 @@ func get_var_suggestions(filter:String) -> Dictionary: func get_value_suggestions(filter:String) -> Dictionary: var suggestions := {} - if filter: - suggestions[filter] = {'value':filter, 'editor_icon':["GuiScrollArrowRight", "EditorIcons"]} var vars: Dictionary = DialogicUtil.get_project_setting('dialogic/variables', {}) for var_path in DialogicUtil.list_variables(vars): suggestions[var_path] = {'value':var_path, 'editor_icon':["ClassList", "EditorIcons"]} @@ -201,3 +247,10 @@ func _on_variable_editor_pressed(): var editor_manager := _editor_node.find_parent('EditorsManager') if editor_manager: editor_manager.open_editor(editor_manager.editors['VariablesEditor']['node'], true) + + +func update_editor_warning() -> void: + if _value_type == 0 and operation != Operations.Set: + ui_update_warning.emit('You cannot do this operation with a string!') + else: + ui_update_warning.emit('') diff --git a/addons/dialogic/Events/Variable/subsystem_variables.gd b/addons/dialogic/Events/Variable/subsystem_variables.gd index 1f4db15d3..510735462 100644 --- a/addons/dialogic/Events/Variable/subsystem_variables.gd +++ b/addons/dialogic/Events/Variable/subsystem_variables.gd @@ -41,27 +41,26 @@ func parse_variables(text:String) -> String: if '{' in text: # Otherwise, why bother? # Trying to extract the curly brackets from the text - var regex = RegEx.new() + var regex := RegEx.new() regex.compile("\\{(?[^{}]*)\\}") - var parsed = text + var parsed := text for result in regex.search_all(text): - var value = get_variable(result.get_string('variable'), "") + var value := get_variable(result.get_string('variable'), "") parsed = parsed.replace("{"+result.get_string('variable')+"}", str(value)) return parsed return text func set_variable(variable_name: String, value: String) -> bool: - if variable_name.left(1) == "{" and variable_name.right(1) == "}": - variable_name = variable_name.substr(1,variable_name.length()-2) + variable_name = variable_name.trim_prefix('{').trim_suffix('}') # Getting all the autoloads - var autoloads = get_autoloads() + var autoloads := get_autoloads() if '.' in variable_name: - var query = variable_name.split('.') - var from = query[0] - var variable = query[1] + var query := variable_name.split('.') + var from := query[0] + var variable := query[1] for a in autoloads: if a.name == from: a.set(variable, value) @@ -78,22 +77,23 @@ func set_variable(variable_name: String, value: String) -> bool: printerr("Dialogic: Tried accessing non-existant variable '"+variable_name+"'.") return false + func get_variable(variable_path:String, default = null) -> Variant: - if variable_path.left(1) == "{" and variable_path.right(1) == "}": - variable_path = variable_path.substr(1,variable_path.length()-2) + variable_path = variable_path.trim_prefix('{').trim_suffix('}') + # Getting all the autoloads - var autoloads = get_autoloads() + var autoloads := get_autoloads() if variable_path in dialogic.current_state_info['variables'].keys(): return dialogic.current_state_info['variables'][variable_path] if '.' in variable_path: - var query = variable_path.split('.') - var from = query[0] + var query := variable_path.split('.') + var from := query[0] var variable = query[1] for a in autoloads: if a.name == from: - var myvar = a.get(variable) + var myvar :Variant= a.get(variable) if myvar != null: return myvar else: @@ -101,7 +101,7 @@ func get_variable(variable_path:String, default = null) -> Variant: return default # if none is found, try getting it from the dialogic variables - var value = _get_value_in_dictionary(variable_path, dialogic.current_state_info['variables']) + var value := _get_value_in_dictionary(variable_path, dialogic.current_state_info['variables']) if value != null: return value else: @@ -116,7 +116,7 @@ func get_variable(variable_path:String, default = null) -> Variant: # e.g. it could set "Something.Something.Something" in {'Something':{'Something':{'Someting':"value"}}} func _set_value_in_dictionary(path:String, dictionary:Dictionary, value): if '.' in path: - var from = path.split('.')[0] + var from := path.split('.')[0] if from in dictionary.keys(): dictionary[from] = _set_value_in_dictionary(path.trim_prefix(from+"."), dictionary[from], value) else: @@ -124,11 +124,12 @@ func _set_value_in_dictionary(path:String, dictionary:Dictionary, value): dictionary[path] = value return dictionary + # this will get a value in a dictionary (or a sub-dictionary based on the path) # e.g. it could get "Something.Something.Something" in {'Something':{'Something':{'Someting':"value"}}} -func _get_value_in_dictionary(path:String, dictionary:Dictionary, default= null): +func _get_value_in_dictionary(path:String, dictionary:Dictionary, default= null) -> Variant: if '.' in path: - var from = path.split('.')[0] + var from := path.split('.')[0] if from in dictionary.keys(): return _get_value_in_dictionary(path.trim_prefix(from+"."), dictionary[from], default) else: @@ -137,22 +138,24 @@ func _get_value_in_dictionary(path:String, dictionary:Dictionary, default= null) return default func get_autoloads() -> Array: - var autoloads = [] + var autoloads := [] for c in get_tree().root.get_children(): autoloads.append(c) return autoloads # allows to set dialogic built-in variables -func _set(property, value): +func _set(property, value) -> bool: property = str(property) - var variables = dialogic.current_state_info['variables'] + var variables: Dictionary = dialogic.current_state_info['variables'] if property in variables.keys(): if typeof(variables[property]) != TYPE_DICTIONARY: variables[property] = value return true if value is VariableFolder: return true + return false + # allows to get dialogic built-in variables func _get(property): diff --git a/addons/dialogic/Other/DialogicGameHandler.gd b/addons/dialogic/Other/DialogicGameHandler.gd index 762387028..2d33646d5 100644 --- a/addons/dialogic/Other/DialogicGameHandler.gd +++ b/addons/dialogic/Other/DialogicGameHandler.gd @@ -158,38 +158,6 @@ func clear() -> bool: return true -################################################################################ -## STATE -################################################################################ - -func execute_condition(condition:String) -> bool: - var regex: RegEx = RegEx.new() - regex.compile('{(\\w.*)}') - var result := regex.search_all(condition) - if result: - for res in result: - var r_string: String = res.get_string() - var value: String = self.VAR.get_variable(r_string) - if !value.is_valid_float(): - value = '"'+value+'"' - condition = condition.replace(r_string, value) - var expr: Expression = Expression.new() - # this doesn't work currently, not sure why. However you can still use autoloads in conditions - # you have to put them in {} brackets tho. E.g. `if {MyAutoload.my_var} > 20:` -# var autoload_names: Array = [] -# var autoloads: Array = [] -# for c in get_tree().root.get_children(): -# autoloads.append(c) -# autoload_names.append(c.name) -# expr.parse(condition, autoload_names) -# if expr.execute(autoloads, self): - expr.parse(condition) - if expr.execute([], self): - return true - if expr.has_execute_failed(): - printerr('Dialogic: Condition failed to execute: ', expr.get_error_text()) - return false - ################################################################################ ## SAVING & LOADING @@ -519,7 +487,6 @@ func get_layout_node() -> Node: func _on_timeline_ended(): - print("wowie") if is_instance_valid(get_tree().get_meta('dialogic_layout_node', '')): match ProjectSettings.get_setting('dialogic/layout/end_behaviour', 0): 0: diff --git a/addons/dialogic/Resources/event.gd b/addons/dialogic/Resources/event.gd index bef3ba14b..34f66d2ef 100644 --- a/addons/dialogic/Resources/event.gd +++ b/addons/dialogic/Resources/event.gd @@ -101,6 +101,9 @@ enum ValueType { } ## List that stores the fields for the editor var editor_list : Array = [] +## Singal that notifies the visual editor block to update +signal ui_update_needed +signal ui_update_warning(text) ## Makes this resource printable. diff --git a/game_ui.tscn b/game_ui.tscn index 7dc156207..5a1b03d95 100644 --- a/game_ui.tscn +++ b/game_ui.tscn @@ -1,14 +1,11 @@ -[gd_scene load_steps=10 format=3 uid="uid://bodlkbe7qcbqs"] +[gd_scene load_steps=7 format=3 uid="uid://bodlkbe7qcbqs"] [ext_resource type="Script" path="res://addons/dialogic/Events/Background/node_background_holder.gd" id="1_7xoxi"] [ext_resource type="Script" path="res://addons/dialogic/Events/Text/node_dialog_text.gd" id="1_pyeja"] [ext_resource type="Script" path="res://addons/dialogic/Events/Choice/node_choice_button.gd" id="2_0chsi"] [ext_resource type="Script" path="res://addons/dialogic/Events/Text/node_next_indicator.gd" id="2_8o2ju"] -[ext_resource type="Script" path="res://addons/dialogic/Events/Text/node_input_handler.gd" id="2_cul8m"] [ext_resource type="Texture2D" uid="uid://bvqgwmds7enrv" path="res://icon.svg" id="3_y357o"] [ext_resource type="Script" path="res://addons/dialogic/Events/Text/node_name_label.gd" id="3_yr5sj"] -[ext_resource type="Script" path="res://addons/dialogic/Events/Character/node_portrait_position.gd" id="7_sijvi"] -[ext_resource type="Script" path="res://addons/dialogic/Events/Character/node_portrait_holder.gd" id="8_mhj1c"] [node name="GameUI" type="CanvasLayer"] @@ -135,17 +132,3 @@ flat = true alignment = 0 expand_icon = true script = ExtResource("2_0chsi") - -[node name="DialogicNode_InputHandler" type="Node" parent="."] -script = ExtResource("2_cul8m") - -[node name="DialogicNode_PortraitPosition" type="Marker2D" parent="."] -position = Vector2(148, 656) -script = ExtResource("7_sijvi") - -[node name="DialogicNode_PortraitPosition2" type="Marker2D" parent="."] -position = Vector2(983, 656) -script = ExtResource("7_sijvi") - -[node name="DialogicNode_PortraitHolder" type="CanvasLayer" parent="."] -script = ExtResource("8_mhj1c") From 60916036cb61a5d4256ce186a2c8797f863c8def Mon Sep 17 00:00:00 2001 From: Jowan-Spooner Date: Wed, 22 Mar 2023 23:23:32 +0100 Subject: [PATCH 2/3] Add Expression capability to {inserted variables} This is because (also to support autoload variables) get_variable() will now execute the given string if no variable could be found for that path. Removed some prints() Fixed an error with float conversion. --- .../Events/Character/event_character.gd | 5 ---- .../TextBubble/DialogicTextBubbleLayout.gd | 3 -- .../Events/Variable/event_variable.gd | 17 +++++------ .../Events/Variable/subsystem_variables.gd | 30 ++++++------------- 4 files changed, 17 insertions(+), 38 deletions(-) diff --git a/addons/dialogic/Events/Character/event_character.gd b/addons/dialogic/Events/Character/event_character.gd index 14dacb97e..94948e3d0 100644 --- a/addons/dialogic/Events/Character/event_character.gd +++ b/addons/dialogic/Events/Character/event_character.gd @@ -196,11 +196,6 @@ func to_text() -> String: ActionTypes.Leave: result_string += "Leave " ActionTypes.Update: result_string += "Update " -# print('to_string') - -# print('character ', character) -# print('characterfrom ', _character_from_directory) - if character or _character_from_directory == '--All--': if action_type == ActionTypes.Leave and _character_from_directory == '--All--': result_string += "--All--" diff --git a/addons/dialogic/Events/DefaultLayouts/TextBubble/DialogicTextBubbleLayout.gd b/addons/dialogic/Events/DefaultLayouts/TextBubble/DialogicTextBubbleLayout.gd index 71fd5225f..a6f42af80 100644 --- a/addons/dialogic/Events/DefaultLayouts/TextBubble/DialogicTextBubbleLayout.gd +++ b/addons/dialogic/Events/DefaultLayouts/TextBubble/DialogicTextBubbleLayout.gd @@ -57,13 +57,10 @@ func _on_dialog_text_started_revealing_text(): custom_minimum_size.x = min(max_width, longest_line_len) # a margin has to be added vertically as well because of the stylebox custom_minimum_size.y = line_height*min(lines, max_lines) - print(custom_minimum_size) if Dialogic.Choices.is_question(Dialogic.current_event_idx): - print("choice!") custom_minimum_size.y += 80 $DialogText.offset_bottom = -25 - print(custom_minimum_size) # Enable Scroll bar when more then max lines $DialogText.scroll_active = lines > max_lines diff --git a/addons/dialogic/Events/Variable/event_variable.gd b/addons/dialogic/Events/Variable/event_variable.gd index d68e65c2a..27277f79d 100644 --- a/addons/dialogic/Events/Variable/event_variable.gd +++ b/addons/dialogic/Events/Variable/event_variable.gd @@ -41,21 +41,20 @@ func _execute() -> void: var orig :Variant= dialogic.VAR.get_variable(name) if value and orig != null: var the_value :Variant = dialogic.Expression.execute_string(value) - - if operation != Operations.Set and orig.is_valid_float() and value.is_valid_float(): - orig = orig.to_float() - the_value = value.to_float() + if operation != Operations.Set and str(orig).is_valid_float() and str(value).is_valid_float(): + orig = float(orig) + the_value = float(the_value) match operation: Operations.Add: - dialogic.VAR.set_variable(name, str(orig+the_value)) + dialogic.VAR.set_variable(name, orig+the_value) Operations.Substract: - dialogic.VAR.set_variable(name, str(orig-the_value)) + dialogic.VAR.set_variable(name, orig-the_value) Operations.Multiply: - dialogic.VAR.set_variable(name, str(orig*the_value)) + dialogic.VAR.set_variable(name, orig*the_value) Operations.Divide: - dialogic.VAR.set_variable(name, str(orig/the_value)) + dialogic.VAR.set_variable(name, orig/the_value) elif operation == Operations.Set: - dialogic.VAR.set_variable(name, str(the_value)) + dialogic.VAR.set_variable(name, the_value) else: printerr("Dialogic: Set Variable event failed because one value wasn't a float! [", orig, ", ",the_value,"]") else: diff --git a/addons/dialogic/Events/Variable/subsystem_variables.gd b/addons/dialogic/Events/Variable/subsystem_variables.gd index 510735462..a13139bd0 100644 --- a/addons/dialogic/Events/Variable/subsystem_variables.gd +++ b/addons/dialogic/Events/Variable/subsystem_variables.gd @@ -51,7 +51,7 @@ func parse_variables(text:String) -> String: return text -func set_variable(variable_name: String, value: String) -> bool: +func set_variable(variable_name: String, value: Variant) -> bool: variable_name = variable_name.trim_prefix('{').trim_suffix('}') # Getting all the autoloads @@ -87,29 +87,17 @@ func get_variable(variable_path:String, default = null) -> Variant: if variable_path in dialogic.current_state_info['variables'].keys(): return dialogic.current_state_info['variables'][variable_path] - if '.' in variable_path: - var query := variable_path.split('.') - var from := query[0] - var variable = query[1] - for a in autoloads: - if a.name == from: - var myvar :Variant= a.get(variable) - if myvar != null: - return myvar - else: - printerr("Dialogic: Tried accessing non-existant variable '"+variable_path+"'.") - return default - - # if none is found, try getting it from the dialogic variables + else: var value := _get_value_in_dictionary(variable_path, dialogic.current_state_info['variables']) if value != null: return value - else: - printerr("Dialogic: Tried accessing non-existant variable '"+variable_path+"'.") - return default - else: - printerr("Dialogic: Tried accessing non-existant variable '"+variable_path+"'.") - return default + + value = dialogic.Expression.execute_string(variable_path, null) + if value != null: + return value + + printerr("Dialogic: Failed accessing '"+variable_path+"'.") + return default # this will set a value in a dictionary (or a sub-dictionary based on the path) From c969d981b60c9b6c9bd3a70f485df85dac94e46c Mon Sep 17 00:00:00 2001 From: Jowan-Spooner Date: Thu, 23 Mar 2023 00:24:16 +0100 Subject: [PATCH 3/3] Small Improvements You can now escape variables with \ Meaning \{my_variable} will not get replaced. Insert variables also now can contain first level variables allowing stupid shit like: `Here comes a variable {len({MyVariable})}` or `{{Some Variable}+{Some Other Variable}}` - fixed the set random mode for visual editor - fixed more float conversion problems --- .../TimelineEditor/TextEditor/syntax_highlighter.gd | 4 ++-- addons/dialogic/Events/Core/subsystem_expression.gd | 2 +- addons/dialogic/Events/Variable/event_variable.gd | 8 ++++---- addons/dialogic/Events/Variable/subsystem_variables.gd | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/addons/dialogic/Editor/TimelineEditor/TextEditor/syntax_highlighter.gd b/addons/dialogic/Editor/TimelineEditor/TextEditor/syntax_highlighter.gd index 92e5fa354..7cb7fd803 100644 --- a/addons/dialogic/Editor/TimelineEditor/TextEditor/syntax_highlighter.gd +++ b/addons/dialogic/Editor/TimelineEditor/TextEditor/syntax_highlighter.gd @@ -180,9 +180,9 @@ func color_word(dict:Dictionary, color:Color, line:String, word:String, from:int func color_region(dict:Dictionary, color:Color, line:String, start:String, end:String, from:int = 0, to:int = 0) -> Dictionary: if end.is_empty(): - region_regex.compile(start+".*") + region_regex.compile("(? Variant: var regex: RegEx = RegEx.create_from_string('{(\\w.*)}') for res in regex.search_all(string): - var value: String = dialogic.VAR.get_variable(res.get_string()) + var value: String = str(dialogic.VAR.get_variable(res.get_string())) if !value.is_valid_float(): value = '"'+value+'"' string = string.replace(res.get_string(), value) diff --git a/addons/dialogic/Events/Variable/event_variable.gd b/addons/dialogic/Events/Variable/event_variable.gd index 27277f79d..b9d482423 100644 --- a/addons/dialogic/Events/Variable/event_variable.gd +++ b/addons/dialogic/Events/Variable/event_variable.gd @@ -40,8 +40,8 @@ func _execute() -> void: if name: var orig :Variant= dialogic.VAR.get_variable(name) if value and orig != null: - var the_value :Variant = dialogic.Expression.execute_string(value) - if operation != Operations.Set and str(orig).is_valid_float() and str(value).is_valid_float(): + var the_value :Variant = dialogic.VAR.get_variable(value) + if operation != Operations.Set and str(orig).is_valid_float() and str(the_value).is_valid_float(): orig = float(orig) the_value = float(the_value) match operation: @@ -136,9 +136,9 @@ func from_text(string:String) -> void: elif value.begins_with('{') and value.ends_with('}') and value.count('{') == 1: value = result.get_string('value').strip_edges().trim_suffix('}').trim_prefix('{') _value_type = 2 - elif value.begins_with('random('): + elif value.begins_with('range(') and value.ends_with(').pick_random()'): _value_type = 4 - var randinf := str(value).trim_prefix('random(').trim_suffix(')').split(',') + var randinf := str(value).trim_prefix('range(').trim_suffix(').pick_random()').split(',') random_min = int(randinf[0]) random_max = int(randinf[1]) else: diff --git a/addons/dialogic/Events/Variable/subsystem_variables.gd b/addons/dialogic/Events/Variable/subsystem_variables.gd index a13139bd0..1ea59a757 100644 --- a/addons/dialogic/Events/Variable/subsystem_variables.gd +++ b/addons/dialogic/Events/Variable/subsystem_variables.gd @@ -42,8 +42,8 @@ func parse_variables(text:String) -> String: if '{' in text: # Otherwise, why bother? # Trying to extract the curly brackets from the text var regex := RegEx.new() - regex.compile("\\{(?[^{}]*)\\}") - var parsed := text + regex.compile("(?([^{}]|\\{.*\\})*)\\}") + var parsed := text.replace('\\{', '{') for result in regex.search_all(text): var value := get_variable(result.get_string('variable'), "") parsed = parsed.replace("{"+result.get_string('variable')+"}", str(value))