finishing up card refactor
This commit is contained in:
parent
cf37714035
commit
c5f0774b3a
|
|
@ -8,7 +8,16 @@ extends PanelContainer
|
|||
#}
|
||||
enum {NAVIGATE, ASSIGN, DRAG}
|
||||
|
||||
var focus_stickies:bool = true
|
||||
var focus_stickies:bool = true:
|
||||
set(stickies):
|
||||
if stickies and sticky_note_container.get_child_count() == 0: return
|
||||
if not current_context == ASSIGN and not focus_stickies == stickies:
|
||||
if stickies:
|
||||
current_sticky_note_id = current_sticky_note_id
|
||||
else:
|
||||
current_dropzone_id = current_dropzone_id
|
||||
|
||||
focus_stickies = stickies
|
||||
|
||||
var has_stage = false:
|
||||
set(focus):
|
||||
|
|
@ -38,7 +47,7 @@ var base_sticky_note_panel: Panel
|
|||
sticky_note_container.get_child(current_sticky_note_id).clear_if_empty()
|
||||
match context:
|
||||
NAVIGATE:
|
||||
pass
|
||||
_return_sticky_notes_to_panels()
|
||||
DRAG:
|
||||
pass
|
||||
ASSIGN:
|
||||
|
|
@ -78,9 +87,14 @@ var mementos_collected: int = 0:
|
|||
|
||||
@onready var current_sticky_note_id: int = 0:
|
||||
set(new_id):
|
||||
if new_id > sticky_note_container.get_child_count() - 1: current_sticky_note_id = 0
|
||||
if sticky_note_container.get_child_count() <= 1: return
|
||||
elif new_id > sticky_note_container.get_child_count() - 1: current_sticky_note_id = 0
|
||||
elif new_id < 0: current_sticky_note_id = sticky_note_container.get_child_count() - 1
|
||||
else: current_sticky_note_id = new_id
|
||||
if current_context == ASSIGN:
|
||||
_return_sticky_notes_to_panels()
|
||||
currently_active_node.preview_sticky_note(sticky_note_container.get_child(current_sticky_note_id).attached_sticky_note)
|
||||
else:
|
||||
currently_active_node = sticky_note_container.get_child(current_sticky_note_id).get_child(1)
|
||||
|
||||
var cache: Array = []
|
||||
|
|
@ -116,19 +130,26 @@ func populate_board(card_names: Array):
|
|||
|
||||
# spawning the cards and adding them to the dictionary
|
||||
for new_card in all_new["cards"]:
|
||||
new_card.position = Vector2(randi_range(dropzone_padding, dropzone_size.x), randi_range(dropzone_padding, dropzone_size.y))
|
||||
insert_area(dropzone, new_card)
|
||||
new_card.set_owner(self)
|
||||
new_card.is_dragable = true
|
||||
add_card(new_card)
|
||||
for new_sticky_note in all_new["sticky_notes"]: # spawning a sticky note
|
||||
var new_panel = base_sticky_note_panel.duplicate()
|
||||
sticky_note_container.add_child(new_panel)
|
||||
new_panel.set_owner(self)
|
||||
new_panel.attatch_sticky_note(new_sticky_note, false)
|
||||
add_sticky_note(new_sticky_note)
|
||||
|
||||
#currently_active_node = area_dict["dropzone_content"][0] # set first Card as currently selected node by default
|
||||
currently_active_node = dropzone.get_child(0)
|
||||
|
||||
func add_card(card: Card):
|
||||
card.reparent(self)
|
||||
card.position = Vector2(randi_range(dropzone_padding, dropzone_size.x), randi_range(dropzone_padding, dropzone_size.y))
|
||||
insert_area(dropzone, card)
|
||||
card.set_owner(self)
|
||||
card.is_dragable = true
|
||||
|
||||
func add_sticky_note(sticky: StickyNote):
|
||||
var new_panel = base_sticky_note_panel.duplicate()
|
||||
sticky_note_container.add_child(new_panel)
|
||||
new_panel.set_owner(self)
|
||||
new_panel.attatch_sticky_note(sticky, false)
|
||||
|
||||
# Checks if a Node is currently inside the dropzone
|
||||
func is_in_dropzone(to_check: Node) -> bool:
|
||||
return dropzone.get_rect().has_point(to_check.global_position)
|
||||
|
|
@ -144,47 +165,48 @@ func handle_mouse_button(to_handle: Area2D, input: InputEvent):
|
|||
currently_active_node = to_handle # update currently selected
|
||||
if input.is_action_pressed("mouse_left"):
|
||||
to_handle.is_dragged = true
|
||||
if to_handle is StickyNote:
|
||||
if not to_handle.on_board:
|
||||
to_handle.reparent(dropzone)
|
||||
to_handle.owner = self
|
||||
current_context = DRAG
|
||||
|
||||
if to_handle is StickyNote:
|
||||
# when user stops dragging
|
||||
if input.is_action_pressed("mouse_right") and current_context == DRAG:
|
||||
focus_stickies = true
|
||||
current_context = NAVIGATE
|
||||
_return_sticky_notes_to_panels()
|
||||
return
|
||||
# when user stops dragging
|
||||
# when Drag stops ...
|
||||
if input.is_action_released("mouse_left"):
|
||||
to_handle.is_dragged = false
|
||||
if to_handle is StickyNote:
|
||||
if is_in_dropzone(to_handle):
|
||||
if to_handle.has_overlapping_areas():
|
||||
for area in to_handle.get_overlapping_areas():
|
||||
if area is Card:
|
||||
focus_stickies = false
|
||||
if area.has_sticky_note_attached():
|
||||
area.exchange_sticky_note_with(to_handle).reparent(dropzone)
|
||||
current_context = ASSIGN
|
||||
|
||||
to_handle = area.exchange_sticky_note_with(to_handle)
|
||||
to_handle.reparent(dropzone)
|
||||
sticky_note_container.get_child(current_sticky_note_id).attached_sticky_note = to_handle
|
||||
current_context = NAVIGATE
|
||||
return
|
||||
else:
|
||||
area.attach_sticky_note(to_handle)
|
||||
if not sticky_note_container.get_child_count() == 0:
|
||||
sticky_note_container.get_child(current_sticky_note_id).clear_if_empty()
|
||||
current_context = NAVIGATE
|
||||
return
|
||||
# when user stops dragging
|
||||
if !is_in_dropzone(to_handle) or input.is_action_pressed("mouse_right"):
|
||||
to_handle.reparent(dropzone)
|
||||
to_handle.on_board = true
|
||||
to_handle.set_owner(self) # needs to be here otherwise the owner disappears
|
||||
current_context = NAVIGATE
|
||||
else:
|
||||
_return_sticky_notes_to_panels()
|
||||
return
|
||||
|
||||
# Handeling any cards and all not yet handled Sticky Notes
|
||||
if input.is_action_released("mouse_left"):
|
||||
## Dropping Cards and Sticky Notes not causing a return condition above.
|
||||
insert_area(dropzone, to_handle)
|
||||
current_context = NAVIGATE
|
||||
focus_stickies = false
|
||||
current_dropzone_id = dropzone.get_children().find(to_handle)
|
||||
if to_handle is StickyNote:
|
||||
to_handle.rotation = to_handle.base_rotation
|
||||
to_handle.scale = to_handle.base_scale
|
||||
current_context = NAVIGATE
|
||||
|
||||
if input.is_action_pressed("mouse_right") and current_context == DRAG:
|
||||
to_handle.reset_drag()
|
||||
|
||||
func _return_sticky_notes_to_panels():
|
||||
for panel in sticky_note_container.get_children():
|
||||
|
|
@ -207,27 +229,29 @@ func is_board_lore() -> bool:
|
|||
|
||||
# Mark area that was hovered over as currently selected
|
||||
func handle_hover(to_handle: Area2D):
|
||||
if to_handle != currently_active_node:
|
||||
currently_active_node.highlighted = false
|
||||
currently_active_node = to_handle
|
||||
|
||||
if is_in_dropzone(to_handle):
|
||||
if to_handle is Card or (to_handle is StickyNote and to_handle.on_board):
|
||||
if is_in_dropzone(to_handle) or to_handle is Card:
|
||||
if not (to_handle is StickyNote and !to_handle.on_board):
|
||||
current_dropzone_id = dropzone.get_children().find(to_handle)
|
||||
focus_stickies = false
|
||||
else:
|
||||
current_sticky_note_id = sticky_note_container.get_children().find(to_handle.attatched_to)
|
||||
current_sticky_note_id = sticky_note_container.get_children().find(to_handle.attached_to)
|
||||
focus_stickies = true
|
||||
|
||||
# Adds a child at the correct child indext in an area
|
||||
func insert_area(parent: Control, node: Area2D):
|
||||
var children = parent.get_children()
|
||||
var children:Array = parent.get_children()
|
||||
var i = 0
|
||||
|
||||
if not node in get_children(): node.reparent(parent)
|
||||
if not node in parent.get_children():
|
||||
node.reparent(parent)
|
||||
node.owner = self
|
||||
|
||||
if children.size() > 0:
|
||||
while children[i].global_position.y > node.global_position.y and i+1 < children.size(): i+=1
|
||||
children.erase(node)
|
||||
while children[i].global_position.y < node.global_position.y and i+1 < children.size():
|
||||
i+=1
|
||||
parent.move_child(node, i)
|
||||
|
||||
# Takes the inputs for control inputs
|
||||
|
|
@ -252,31 +276,46 @@ func _input(event):
|
|||
else:
|
||||
current_dropzone_id += 1
|
||||
|
||||
elif event.is_action_pressed("ui_left"): # left to switch context to the left
|
||||
elif event.is_action_pressed("ui_right"): # left to switch context to the left
|
||||
if not focus_stickies:
|
||||
if current_context == NAVIGATE:
|
||||
focus_stickies = true
|
||||
elif current_context == ASSIGN:
|
||||
current_context = NAVIGATE
|
||||
|
||||
elif event.is_action_pressed("ui_right"): # right to switch context to the right
|
||||
elif event.is_action_pressed("ui_left"): # right to switch context to the right
|
||||
if focus_stickies:
|
||||
if current_context == NAVIGATE:
|
||||
focus_stickies = false
|
||||
elif current_context == ASSIGN:
|
||||
current_context = NAVIGATE
|
||||
|
||||
elif event.is_action_pressed("ui_accept"): # select the selected note it
|
||||
var card:Card = dropzone.get_child(current_dropzone_id)
|
||||
var card:Card
|
||||
if dropzone.get_child(current_dropzone_id) is Card:
|
||||
card = dropzone.get_child(current_dropzone_id)
|
||||
if current_context == ASSIGN: # to assign it to a card
|
||||
if card.has_sticky_note_attached():
|
||||
currently_active_node = card.exchange_sticky_note_with(currently_active_node)
|
||||
current_dropzone_id = find_first_free_card()
|
||||
else:
|
||||
card.attach_sticky_note(currently_active_node)
|
||||
current_context == NAVIGATE
|
||||
card.attach_sticky_note(sticky_note_container.get_child(current_sticky_note_id).attached_sticky_note)
|
||||
current_context = NAVIGATE
|
||||
focus_stickies = false
|
||||
else:
|
||||
if focus_stickies:
|
||||
current_context = ASSIGN
|
||||
current_dropzone_id = find_first_free_card()
|
||||
else:
|
||||
if card.has_sticky_note_attached():
|
||||
if !focus_stickies and card.has_sticky_note_attached():
|
||||
currently_active_node = card.remove_sticky_note()
|
||||
add_sticky_note(currently_active_node)
|
||||
current_dropzone_id = -1
|
||||
else: current_dropzone_id = find_first_free_card()
|
||||
|
||||
current_context = ASSIGN
|
||||
focus_stickies = !focus_stickies
|
||||
if focus_stickies:
|
||||
current_sticky_note_id = current_sticky_note_id
|
||||
else:
|
||||
current_dropzone_id = current_dropzone_id
|
||||
|
||||
|
||||
# move the note it so it floats next to the card where it should be attached
|
||||
func _select_card_for_assigning(sticky_note: Area2D, card: Area2D):
|
||||
|
|
@ -294,3 +333,7 @@ func find_first_free_card() -> int:
|
|||
if !dropzone.get_child((i+current_dropzone_id)%dropzone.get_child_count()).has_sticky_note_attached():
|
||||
return (i+current_dropzone_id)%dropzone.get_child_count()
|
||||
return -1
|
||||
|
||||
func on_sticky_panel_cleared():
|
||||
if current_sticky_note_id == sticky_note_container.get_child_count() - 1:
|
||||
current_sticky_note_id -= 1
|
||||
|
|
|
|||
|
|
@ -155,22 +155,22 @@ func _move_card():
|
|||
position += (get_viewport().get_mouse_position() - position) - mouse_offset
|
||||
|
||||
func has_sticky_note_attached() -> bool:
|
||||
return is_instance_valid(current_sticky_note)
|
||||
return get_child(-1) is Card
|
||||
|
||||
func preview_sticky_note(sticky_note: StickyNote):
|
||||
if has_sticky_note_attached():
|
||||
sticky_note.tween_transform_to(sticky_note_anchor.global_transform + sticky_note.diameter)
|
||||
else:
|
||||
sticky_note.tween_transform_to(sticky_note_anchor.global_transform)
|
||||
sticky_note.reparent(self.get_parent())
|
||||
sticky_note.owner = owner
|
||||
sticky_note.tween_transform_to(Transform2D(0, sticky_note_anchor.global_position + 0 * Vector2(sticky_note.diameter, sticky_note.diameter)))
|
||||
|
||||
func attach_sticky_note(sticky_note: StickyNote) -> bool:
|
||||
if is_instance_valid(current_sticky_note):
|
||||
if has_sticky_note_attached():
|
||||
return false
|
||||
sticky_note.reparent(get_child(3, true))
|
||||
sticky_note.position = Vector2(0,0)
|
||||
sticky_note.reparent(self)
|
||||
sticky_note.owner = self.owner
|
||||
sticky_note.position = sticky_note_anchor.position
|
||||
sticky_note.on_board = false
|
||||
current_sticky_note = sticky_note
|
||||
sticky_note.attatched_to = self
|
||||
sticky_note.attached_to = self
|
||||
return true
|
||||
|
||||
func remove_sticky_note() -> StickyNote:
|
||||
|
|
@ -178,8 +178,9 @@ func remove_sticky_note() -> StickyNote:
|
|||
var former_child:StickyNote = current_sticky_note
|
||||
current_sticky_note = null
|
||||
former_child.reparent(get_parent())
|
||||
former_child.owner = self.owner
|
||||
former_child.on_board = true
|
||||
former_child.attatched_to = null
|
||||
former_child.attached_to = null
|
||||
return former_child
|
||||
|
||||
func exchange_sticky_note_with(new_note: StickyNote) -> StickyNote:
|
||||
|
|
@ -191,3 +192,10 @@ func exchange_sticky_note_with(new_note: StickyNote) -> StickyNote:
|
|||
func check_hover():
|
||||
if is_mouse_entered:
|
||||
_on_mouse_entered()
|
||||
|
||||
func reclaim_sticky_note():
|
||||
current_sticky_note.on_board = false
|
||||
current_sticky_note.tween_transform_to(sticky_note_anchor.global_transform)
|
||||
await current_sticky_note.transform_tween_finished
|
||||
current_sticky_note.reparent(self)
|
||||
current_sticky_note.owner = self.owner
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ class_name PostItPanel
|
|||
extends Panel
|
||||
|
||||
@export var minimum_size:Vector2 = Vector2(400, 100)
|
||||
var attatched_sticky_note: StickyNote
|
||||
var attached_sticky_note: StickyNote
|
||||
@onready var ancor = $"sticky-note_anchor"
|
||||
|
||||
func _ready():
|
||||
|
|
@ -21,30 +21,31 @@ func attatch_sticky_note(attatchment: StickyNote, tween:bool = true):
|
|||
custom_minimum_size = minimum_size
|
||||
ancor.position = Vector2(ancor.position.x, minimum_size.y/2)
|
||||
attatchment.reparent(self)
|
||||
attatched_sticky_note = attatchment
|
||||
attached_sticky_note = attatchment
|
||||
attatchment.owner = self.owner
|
||||
attatchment.attatched_to = self
|
||||
attatchment.attached_to = self
|
||||
attatchment.transform = ancor.transform
|
||||
|
||||
func reclaim_sticky_note():
|
||||
if is_empty():
|
||||
attatched_sticky_note.on_board = false
|
||||
attatched_sticky_note.tween_transform_to(ancor.global_position)
|
||||
await attatched_sticky_note.transform_tween_finished
|
||||
attatched_sticky_note.reparent(self)
|
||||
attatched_sticky_note.owner = self.owner
|
||||
if is_empty() and attached_sticky_note.on_board == true:
|
||||
attached_sticky_note.on_board = false
|
||||
attached_sticky_note.tween_transform_to(ancor.global_transform)
|
||||
await attached_sticky_note.transform_tween_finished
|
||||
attached_sticky_note.reparent(self)
|
||||
attached_sticky_note.owner = self.owner
|
||||
|
||||
func clear_if_empty():
|
||||
if !is_empty(): return
|
||||
if attatched_sticky_note.attatched_to == self: attatched_sticky_note.attatched_to = null
|
||||
if attached_sticky_note.attached_to == self: attached_sticky_note.attached_to = null
|
||||
var height_tween: Tween = create_tween()
|
||||
height_tween.tween_property(self, "custom_minimum_size", Vector2.ZERO, 0.3)
|
||||
await height_tween.finished
|
||||
owner.on_sticky_panel_cleared()
|
||||
self.free()
|
||||
|
||||
func replace_sticky_note_with(new_sticky_note: StickyNote):
|
||||
if is_empty():
|
||||
attatched_sticky_note = new_sticky_note
|
||||
attached_sticky_note = new_sticky_note
|
||||
|
||||
func is_empty() -> bool:
|
||||
return ancor.get_child_count() == 0
|
||||
return get_child_count() == 1
|
||||
|
|
|
|||
|
|
@ -51,12 +51,13 @@ var is_dragged: bool = false:
|
|||
is_dragged = dragged
|
||||
z_index = int(dragged)
|
||||
|
||||
var mouse_offset: Vector2
|
||||
var initial_drag_position: Vector2
|
||||
var mouse_diff: Vector2
|
||||
|
||||
@onready var diameter = $CollisionShape2D.shape.height
|
||||
@export_range(1.0, 10.0) var bounce_speed: float = 8
|
||||
var on_board: bool = false
|
||||
var attatched_to: Node = null
|
||||
var attached_to: Node = null
|
||||
|
||||
func _ready() -> void:
|
||||
|
||||
|
|
@ -86,7 +87,6 @@ func _process(delta: float) -> void:
|
|||
|
||||
_move_sticky_note()
|
||||
|
||||
|
||||
func _on_focus_entered():
|
||||
print(self, "is focused")
|
||||
|
||||
|
|
@ -105,18 +105,17 @@ func _on_mouse_exited():
|
|||
get_parent().check_hover()
|
||||
|
||||
func _on_input_event(viewport, event, shape_idx):
|
||||
if event is InputEventMouseMotion:
|
||||
_move_sticky_note()
|
||||
|
||||
if event is InputEventMouseButton:
|
||||
if event.button_index == MOUSE_BUTTON_LEFT or event.button_index == MOUSE_BUTTON_RIGHT:
|
||||
if "handle_mouse_button" in owner:
|
||||
mouse_offset = (get_viewport().get_mouse_position() - global_position)
|
||||
mouse_diff = get_viewport().get_mouse_position()
|
||||
initial_drag_position = global_position
|
||||
owner.handle_mouse_button(self, event)
|
||||
|
||||
func _move_sticky_note():
|
||||
if is_dragged:
|
||||
position += (get_viewport().get_mouse_position() - position) - mouse_offset
|
||||
position = initial_drag_position + get_viewport().get_mouse_position() - mouse_diff
|
||||
|
||||
func is_sticky_note_attached() -> bool:
|
||||
# there is probably a nicer way to do this
|
||||
|
|
@ -127,3 +126,7 @@ func tween_transform_to(target: Transform2D):
|
|||
transform_tween.tween_property(self, "transform", target, 0.25)
|
||||
await transform_tween.finished
|
||||
emit_signal("transform_tween_finished")
|
||||
|
||||
func reset_drag():
|
||||
if attached_to != null:
|
||||
attached_to.reclaim_sticky_note()
|
||||
|
|
|
|||
|
|
@ -184,7 +184,7 @@ theme = ExtResource("3_mi4ah")
|
|||
theme_type_variation = &"card_text"
|
||||
autowrap_mode = 3
|
||||
|
||||
[node name="sticky_note anchor" type="Node2D" parent="."]
|
||||
[node name="sticky note anchor" type="Node2D" parent="."]
|
||||
position = Vector2(-65.6478, 60.3852)
|
||||
|
||||
[connection signal="input_event" from="." to="." method="_on_input_event"]
|
||||
|
|
|
|||
Loading…
Reference in New Issue