Skip to content

Commit 8ee8da8

Browse files
DoomTas3rmanuq
authored andcommitted
Pointy shape for booleans
Use a custom background drawing for parameter blocks and input that are of type boolean. #279
1 parent 9a3ea49 commit 8ee8da8

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

addons/block_code/ui/blocks/parameter_block/parameter_block.gd

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ var spawned_by: ParameterOutput
1515
func _ready():
1616
super()
1717
_background.color = color
18+
_update_block_shape()
19+
20+
21+
func _on_definition_changed():
22+
super()
23+
_update_block_shape()
24+
25+
26+
func _update_block_shape():
27+
if not definition:
28+
return
29+
await ready
30+
_background.is_pointy_value = definition.variant_type == TYPE_BOOL
1831

1932

2033
func _on_drag_drop_area_drag_started(offset: Vector2) -> void:

addons/block_code/ui/blocks/parameter_block/parameter_block.tscn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ layout_mode = 2
2020
script = ExtResource("2_oimwh")
2121
color = Color(1, 1, 1, 1)
2222
block_type = 3
23+
is_pointy_value = null
2324

2425
[node name="DragDropArea" parent="." instance=ExtResource("2_0eadx")]
2526
layout_mode = 2

addons/block_code/ui/blocks/utilities/background/background.gd

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ var parent_block: Block
2323
@export var control_part: ControlPart = ControlPart.TOP:
2424
set = _set_control_part
2525

26+
## Only relevant if block_type is VALUE.
27+
@export var is_pointy_value: bool = false:
28+
set = _set_is_pointy_value
29+
2630

2731
func _set_color(new_color):
2832
color = new_color
@@ -40,14 +44,19 @@ func _set_control_part(new_control_part):
4044
queue_redraw()
4145

4246

47+
func _set_is_pointy_value(new_is_pointy_value):
48+
is_pointy_value = new_is_pointy_value
49+
queue_redraw()
50+
51+
4352
func _ready():
4453
parent_block = BlockTreeUtil.get_parent_block(self)
4554
parent_block.focus_entered.connect(queue_redraw)
4655
parent_block.focus_exited.connect(queue_redraw)
4756

4857

4958
func _get_border_color() -> Color:
50-
if parent_block and parent_block.has_focus():
59+
if parent_block.has_focus():
5160
return Constants.FOCUS_BORDER_COLOR
5261
return outline_color
5362

@@ -110,6 +119,24 @@ func _get_statement_shape() -> PackedVector2Array:
110119
return box_shape.slice(0, 1) + top_knob_shape + box_shape.slice(1, 3) + bottom_knob_shape + box_shape.slice(3)
111120

112121

122+
# Note: This is a especial case of _get_round_value_shape() with resolution = 2,
123+
# but it's easier this way.
124+
func _get_pointy_value_shape() -> PackedVector2Array:
125+
var radius_x = min(size.x, size.y) / 2
126+
var radius_y = max(radius_x, size.y / 2)
127+
return PackedVector2Array(
128+
[
129+
Vector2(radius_x, 0),
130+
Vector2(size.x - radius_x, 0),
131+
Vector2(size.x, radius_y),
132+
Vector2(size.x - radius_x, size.y),
133+
Vector2(radius_x, size.y),
134+
Vector2(0, radius_y),
135+
Vector2(radius_x, 0),
136+
]
137+
)
138+
139+
113140
func _get_round_value_shape() -> PackedVector2Array:
114141
# Normally radius_y will be equal to radius_x. But if the block is more vertical
115142
# than horizontal, we'll have to deform the arc shapes.
@@ -201,7 +228,11 @@ func _draw():
201228
fill_polygon = shape
202229
stroke_polygon = shape
203230
Types.BlockType.VALUE:
204-
var shape = _get_round_value_shape()
231+
var shape
232+
if is_pointy_value:
233+
shape = _get_pointy_value_shape()
234+
else:
235+
shape = _get_round_value_shape()
205236
fill_polygon = shape
206237
stroke_polygon = shape
207238
Types.BlockType.CONTROL:

addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.gd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ func _update_visible_input():
223223
func _switch_input(node: Node):
224224
for c in _input_switcher.get_children():
225225
c.visible = c == node
226-
_background.visible = node not in [_option_input]
226+
_background.visible = node not in [_option_input, null]
227+
_background.is_pointy_value = node == _bool_input
227228

228229

229230
func _update_option_input(current_value: Variant = null):

0 commit comments

Comments
 (0)