From 7be00b6cb229a3f069e823ddce47b1b772f31214 Mon Sep 17 00:00:00 2001 From: Daze Date: Sat, 19 Oct 2024 23:08:50 +0000 Subject: [PATCH] Hexagonal parameter block and input MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I like hexagons! --- .../blocks/parameter_block/parameter_block.gd | 29 ++++++++++++------- .../parameter_block/parameter_block.tscn | 24 +++++++++++---- .../blocks/utilities/background/background.gd | 18 ++++++++---- .../parameter_input/parameter_input.gd | 5 +++- .../parameter_input/parameter_input.tscn | 13 ++++++++- 5 files changed, 66 insertions(+), 23 deletions(-) diff --git a/addons/block_code/ui/blocks/parameter_block/parameter_block.gd b/addons/block_code/ui/blocks/parameter_block/parameter_block.gd index f12ebf1b..9a9b952c 100644 --- a/addons/block_code/ui/blocks/parameter_block/parameter_block.gd +++ b/addons/block_code/ui/blocks/parameter_block/parameter_block.gd @@ -6,6 +6,7 @@ const Constants = preload("res://addons/block_code/ui/constants.gd") const Util = preload("res://addons/block_code/ui/util.gd") const ParameterOutput = preload("res://addons/block_code/ui/blocks/utilities/parameter_output/parameter_output.gd") +@onready var _background := $Background @onready var _panel := $Panel var args_to_add_after_format: Dictionary # Only used when loading @@ -18,16 +19,22 @@ var _panel_focus: StyleBox func _ready(): super() - _panel_normal = _panel.get_theme_stylebox("panel").duplicate() - _panel_normal.bg_color = color - _panel_normal.border_color = color.darkened(0.2) + if not definition == null and definition.variant_type == Variant.Type.TYPE_BOOL: + _background.visible = true + _background.variant = 3 + _background.color = color + _panel.visible = false + else: + _panel_normal = _panel.get_theme_stylebox("panel").duplicate() + _panel_normal.bg_color = color + _panel_normal.border_color = color.darkened(0.2) - _panel_focus = _panel.get_theme_stylebox("panel").duplicate() - _panel_focus.bg_color = color - _panel_focus.border_color = Constants.FOCUS_BORDER_COLOR + _panel_focus = _panel.get_theme_stylebox("panel").duplicate() + _panel_focus.bg_color = color + _panel_focus.border_color = Constants.FOCUS_BORDER_COLOR - if not Util.node_is_part_of_edited_scene(self): - _panel.add_theme_stylebox_override("panel", _panel_normal) + if not Util.node_is_part_of_edited_scene(self): + _panel.add_theme_stylebox_override("panel", _panel_normal) func _on_drag_drop_area_drag_started(offset: Vector2) -> void: @@ -43,8 +50,10 @@ static func get_scene_path(): func _on_focus_entered(): - _panel.add_theme_stylebox_override("panel", _panel_focus) + if not definition == null and not definition.variant_type == Variant.Type.TYPE_BOOL: + _panel.add_theme_stylebox_override("panel", _panel_focus) func _on_focus_exited(): - _panel.add_theme_stylebox_override("panel", _panel_normal) + if not definition == null and not definition.variant_type == Variant.Type.TYPE_BOOL: + _panel.add_theme_stylebox_override("panel", _panel_normal) diff --git a/addons/block_code/ui/blocks/parameter_block/parameter_block.tscn b/addons/block_code/ui/blocks/parameter_block/parameter_block.tscn index 4109d0c8..4a822ef6 100644 --- a/addons/block_code/ui/blocks/parameter_block/parameter_block.tscn +++ b/addons/block_code/ui/blocks/parameter_block/parameter_block.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=5 format=3 uid="uid://clipm2dd28jde"] +[gd_scene load_steps=6 format=3 uid="uid://clipm2dd28jde"] [ext_resource type="Script" path="res://addons/block_code/ui/blocks/parameter_block/parameter_block.gd" id="1_0hajy"] [ext_resource type="PackedScene" uid="uid://c7puyxpqcq6xo" path="res://addons/block_code/ui/blocks/utilities/drag_drop_area/drag_drop_area.tscn" id="2_0eadx"] +[ext_resource type="Script" path="res://addons/block_code/ui/blocks/utilities/background/background.gd" id="2_2q1xr"] [ext_resource type="PackedScene" uid="uid://b1xvp3u11h41s" path="res://addons/block_code/ui/blocks/utilities/template_editor/template_editor.tscn" id="3_shl1a"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_dbera"] @@ -14,6 +15,10 @@ corner_radius_top_left = 16 corner_radius_top_right = 16 corner_radius_bottom_right = 16 corner_radius_bottom_left = 16 +expand_margin_left = 2.0 +expand_margin_top = 2.0 +expand_margin_right = 2.0 +expand_margin_bottom = 2.0 [node name="ParameterBlock" type="MarginContainer" node_paths=PackedStringArray("template_editor")] offset_right = 16.0 @@ -24,6 +29,15 @@ mouse_filter = 2 script = ExtResource("1_0hajy") template_editor = NodePath("MarginContainer/TemplateEditor") +[node name="Background" type="Control" parent="."] +unique_name_in_owner = true +visible = false +layout_mode = 2 +script = ExtResource("2_2q1xr") +color = Color(1, 1, 1, 1) +show_top = false +show_bottom = false + [node name="Panel" type="Panel" parent="."] unique_name_in_owner = true layout_mode = 2 @@ -36,15 +50,15 @@ mouse_default_cursor_shape = 2 [node name="MarginContainer" type="MarginContainer" parent="."] layout_mode = 2 mouse_filter = 2 +theme_override_constants/margin_left = 10 +theme_override_constants/margin_top = 6 +theme_override_constants/margin_right = 10 +theme_override_constants/margin_bottom = 6 [node name="TemplateEditor" parent="MarginContainer" instance=ExtResource("3_shl1a")] unique_name_in_owner = true layout_mode = 2 size_flags_horizontal = 0 -theme_override_constants/margin_left = 10 -theme_override_constants/margin_top = 8 -theme_override_constants/margin_right = 10 -theme_override_constants/margin_bottom = 8 [connection signal="focus_entered" from="." to="." method="_on_focus_entered"] [connection signal="focus_exited" from="." to="." method="_on_focus_exited"] diff --git a/addons/block_code/ui/blocks/utilities/background/background.gd b/addons/block_code/ui/blocks/utilities/background/background.gd index df87d7da..7e9cdf17 100644 --- a/addons/block_code/ui/blocks/utilities/background/background.gd +++ b/addons/block_code/ui/blocks/utilities/background/background.gd @@ -78,15 +78,18 @@ func _set_variant(new_variant): func _ready(): + # I think the parent block should get the child but this works parent_block = BlockTreeUtil.get_parent_block(self) - parent_block.focus_entered.connect(queue_redraw) - parent_block.focus_exited.connect(queue_redraw) + + if not parent_block == null: + parent_block.focus_entered.connect(queue_redraw) + parent_block.focus_exited.connect(queue_redraw) func _draw(): var top_left_align = Constants.KNOB_X + shift_top var bottom_left_align = Constants.KNOB_X + shift_bottom - var top_knob = [] + var top_knob: PackedVector2Array var fill_polygon: PackedVector2Array fill_polygon.append(Vector2(0.0, 0.0)) @@ -94,7 +97,6 @@ func _draw(): if top_variant == 1: top_knob.append_array( [ - Vector2(0, 0), Vector2(5, -4.012612), Vector2(10, -7.240165), Vector2(15, -9.822201), @@ -252,5 +254,9 @@ func _draw(): edge_polygon.append(Vector2(0.0, 0.0 - (0.0 if shift_top > 0 else outline_middle))) edge_polygon.append(Vector2(0.0, size.y + (0.0 if shift_bottom > 0 else outline_middle))) - draw_polyline(stroke_polygon, Constants.FOCUS_BORDER_COLOR if parent_block.has_focus() else outline_color, Constants.OUTLINE_WIDTH) - draw_polyline(edge_polygon, Constants.FOCUS_BORDER_COLOR if parent_block.has_focus() else outline_color, Constants.OUTLINE_WIDTH) + if parent_block == null: + draw_polyline(stroke_polygon, outline_color, Constants.OUTLINE_WIDTH) + draw_polyline(edge_polygon, outline_color, Constants.OUTLINE_WIDTH) + else: + draw_polyline(stroke_polygon, Constants.FOCUS_BORDER_COLOR if parent_block.has_focus() else outline_color, Constants.OUTLINE_WIDTH) + draw_polyline(edge_polygon, Constants.FOCUS_BORDER_COLOR if parent_block.has_focus() else outline_color, Constants.OUTLINE_WIDTH) diff --git a/addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.gd b/addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.gd index 29db8b1c..5b93f181 100644 --- a/addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.gd +++ b/addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.gd @@ -21,6 +21,7 @@ var default_value: Variant var _drag_start: Vector2 = Vector2.INF +@onready var _background := %Background @onready var _panel := %Panel @onready var snap_point := %SnapPoint @onready var _input_switcher := %InputSwitcher @@ -216,6 +217,7 @@ func _update_visible_input(): TYPE_VECTOR2: _switch_input(_vector2_input) TYPE_BOOL: + _background.variant = 3 _switch_input(_bool_input) _: _switch_input(_text_input) @@ -224,7 +226,8 @@ func _update_visible_input(): func _switch_input(node: Node): for c in _input_switcher.get_children(): c.visible = c == node - _panel.visible = node not in [_option_input] + _panel.visible = not node == null and node not in [_option_input] and node not in [_bool_input] + _background.visible = node in [_bool_input] func _update_option_input(current_value: Variant = null): diff --git a/addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.tscn b/addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.tscn index 1dd1c812..90ce8368 100644 --- a/addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.tscn +++ b/addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=12 format=3 uid="uid://cjvxs6euc6xbm"] +[gd_scene load_steps=13 format=3 uid="uid://cjvxs6euc6xbm"] [ext_resource type="Script" path="res://addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.gd" id="1_rgmxn"] +[ext_resource type="Script" path="res://addons/block_code/ui/blocks/utilities/background/background.gd" id="2_5dmag"] [ext_resource type="PackedScene" uid="uid://c7puyxpqcq6xo" path="res://addons/block_code/ui/blocks/utilities/drag_drop_area/drag_drop_area.tscn" id="2_05gck"] [ext_resource type="PackedScene" uid="uid://b1oge52xhjqnu" path="res://addons/block_code/ui/blocks/utilities/snap_point/snap_point.tscn" id="2_6esp3"] @@ -41,6 +42,16 @@ grow_vertical = 2 mouse_filter = 2 script = ExtResource("1_rgmxn") +[node name="Background" type="Control" parent="."] +unique_name_in_owner = true +visible = false +layout_mode = 2 +script = ExtResource("2_5dmag") +color = Color(1, 1, 1, 1) +draw_outline = false +show_top = false +show_bottom = false + [node name="Panel" type="Panel" parent="."] unique_name_in_owner = true layout_mode = 2