fix: multi-cell tile drag snaps by module position, not mouse
_end_drag now calculates the target grid cell from the module's visual top-left position (mouse_pos - grab_offset) instead of the raw mouse position. This prevents multi-cell tiles from jumping an extra cell when grabbed near an edge.
This commit is contained in:
parent
db0c6780df
commit
6aba0e23d0
2 changed files with 10 additions and 5 deletions
|
|
@ -548,15 +548,20 @@ func _end_drag(mouse_pos: Vector2) -> void:
|
|||
_drag_module.modulate = Color(1, 1, 1, 1)
|
||||
|
||||
var d := _get_module_grid_data(_drag_module)
|
||||
var cell_pos := _cell_at_position(mouse_pos)
|
||||
# Calculate target cell from the module's visual position (which already
|
||||
# accounts for the grab offset), not from the raw mouse position.
|
||||
# This ensures multi-cell tiles snap to the grid based on where the
|
||||
# module's top-left would logically land, not where the pointer is.
|
||||
var snap_pos := _drag_module.position + Vector2(_cell_w * 0.5, _cell_h * 0.5)
|
||||
var cell_pos := _cell_at_position(snap_pos)
|
||||
var target_col := cell_pos.x
|
||||
var target_row := cell_pos.y
|
||||
|
||||
# Check if mouse is actually inside the cell bounds
|
||||
# Check if the module's center is actually inside the cell bounds
|
||||
var on_cell := false
|
||||
if _is_valid_cell(target_col, target_row):
|
||||
var cell_ref: PanelContainer = _cells[target_row][target_col]
|
||||
on_cell = Rect2(Vector2.ZERO, cell_ref.size).has_point(mouse_pos - cell_ref.position)
|
||||
on_cell = Rect2(Vector2.ZERO, cell_ref.size).has_point(snap_pos - cell_ref.position)
|
||||
|
||||
if not on_cell or not _is_valid_cell(target_col, target_row):
|
||||
_drop_to_source()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue