From e45d7d93ba3c488224f6d85129cf4d9dfaa59fd7 Mon Sep 17 00:00:00 2001 From: Daze Date: Sat, 19 Oct 2024 02:36:34 +0000 Subject: [PATCH] Adds top knob variant and styles entry block --- .../ui/blocks/entry_block/entry_block.gd | 1 + .../ui/blocks/entry_block/entry_block.tscn | 2 +- .../blocks/utilities/background/background.gd | 59 ++++++++++++------- .../ui/blocks/utilities/background/gutter.gd | 4 +- 4 files changed, 43 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..ceda9bf9 100644 --- a/addons/block_code/ui/blocks/entry_block/entry_block.tscn +++ b/addons/block_code/ui/blocks/entry_block/entry_block.tscn @@ -35,7 +35,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 diff --git a/addons/block_code/ui/blocks/utilities/background/background.gd b/addons/block_code/ui/blocks/utilities/background/background.gd index ca7ff414..831131bf 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,27 @@ 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: + var radius = size.y * 2 + var clip = 20 + var clip_offset_y = sqrt(abs(pow(radius, 2) - pow(radius - clip, 2))) + + for pixel_x in range(-radius + clip, radius + 1 - clip, 5): + var pixel_y = (-sqrt(abs(pow(radius, 2) - pow(pixel_x, 2)))) + clip_offset_y + top_knob.append(Vector2(pixel_x + (radius - clip), pixel_y)) + 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 +129,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 +175,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 +200,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()