fix: can now attach notes
This commit is contained in:
parent
a992ef476d
commit
2164c2e1fc
|
|
@ -204,14 +204,13 @@ func is_in_dropzone(to_check: Draggable) -> bool:
|
||||||
|
|
||||||
# Called by notes when a mouse event needs handling
|
# Called by notes when a mouse event needs handling
|
||||||
func handle_mouse_button(input: InputEventMouseButton, target: Draggable) -> void:
|
func handle_mouse_button(input: InputEventMouseButton, target: Draggable) -> void:
|
||||||
|
|
||||||
# === DRAG START ===
|
# === DRAG START ===
|
||||||
if input.button_index == MOUSE_BUTTON_LEFT and input.is_pressed():
|
if input.button_index == MOUSE_BUTTON_LEFT and input.is_pressed():
|
||||||
_start_drag(target)
|
_start_drag(target)
|
||||||
return
|
return
|
||||||
|
|
||||||
# === DRAG END ===
|
# === DRAG END ===
|
||||||
if input.button_index == MOUSE_BUTTON_LEFT and not input.is_released():
|
if input.button_index == MOUSE_BUTTON_LEFT and input.is_released():
|
||||||
_end_drag(target)
|
_end_drag(target)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -220,7 +219,6 @@ func handle_mouse_button(input: InputEventMouseButton, target: Draggable) -> voi
|
||||||
func _start_drag(draggable: Draggable) -> void:
|
func _start_drag(draggable: Draggable) -> void:
|
||||||
selection = draggable
|
selection = draggable
|
||||||
current_context = DRAG
|
current_context = DRAG
|
||||||
|
|
||||||
var mouse_offset := get_viewport().get_mouse_position() - draggable.global_position
|
var mouse_offset := get_viewport().get_mouse_position() - draggable.global_position
|
||||||
draggable.start_drag(mouse_offset)
|
draggable.start_drag(mouse_offset)
|
||||||
|
|
||||||
|
|
@ -234,28 +232,44 @@ func _end_drag(draggable: Draggable) -> void:
|
||||||
|
|
||||||
var destination := draggable.end_drag()
|
var destination := draggable.end_drag()
|
||||||
|
|
||||||
if not destination and draggable is StickyNote:
|
# Handle sticky note drops
|
||||||
# reclaim if necessary
|
if draggable is StickyNote:
|
||||||
pass
|
var sticky := draggable as StickyNote
|
||||||
|
|
||||||
if destination and destination is Card:
|
# If dropped on a card, attach it
|
||||||
# attach / unattach
|
if destination and destination is Card:
|
||||||
pass
|
var target_card := destination as Card
|
||||||
|
|
||||||
if destination and destination is StickyNote:
|
# If sticky was previously attached to a different card, detach it first
|
||||||
# unattach and attach to parent
|
if sticky.is_attached and sticky.attached_to != target_card:
|
||||||
pass
|
sticky.attached_to.remove_sticky_note()
|
||||||
|
|
||||||
# Let draggable find its own drop target
|
# If target card already has a sticky, exchange them
|
||||||
#var drop_target := draggable.find_drop_target()
|
if target_card.has_sticky_note_attached():
|
||||||
|
var exchanged_sticky := target_card.exchange_sticky_note_with(sticky)
|
||||||
|
# Reclaim the exchanged sticky to the board
|
||||||
|
if exchanged_sticky:
|
||||||
|
reclaim_sticky(exchanged_sticky)
|
||||||
|
else:
|
||||||
|
# Simple attach
|
||||||
|
sticky.reparent(target_card)
|
||||||
|
target_card.attach_sticky_note(sticky)
|
||||||
|
|
||||||
# Execute the drop
|
# If dropped on board (no destination), ensure it's a child of the board
|
||||||
#if drop_target and Draggable.is_drop_target(drop_target):
|
elif not destination:
|
||||||
# var result = drop_target.handle_drop(draggable)
|
# If it was attached to a card, detach it first
|
||||||
# pass
|
if sticky.is_attached:
|
||||||
|
sticky.attached_to.remove_sticky_note()
|
||||||
|
|
||||||
# Check win condition if sticky was attached to card
|
# Make sure sticky is parented to board
|
||||||
if draggable is StickyNote and draggable.is_attached:
|
if sticky.get_parent() != self:
|
||||||
|
sticky.reparent(self)
|
||||||
|
|
||||||
|
# Ensure it's in the notes array
|
||||||
|
if not sticky in notes:
|
||||||
|
notes.append(sticky)
|
||||||
|
|
||||||
|
# Check win condition after any sticky movement
|
||||||
check_board_completion()
|
check_board_completion()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -145,8 +145,6 @@ func init(card_name: String = "card", own_id:StringName = "-1") -> void:
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
super._ready()
|
super._ready()
|
||||||
input_event.connect(_on_input_event)
|
|
||||||
|
|
||||||
_handle_wiggle(0)
|
_handle_wiggle(0)
|
||||||
_on_text_updated.call_deferred()
|
_on_text_updated.call_deferred()
|
||||||
|
|
||||||
|
|
@ -192,11 +190,6 @@ func _handle_wiggle(delta):
|
||||||
rotation = noise.get_noise_1d(wiggle_pos)*wiggle_strength
|
rotation = noise.get_noise_1d(wiggle_pos)*wiggle_strength
|
||||||
|
|
||||||
|
|
||||||
func _input(event: InputEvent) -> void:
|
|
||||||
if event is InputEventMouseButton:
|
|
||||||
if event.button_index == MOUSE_BUTTON_LEFT and not event.pressed:
|
|
||||||
is_dragged = false
|
|
||||||
|
|
||||||
func _on_mouse_entered() -> void:
|
func _on_mouse_entered() -> void:
|
||||||
super._on_mouse_entered()
|
super._on_mouse_entered()
|
||||||
|
|
||||||
|
|
@ -205,12 +198,6 @@ func _on_mouse_exited():
|
||||||
if burn_state == burned.SINGED:
|
if burn_state == burned.SINGED:
|
||||||
burn_state = burned.NOT
|
burn_state = burned.NOT
|
||||||
|
|
||||||
func _on_input_event(_viewport, event, _shape_idx):
|
|
||||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
|
|
||||||
if highlighted:
|
|
||||||
mouse_offset = get_viewport().get_mouse_position() - position
|
|
||||||
if _get_board(): _get_board().handle_mouse_button(event, self)
|
|
||||||
|
|
||||||
func _move_card():
|
func _move_card():
|
||||||
if is_dragged:
|
if is_dragged:
|
||||||
update_drag_position(get_viewport().get_mouse_position())
|
update_drag_position(get_viewport().get_mouse_position())
|
||||||
|
|
@ -258,9 +245,12 @@ func remove_sticky_note() -> StickyNote:
|
||||||
return former_child
|
return former_child
|
||||||
|
|
||||||
func exchange_sticky_note_with(new_note: StickyNote) -> StickyNote:
|
func exchange_sticky_note_with(new_note: StickyNote) -> StickyNote:
|
||||||
var tmp := remove_sticky_note()
|
if new_note == get_attached_sticky_note():
|
||||||
|
return null
|
||||||
|
|
||||||
|
var old_note := remove_sticky_note()
|
||||||
attach_sticky_note(new_note)
|
attach_sticky_note(new_note)
|
||||||
return tmp
|
return old_note
|
||||||
|
|
||||||
|
|
||||||
# === DROP TARGET PATTERN IMPLEMENTATION ===
|
# === DROP TARGET PATTERN IMPLEMENTATION ===
|
||||||
|
|
@ -297,7 +287,7 @@ func handle_drop(draggable: StickyNote) -> int:
|
||||||
## Retrieves the sticky that was exchanged during last drop
|
## Retrieves the sticky that was exchanged during last drop
|
||||||
## Clears the reference after retrieval
|
## Clears the reference after retrieval
|
||||||
func get_last_exchanged_sticky() -> StickyNote:
|
func get_last_exchanged_sticky() -> StickyNote:
|
||||||
var result = _last_exchanged_sticky
|
var result := _last_exchanged_sticky
|
||||||
_last_exchanged_sticky = null
|
_last_exchanged_sticky = null
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
@ -307,15 +297,3 @@ func get_last_exchanged_sticky() -> StickyNote:
|
||||||
## Cards always drop back to board dropzone
|
## Cards always drop back to board dropzone
|
||||||
func find_drop_target() -> Node:
|
func find_drop_target() -> Node:
|
||||||
return _get_board()
|
return _get_board()
|
||||||
|
|
||||||
|
|
||||||
# === HELPER FUNCTIONS ===
|
|
||||||
|
|
||||||
## Walks up the scene tree to find the CardBoard
|
|
||||||
func _get_board() -> CardBoard:
|
|
||||||
var node := get_parent()
|
|
||||||
while node:
|
|
||||||
if node is CardBoard:
|
|
||||||
return node
|
|
||||||
node = node.get_parent()
|
|
||||||
return null
|
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ var _drag_source: Node = null # Where the drag started from
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
mouse_entered.connect(_on_mouse_entered)
|
mouse_entered.connect(_on_mouse_entered)
|
||||||
mouse_exited.connect(_on_mouse_exited)
|
mouse_exited.connect(_on_mouse_exited)
|
||||||
|
input_event.connect(_on_input_event)
|
||||||
|
|
||||||
|
|
||||||
func _get_hover_handler() -> Node:
|
func _get_hover_handler() -> Node:
|
||||||
|
|
@ -51,6 +52,16 @@ func _get_hover_handler() -> Node:
|
||||||
parent = parent.get_parent()
|
parent = parent.get_parent()
|
||||||
return parent
|
return parent
|
||||||
|
|
||||||
|
|
||||||
|
## Walks up the scene tree to find the CardBoard
|
||||||
|
func _get_board() -> Node:
|
||||||
|
var node := get_parent()
|
||||||
|
while node:
|
||||||
|
if node.has_method("handle_mouse_button"):
|
||||||
|
return node
|
||||||
|
node = node.get_parent()
|
||||||
|
return null
|
||||||
|
|
||||||
## === DRAG LIFECYCLE METHODS ===
|
## === DRAG LIFECYCLE METHODS ===
|
||||||
## Override these in Card and StickyNote for specific behavior
|
## Override these in Card and StickyNote for specific behavior
|
||||||
|
|
||||||
|
|
@ -68,6 +79,28 @@ func _on_mouse_exited() -> void:
|
||||||
if handler: handler.handle_hover(self)
|
if handler: handler.handle_hover(self)
|
||||||
|
|
||||||
|
|
||||||
|
## Handles global input events (used to catch mouse release during drag)
|
||||||
|
func _input(event: InputEvent) -> void:
|
||||||
|
if event is InputEventMouseButton:
|
||||||
|
if event.button_index == MOUSE_BUTTON_LEFT and not event.pressed:
|
||||||
|
if is_dragged:
|
||||||
|
is_dragged = false
|
||||||
|
# Trigger the drop logic
|
||||||
|
var board := _get_board()
|
||||||
|
if board and board.has_method("_end_drag"):
|
||||||
|
board._end_drag(self)
|
||||||
|
|
||||||
|
|
||||||
|
## Handles input events on this Area2D (used to start drag)
|
||||||
|
func _on_input_event(_viewport, event, _shape_idx):
|
||||||
|
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
|
||||||
|
if highlighted:
|
||||||
|
var mouse_offset := get_viewport().get_mouse_position() - position
|
||||||
|
var board := _get_board()
|
||||||
|
if board and board.has_method("handle_mouse_button"):
|
||||||
|
board.handle_mouse_button(event, self)
|
||||||
|
|
||||||
|
|
||||||
## Starts a drag operation
|
## Starts a drag operation
|
||||||
func start_drag(mouse_offset: Vector2) -> void:
|
func start_drag(mouse_offset: Vector2) -> void:
|
||||||
_drag_start_position = global_position
|
_drag_start_position = global_position
|
||||||
|
|
|
||||||
|
|
@ -150,11 +150,14 @@ func _find_drop_target() -> Node:
|
||||||
if area is StickyNote and not area.is_attached: continue # Can only drop on attached stickies
|
if area is StickyNote and not area.is_attached: continue # Can only drop on attached stickies
|
||||||
|
|
||||||
if area is Card:
|
if area is Card:
|
||||||
if (not closest) or ((closest.position-position).length() < (area.position - position).length()):
|
if (not closest) or ((area.position - position).length() < (closest.position - position).length()):
|
||||||
closest = area
|
closest = area
|
||||||
return area
|
|
||||||
|
|
||||||
# Priority 3: Default to board (stay loose in dropzone)
|
# Return the closest card if found
|
||||||
|
if closest:
|
||||||
|
return closest
|
||||||
|
|
||||||
|
# Priority 2: Default to board (stay loose in dropzone)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
## Find the nearest panel that can accept this sticky
|
## Find the nearest panel that can accept this sticky
|
||||||
|
|
|
||||||
|
|
@ -7,3 +7,4 @@ func play() -> void:
|
||||||
|
|
||||||
func handle_hover(area: Draggable):
|
func handle_hover(area: Draggable):
|
||||||
prints("Playable[base].handle_hover", area, area.name)
|
prints("Playable[base].handle_hover", area, area.name)
|
||||||
|
pass
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue