From 51a9b6a3dfdaa9a10c6893cf5381ac920f80b8ce Mon Sep 17 00:00:00 2001 From: j30 <46060104+joaquin30@users.noreply.github.com> Date: Sun, 15 Dec 2024 17:49:29 -0500 Subject: [PATCH] added CollapsableSettings scene and class derived from HBoxContainer, added example in play_sound.tres --- .../block_code/blocks/sounds/play_sound.tres | 2 +- .../template_editor/collapsable_settings.gd | 32 ++++++++++++++++ .../template_editor/collapsable_settings.tscn | 22 +++++++++++ .../utilities/template_editor/minus.png | Bin 0 -> 263 bytes .../template_editor/minus.png.import | 34 +++++++++++++++++ .../blocks/utilities/template_editor/plus.png | Bin 0 -> 273 bytes .../utilities/template_editor/plus.png.import | 34 +++++++++++++++++ .../template_editor/template_editor.gd | 35 ++++++++++++------ 8 files changed, 146 insertions(+), 13 deletions(-) create mode 100644 addons/block_code/ui/blocks/utilities/template_editor/collapsable_settings.gd create mode 100644 addons/block_code/ui/blocks/utilities/template_editor/collapsable_settings.tscn create mode 100644 addons/block_code/ui/blocks/utilities/template_editor/minus.png create mode 100644 addons/block_code/ui/blocks/utilities/template_editor/minus.png.import create mode 100644 addons/block_code/ui/blocks/utilities/template_editor/plus.png create mode 100644 addons/block_code/ui/blocks/utilities/template_editor/plus.png.import diff --git a/addons/block_code/blocks/sounds/play_sound.tres b/addons/block_code/blocks/sounds/play_sound.tres index 72840769..06d6a34a 100644 --- a/addons/block_code/blocks/sounds/play_sound.tres +++ b/addons/block_code/blocks/sounds/play_sound.tres @@ -10,7 +10,7 @@ description = "Play the audio stream with volume and pitch" category = "Sounds" type = 2 variant_type = 0 -display_template = "play the sound {name: STRING} with volume {db: FLOAT} dB and pitch scale {pitch: FLOAT}" +display_template = "play the sound {name: STRING} | with volume {db: FLOAT} dB and pitch scale {pitch: FLOAT}" code_template = "var __sound_node = get_node({name}) __sound_node.volume_db = {db} __sound_node.pitch_scale = {pitch} diff --git a/addons/block_code/ui/blocks/utilities/template_editor/collapsable_settings.gd b/addons/block_code/ui/blocks/utilities/template_editor/collapsable_settings.gd new file mode 100644 index 00000000..b3775d83 --- /dev/null +++ b/addons/block_code/ui/blocks/utilities/template_editor/collapsable_settings.gd @@ -0,0 +1,32 @@ +@tool +class_name CollapsableSettings +extends HBoxContainer + +var collapsed = false + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + collapse() + $CollapseButton.connect("button_up", collapse) + $ExpandButton.connect("button_up", expand) + +func expand() -> void: + if not collapsed: + return + for child in get_children(true): + child.visible = true + $ExpandButton.visible = false + $CollapseButton.visible = true + collapsed = false + +func collapse() -> void: + if collapsed: + return + for child in get_children(true): + child.visible = false + $ExpandButton.visible = true + collapsed = true + +func reorder() -> void: + move_child($ExpandButton, 0) + move_child($CollapseButton, -1) diff --git a/addons/block_code/ui/blocks/utilities/template_editor/collapsable_settings.tscn b/addons/block_code/ui/blocks/utilities/template_editor/collapsable_settings.tscn new file mode 100644 index 00000000..fad628fc --- /dev/null +++ b/addons/block_code/ui/blocks/utilities/template_editor/collapsable_settings.tscn @@ -0,0 +1,22 @@ +[gd_scene load_steps=4 format=3 uid="uid://1xfpd777g8pf"] + +[ext_resource type="Script" path="res://addons/block_code/ui/blocks/utilities/template_editor/collapsable_settings.gd" id="1_f0ssn"] +[ext_resource type="Texture2D" uid="uid://5y2dvf2xc4vx" path="res://addons/block_code/ui/blocks/utilities/template_editor/plus.png" id="2_8s057"] +[ext_resource type="Texture2D" uid="uid://b85dahj52hy0d" path="res://addons/block_code/ui/blocks/utilities/template_editor/minus.png" id="3_6qcv3"] + +[node name="CollapsableSettings" type="HBoxContainer"] +offset_right = 36.0 +offset_bottom = 31.0 +script = ExtResource("1_f0ssn") + +[node name="ExpandButton" type="Button" parent="."] +layout_mode = 2 +icon = ExtResource("2_8s057") +flat = true +icon_alignment = 1 + +[node name="CollapseButton" type="Button" parent="."] +layout_mode = 2 +icon = ExtResource("3_6qcv3") +flat = true +icon_alignment = 1 diff --git a/addons/block_code/ui/blocks/utilities/template_editor/minus.png b/addons/block_code/ui/blocks/utilities/template_editor/minus.png new file mode 100644 index 0000000000000000000000000000000000000000..17bf5ef96971d458605b63366d8240945c549f2a GIT binary patch literal 263 zcmV+i0r>ujP)k87R&oB9h(%fQQcn)Y0MRCD4~i1!xNGk$tD5F5fymu+8jmB$uDT=sRzyT+ z0vYj-vjzl9{dNs2UYc+j2ePhOZR6jcmlsZ{2xrP7$ N002ovPDHLkV1in@Xwv`y literal 0 HcmV?d00001 diff --git a/addons/block_code/ui/blocks/utilities/template_editor/minus.png.import b/addons/block_code/ui/blocks/utilities/template_editor/minus.png.import new file mode 100644 index 00000000..f599e79f --- /dev/null +++ b/addons/block_code/ui/blocks/utilities/template_editor/minus.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://b85dahj52hy0d" +path="res://.godot/imported/minus.png-7cbe293178ea19d9e5fbc8ba50c3a01b.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://addons/block_code/ui/blocks/utilities/template_editor/minus.png" +dest_files=["res://.godot/imported/minus.png-7cbe293178ea19d9e5fbc8ba50c3a01b.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/addons/block_code/ui/blocks/utilities/template_editor/plus.png b/addons/block_code/ui/blocks/utilities/template_editor/plus.png new file mode 100644 index 0000000000000000000000000000000000000000..79b10d4f1e9e4721c9c980c48566c65b821c1010 GIT binary patch literal 273 zcmV+s0q*{ZP)dExn2)eihDTW1@1Bd3*aFfS<~>9gH~s5aaZmvE1Kq`0z0#pG+r&pj(Vc} zEr^J&3S^YOr}fc*k?LqzExGf1;O`BndqC^m?C-k8Re{Xoc-N|#$Bzd99Nz;E0~u}L z8nu+%uV4#t9@trh9{2BzWIIi`hteG;!ee=F;fRr`i-|;HkuANNd5Eo;zMPJjiMHws X1OA{kgaNW-00000NkvXXu0mjfEpT@H literal 0 HcmV?d00001 diff --git a/addons/block_code/ui/blocks/utilities/template_editor/plus.png.import b/addons/block_code/ui/blocks/utilities/template_editor/plus.png.import new file mode 100644 index 00000000..e5df5f29 --- /dev/null +++ b/addons/block_code/ui/blocks/utilities/template_editor/plus.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://5y2dvf2xc4vx" +path="res://.godot/imported/plus.png-415014510d01c9db50069dbfc9e6ab6f.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://addons/block_code/ui/blocks/utilities/template_editor/plus.png" +dest_files=["res://.godot/imported/plus.png-415014510d01c9db50069dbfc9e6ab6f.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/addons/block_code/ui/blocks/utilities/template_editor/template_editor.gd b/addons/block_code/ui/blocks/utilities/template_editor/template_editor.gd index 1d22c7bd..9762e411 100644 --- a/addons/block_code/ui/blocks/utilities/template_editor/template_editor.gd +++ b/addons/block_code/ui/blocks/utilities/template_editor/template_editor.gd @@ -12,6 +12,7 @@ const ParameterInput = preload("res://addons/block_code/ui/blocks/utilities/para const ParameterInputScene = preload("res://addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.tscn") const ParameterOutput = preload("res://addons/block_code/ui/blocks/utilities/parameter_output/parameter_output.gd") const ParameterOutputScene = preload("res://addons/block_code/ui/blocks/utilities/parameter_output/parameter_output.tscn") +const CollapsableSettingsScene = preload("res://addons/block_code/ui/blocks/utilities/template_editor/collapsable_settings.tscn") ## A string describing a block's display format. For example: ## [br] @@ -87,26 +88,36 @@ func _update_from_format_string(): child.queue_free() var match_id = 0 + var is_collapsable = false + var collapsable: CollapsableSettings = CollapsableSettingsScene.instantiate() for item in BlockDefinition.parse_display_template(format_string): + var hidden = item.has("hidden") and item.get("hidden") + if hidden: + is_collapsable = true if item.has("label"): - _append_label(item.get("label")) + _append_label(collapsable if hidden else _container, item.get("label")) elif item.has("in_parameter"): - _append_input_parameter(item.get("in_parameter"), match_id) + _append_input_parameter(collapsable if hidden else _container, item.get("in_parameter"), match_id) elif item.has("out_parameter"): - _append_output_parameter(item.get("out_parameter"), match_id) + _append_output_parameter(collapsable if hidden else _container, item.get("out_parameter"), match_id) elif item.has("const_parameter"): - _append_const_parameter(item.get("const_parameter"), match_id) + _append_const_parameter(collapsable if hidden else _container, item.get("const_parameter"), match_id) match_id += 1 + if is_collapsable: + collapsable.reorder() + _container.add_child(collapsable) + else: + collapsable.queue_free() -func _append_label(label_format: String): +func _append_label(container: Container, label_format: String): var label = Label.new() label.add_theme_color_override("font_color", Color.WHITE) label.text = label_format.strip_edges() - _container.add_child(label) + container.add_child(label) -func _append_input_parameter(parameter: Dictionary, id: int) -> ParameterInput: +func _append_input_parameter(container: Container, parameter: Dictionary, id: int) -> ParameterInput: var default_value = parameter_defaults.get(parameter["name"]) var parameter_input: ParameterInput = ParameterInputScene.instantiate() @@ -125,26 +136,26 @@ func _append_input_parameter(parameter: Dictionary, id: int) -> ParameterInput: parameter_input.modified.connect(func(): modified.emit()) - _container.add_child(parameter_input) + container.add_child(parameter_input) _parameter_inputs_by_name[parameter["name"]] = parameter_input return parameter_input -func _append_output_parameter(parameter: Dictionary, id: int): +func _append_output_parameter(container: Container, parameter: Dictionary, id: int): var parameter_output: ParameterOutput parameter_output = ParameterOutputScene.instantiate() parameter_output.name = "ParameterOutput%d" % id parameter_output.block = parent_block parameter_output.parameter_name = parameter["name"] - _container.add_child(parameter_output) + container.add_child(parameter_output) -func _append_const_parameter(parameter: Dictionary, id: int): +func _append_const_parameter(container: Container, parameter: Dictionary, id: int): # const_parameter is a kind of in_parameter with default value, but never # changes value. - var parameter_const := _append_input_parameter(parameter, id) + var parameter_const := _append_input_parameter(container, parameter, id) parameter_const.visible = false