Skip to content

Commit

Permalink
Hexagonal parameter block and input
Browse files Browse the repository at this point in the history
I like hexagons!
  • Loading branch information
DoomTas3r committed Oct 22, 2024
1 parent 3472ea1 commit 7be00b6
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 23 deletions.
29 changes: 19 additions & 10 deletions addons/block_code/ui/blocks/parameter_block/parameter_block.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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)
24 changes: 19 additions & 5 deletions addons/block_code/ui/blocks/parameter_block/parameter_block.tscn
Original file line number Diff line number Diff line change
@@ -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"]
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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"]
Expand Down
18 changes: 12 additions & 6 deletions addons/block_code/ui/blocks/utilities/background/background.gd
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,25 @@ 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))

if show_top:
if top_variant == 1:
top_knob.append_array(
[
Vector2(0, 0),
Vector2(5, -4.012612),
Vector2(10, -7.240165),
Vector2(15, -9.822201),
Expand Down Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -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"]

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7be00b6

Please sign in to comment.