Skip to content

Commit f3c1e45

Browse files
committed
Fix drag preview shape
Previously all blocks had a statement shape as drag preview. Now that we have a good mapping of blocks / shapes, use the corresponding shape. A especial case is the control block which uses the background twice, one for the top part and one for the bottom part. For simplicity, use the statement shape in this case. Also, move drag colors to constants.
1 parent 8ee8da8 commit f3c1e45

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

addons/block_code/drag_manager/drag.gd

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func _get_distance_to_snap_point(snap_point: SnapPoint) -> float:
179179
func _update_action_hint():
180180
match action:
181181
DragAction.REMOVE:
182-
_block.modulate = Color(1.0, 1.0, 1.0, 0.5)
182+
_block.modulate = Constants.DRAG_REMOVE_COLOR
183183
_:
184184
_block.modulate = Color.WHITE
185185

@@ -193,7 +193,15 @@ func _update_preview():
193193
# Make preview block
194194
_preview_block = Background.new()
195195

196-
_preview_block.color = Color(1, 1, 1, 0.5)
196+
_preview_block.color = Constants.DRAG_PREVIEW_COLOR
197+
if _block.definition.type == Types.BlockType.CONTROL:
198+
# Especial case for control block, use statement shape as preview:
199+
_preview_block.block_type = Types.BlockType.STATEMENT
200+
else:
201+
_preview_block.block_type = _block.definition.type
202+
if _block.definition.type == Types.BlockType.VALUE and _block.definition.variant_type == TYPE_BOOL:
203+
_preview_block.is_pointy_value = true
204+
197205
_preview_block.custom_minimum_size = _block.get_global_rect().size / scale
198206
_preview_block.size_flags_horizontal = Control.SIZE_SHRINK_BEGIN
199207
_preview_block.size_flags_vertical = Control.SIZE_SHRINK_BEGIN

addons/block_code/ui/constants.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const MINIMUM_DRAG_THRESHOLD = 25
1313
const ROUND_RESOLUTION = 10
1414

1515
const FOCUS_BORDER_COLOR = Color(225, 242, 0)
16+
const DRAG_REMOVE_COLOR = Color(1, 1, 1, 0.5)
17+
const DRAG_PREVIEW_COLOR = Color(225, 242, 0, 0.3)
1618

1719
## Properties for builtin categories. Order starts at 10 for the first
1820
## category and then are separated by 10 to allow custom categories to

0 commit comments

Comments
 (0)