Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion addons/card_3d/scripts/card_collection_3d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ signal mouse_exit_drop_zone()
signal card_selected(card)
signal card_clicked(card)
signal card_added(card)
signal card_moved(card,from,to)


const _DEFAULT_DROP_ZONE_SHAPE_3D: Shape3D = preload("res://addons/card_3d/shapes_3d/default_card_collection_3d_drop_zone_shape_3d.tres")
const _DEFAULT_DROP_ZONE_Z_OFFSET: float = 1.6
Expand Down Expand Up @@ -98,7 +100,7 @@ func remove_card(index: int) -> Card3D:

remove_child(removed_card)
apply_card_layout()

removed_card.card_3d_mouse_down.disconnect(_on_card_pressed.bind(removed_card))
removed_card.card_3d_mouse_up.disconnect(_on_card_clicked.bind(removed_card))
removed_card.card_3d_mouse_over.disconnect(_on_card_hover.bind(removed_card))
Expand All @@ -124,6 +126,19 @@ func remove_all() -> Array[Card3D]:

return cards_to_return

func move_card(card_to_move: Card3D, new_index: int) -> void:
var current_index: int = card_indicies[card_to_move]

cards.remove_at(current_index)
cards.insert(new_index, card_to_move)

var from = min(current_index, new_index)
var to = max(current_index, new_index) + 1
for i in range(from, to):
card_indicies[cards[i]] = i

apply_card_layout()
card_moved.emit(card_to_move,current_index,new_index)

func apply_card_layout():
card_layout_strategy.update_card_positions(cards, card_move_tween_duration)
Expand Down
3 changes: 1 addition & 2 deletions addons/card_3d/scripts/drag_controller.gd
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ func _return_card_to_collection(mouse_position: Vector2):
new_index = clamp(new_index, 0, _drag_from_collection.cards.size() - 1)

if current_index != new_index:
_drag_from_collection.remove_card(current_index)
_drag_from_collection.insert_card(_dragging_card, new_index)
_drag_from_collection.move_card(_dragging_card,new_index)
card_moved.emit(_dragging_card, _drag_from_collection, _drag_from_collection, current_index, new_index)

_drag_from_collection.apply_card_layout()
Expand Down