Skip to content

Commit

Permalink
[CtrlInventoryGridEx] Additional boundary checks
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-kish committed Apr 17, 2024
1 parent f9339a4 commit 82f0ed4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 4 additions & 0 deletions addons/gloot/ui/ctrl_dragable.gd
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ static func get_grab_offset() -> Vector2:
return _grab_offset


static func get_grab_offset_local_to(control: Control) -> Vector2:
return CtrlDragable.get_grab_offset() / control.get_global_transform().get_scale()


func _get_drag_data(at_position: Vector2):
if !_enabled:
return null
Expand Down
8 changes: 4 additions & 4 deletions addons/gloot/ui/ctrl_drop_zone.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ extends Control
signal dragable_dropped(dragable, position)

const CtrlDragable = preload("res://addons/gloot/ui/ctrl_dragable.gd")
const CtrlDropZone = preload("res://addons/gloot/ui/ctrl_drop_zone.gd")


func activate() -> void:
Expand All @@ -24,7 +23,8 @@ func _can_drop_data(at_position: Vector2, data) -> bool:


func _drop_data(at_position: Vector2, data) -> void:
var local_pos := CtrlDragable.get_grab_offset() / get_global_transform().get_scale()
dragable_dropped.emit(data, at_position - local_pos)
CtrlDragable.dragable_dropped.emit(data, self, at_position - local_pos)
var local_offset := CtrlDragable.get_grab_offset_local_to(self)
dragable_dropped.emit(data, at_position - local_offset)
CtrlDragable.dragable_dropped.emit(data, self, at_position - local_offset)


7 changes: 5 additions & 2 deletions addons/gloot/ui/ctrl_inventory_grid_ex.gd
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,13 @@ func _highlight_grabbed_item(style: StyleBox):
_fill_background(field_style, PriorityPanel.StylePriority.LOW)
return

_fill_background(field_style, PriorityPanel.StylePriority.LOW)

var grabbed_item_coords := _ctrl_inventory_grid_basic.get_field_coords(global_grabbed_item_pos + (field_dimensions / 2))
var item_size := inventory.get_item_size(grabbed_item)
var rect := Rect2i(grabbed_item_coords, item_size)
_fill_background(field_style, PriorityPanel.StylePriority.LOW)
if !Rect2i(Vector2i.ZERO, inventory.size).encloses(rect):
return
_set_rect_background(rect, style, PriorityPanel.StylePriority.LOW)


Expand Down Expand Up @@ -375,7 +378,7 @@ func _get_global_grabbed_item() -> InventoryItem:

func _get_global_grabbed_item_local_pos() -> Vector2:
if CtrlDragable.get_grabbed_dragable():
return get_local_mouse_position() - CtrlDragable.get_grab_offset()
return get_local_mouse_position() - CtrlDragable.get_grab_offset_local_to(self)
return Vector2(-1, -1)


Expand Down

0 comments on commit 82f0ed4

Please sign in to comment.