Skip to content

Commit

Permalink
Fix drag preview shape
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
manuq committed Dec 4, 2024
1 parent a50cb31 commit 609d19e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 10 additions & 2 deletions addons/block_code/drag_manager/drag.gd
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func _get_distance_to_snap_point(snap_point: SnapPoint) -> float:
func _update_action_hint():
match action:
DragAction.REMOVE:
_block.modulate = Color(1.0, 1.0, 1.0, 0.5)
_block.modulate = Constants.DRAG_REMOVE_COLOR
_:
_block.modulate = Color.WHITE

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

_preview_block.color = Color(1, 1, 1, 0.5)
_preview_block.color = Constants.DRAG_PREVIEW_COLOR
if _block.definition.type == Types.BlockType.CONTROL:
# Especial case for control block, use statement shape as preview:
_preview_block.block_type = Types.BlockType.STATEMENT
else:
_preview_block.block_type = _block.definition.type
if _block.definition.type == Types.BlockType.VALUE and _block.definition.variant_type == TYPE_BOOL:
_preview_block.is_pointy_value = true

_preview_block.custom_minimum_size = _block.get_global_rect().size / scale
_preview_block.size_flags_horizontal = Control.SIZE_SHRINK_BEGIN
_preview_block.size_flags_vertical = Control.SIZE_SHRINK_BEGIN
Expand Down
2 changes: 2 additions & 0 deletions addons/block_code/ui/constants.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const MINIMUM_DRAG_THRESHOLD = 25
const ROUND_RESOLUTION = 10

const FOCUS_BORDER_COLOR = Color(225, 242, 0)
const DRAG_REMOVE_COLOR = Color(1, 1, 1, 0.5)
const DRAG_PREVIEW_COLOR = Color(225, 242, 0, 0.3)

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

0 comments on commit 609d19e

Please sign in to comment.