From 3472ea176c45d06d0ecab983f61b0a1be1ef3116 Mon Sep 17 00:00:00 2001 From: Daze Date: Sat, 19 Oct 2024 02:36:34 +0000 Subject: [PATCH] Adds top knob variant, hitbox, and styles entry block --- .../ui/blocks/entry_block/entry_block.gd | 1 + .../ui/blocks/entry_block/entry_block.tscn | 12 ++- .../blocks/utilities/background/background.gd | 73 ++++++++++++++----- .../ui/blocks/utilities/background/gutter.gd | 4 +- 4 files changed, 67 insertions(+), 23 deletions(-) diff --git a/addons/block_code/ui/blocks/entry_block/entry_block.gd b/addons/block_code/ui/blocks/entry_block/entry_block.gd index 22a8b58d..3f8eb703 100644 --- a/addons/block_code/ui/blocks/entry_block/entry_block.gd +++ b/addons/block_code/ui/blocks/entry_block/entry_block.gd @@ -9,6 +9,7 @@ extends StatementBlock func _ready(): super() bottom_snap = null + _background.show_top = true static func get_block_class(): diff --git a/addons/block_code/ui/blocks/entry_block/entry_block.tscn b/addons/block_code/ui/blocks/entry_block/entry_block.tscn index 3419c956..3c0ed713 100644 --- a/addons/block_code/ui/blocks/entry_block/entry_block.tscn +++ b/addons/block_code/ui/blocks/entry_block/entry_block.tscn @@ -19,6 +19,12 @@ layout_mode = 2 mouse_filter = 2 theme_override_constants/separation = 0 +[node name="DragDropArea2" parent="VBoxContainer" instance=ExtResource("3_swkpp")] +custom_minimum_size = Vector2(80, 16) +layout_mode = 2 +size_flags_horizontal = 0 +mouse_default_cursor_shape = 2 + [node name="TopMarginContainer" type="MarginContainer" parent="VBoxContainer"] custom_minimum_size = Vector2(0, 30) layout_mode = 2 @@ -35,7 +41,7 @@ layout_mode = 2 mouse_filter = 1 script = ExtResource("2_yrw8l") color = Color(1, 1, 1, 1) -show_top = false +top_variant = 1 [node name="DragDropArea" parent="VBoxContainer/TopMarginContainer" instance=ExtResource("3_swkpp")] layout_mode = 2 @@ -56,4 +62,8 @@ layout_mode = 2 [node name="SnapPoint" parent="VBoxContainer" instance=ExtResource("4_yj206")] layout_mode = 2 +[node name="MarginContainer" type="MarginContainer" parent="VBoxContainer"] +layout_mode = 2 + +[connection signal="drag_started" from="VBoxContainer/DragDropArea2" to="." method="_on_drag_drop_area_drag_started"] [connection signal="drag_started" from="VBoxContainer/TopMarginContainer/DragDropArea" to="." method="_on_drag_drop_area_drag_started"] diff --git a/addons/block_code/ui/blocks/utilities/background/background.gd b/addons/block_code/ui/blocks/utilities/background/background.gd index ca7ff414..df87d7da 100644 --- a/addons/block_code/ui/blocks/utilities/background/background.gd +++ b/addons/block_code/ui/blocks/utilities/background/background.gd @@ -11,7 +11,7 @@ var parent_block: Block set = _set_color @export var draw_outline: bool = true: - set = _draw_outline + set = _set_draw_outline @export var show_top: bool = true: set = _set_show_top @@ -27,9 +27,13 @@ var parent_block: Block @export var shift_bottom: float = 0.0: set = _set_shift_bottom +## Style of the top knob +@export var top_variant: int = 0: + set = _set_top_variant + ## |0|, \1/, /2/, <3>, >4>, v5v, v6^, \7y, /8y @export var variant: int = 0: - set = _variant + set = _set_variant func _set_color(new_color): @@ -38,7 +42,7 @@ func _set_color(new_color): queue_redraw() -func _draw_outline(new_outline): +func _set_draw_outline(new_outline): draw_outline = new_outline queue_redraw() @@ -63,7 +67,12 @@ func _set_shift_bottom(new_shift_bottom): queue_redraw() -func _variant(new_variant): +func _set_top_variant(new_variant): + top_variant = clamp(new_variant, 0, 1) + queue_redraw() + + +func _set_variant(new_variant): variant = clamp(new_variant, 0, 8) queue_redraw() @@ -75,14 +84,41 @@ func _ready(): func _draw(): + var top_left_align = Constants.KNOB_X + shift_top + var bottom_left_align = Constants.KNOB_X + shift_bottom + var top_knob = [] var fill_polygon: PackedVector2Array fill_polygon.append(Vector2(0.0, 0.0)) if show_top: - fill_polygon.append(Vector2(Constants.KNOB_X + shift_top, 0.0)) - fill_polygon.append(Vector2(Constants.KNOB_X + Constants.KNOB_Z + shift_top, Constants.KNOB_H)) - fill_polygon.append(Vector2(Constants.KNOB_X + Constants.KNOB_Z + Constants.KNOB_W + shift_top, Constants.KNOB_H)) - fill_polygon.append(Vector2(Constants.KNOB_X + Constants.KNOB_Z * 2 + Constants.KNOB_W + shift_top, 0.0)) + if top_variant == 1: + top_knob.append_array( + [ + Vector2(0, 0), + Vector2(5, -4.012612), + Vector2(10, -7.240165), + Vector2(15, -9.822201), + Vector2(20, -11.84718), + Vector2(25, -13.37339), + Vector2(30, -14.43944), + Vector2(35, -15.06994), + Vector2(40, -15.27864), + Vector2(45, -15.06994), + Vector2(50, -14.43944), + Vector2(55, -13.37339), + Vector2(60, -11.84718), + Vector2(65, -9.822201), + Vector2(70, -7.240165), + Vector2(75, -4.012612), + Vector2(80, 0) + ] + ) + else: + top_knob.append(Vector2(top_left_align, 0.0)) + top_knob.append(Vector2(top_left_align + Constants.KNOB_Z, Constants.KNOB_H)) + top_knob.append(Vector2(top_left_align + Constants.KNOB_Z + Constants.KNOB_W, Constants.KNOB_H)) + top_knob.append(Vector2(top_left_align + Constants.KNOB_Z * 2 + Constants.KNOB_W, 0.0)) + fill_polygon.append_array(top_knob) # Right side if variant > 0: @@ -107,10 +143,10 @@ func _draw(): fill_polygon.append(Vector2(size.x, size.y)) if show_bottom: - fill_polygon.append(Vector2(Constants.KNOB_X + Constants.KNOB_Z * 2 + Constants.KNOB_W + shift_bottom, size.y)) - fill_polygon.append(Vector2(Constants.KNOB_X + Constants.KNOB_Z + Constants.KNOB_W + shift_bottom, size.y + Constants.KNOB_H)) - fill_polygon.append(Vector2(Constants.KNOB_X + Constants.KNOB_Z + shift_bottom, size.y + Constants.KNOB_H)) - fill_polygon.append(Vector2(Constants.KNOB_X + shift_bottom, size.y)) + fill_polygon.append(Vector2(bottom_left_align + Constants.KNOB_Z * 2 + Constants.KNOB_W, size.y)) + fill_polygon.append(Vector2(bottom_left_align + Constants.KNOB_Z + Constants.KNOB_W, size.y + Constants.KNOB_H)) + fill_polygon.append(Vector2(bottom_left_align + Constants.KNOB_Z, size.y + Constants.KNOB_H)) + fill_polygon.append(Vector2(bottom_left_align, size.y)) # Left side if variant > 0: @@ -153,10 +189,7 @@ func _draw(): stroke_polygon.append(Vector2(shift_top - (0.0 if not shift_top > 0 else outline_middle), 0.0)) if show_top: - stroke_polygon.append(Vector2(Constants.KNOB_X + shift_top, 0.0)) - stroke_polygon.append(Vector2(Constants.KNOB_X + Constants.KNOB_Z + shift_top, Constants.KNOB_H)) - stroke_polygon.append(Vector2(Constants.KNOB_X + Constants.KNOB_Z + Constants.KNOB_W + shift_top, Constants.KNOB_H)) - stroke_polygon.append(Vector2(Constants.KNOB_X + Constants.KNOB_Z * 2 + Constants.KNOB_W + shift_top, 0.0)) + stroke_polygon.append_array(top_knob) # Right line if variant > 0: @@ -181,10 +214,10 @@ func _draw(): stroke_polygon.append(Vector2(size.x, size.y)) if show_bottom: - stroke_polygon.append(Vector2(Constants.KNOB_X + Constants.KNOB_Z * 2 + Constants.KNOB_W + shift_bottom, size.y)) - stroke_polygon.append(Vector2(Constants.KNOB_X + Constants.KNOB_Z + Constants.KNOB_W + shift_bottom, size.y + Constants.KNOB_H)) - stroke_polygon.append(Vector2(Constants.KNOB_X + Constants.KNOB_Z + shift_bottom, size.y + Constants.KNOB_H)) - stroke_polygon.append(Vector2(Constants.KNOB_X + shift_bottom, size.y)) + stroke_polygon.append(Vector2(bottom_left_align + Constants.KNOB_Z * 2 + Constants.KNOB_W, size.y)) + stroke_polygon.append(Vector2(bottom_left_align + Constants.KNOB_Z + Constants.KNOB_W, size.y + Constants.KNOB_H)) + stroke_polygon.append(Vector2(bottom_left_align + Constants.KNOB_Z, size.y + Constants.KNOB_H)) + stroke_polygon.append(Vector2(bottom_left_align, size.y)) # Left line if variant > 0: diff --git a/addons/block_code/ui/blocks/utilities/background/gutter.gd b/addons/block_code/ui/blocks/utilities/background/gutter.gd index a68c535f..4cf3cfbd 100644 --- a/addons/block_code/ui/blocks/utilities/background/gutter.gd +++ b/addons/block_code/ui/blocks/utilities/background/gutter.gd @@ -12,7 +12,7 @@ var parent_block: Block ## Variant @export var variant: bool = 0: - set = _variant + set = _set_variant func _set_color(new_color): @@ -21,7 +21,7 @@ func _set_color(new_color): queue_redraw() -func _variant(new_variant): +func _set_variant(new_variant): variant = new_variant queue_redraw()