add logic to attach post-its to cards

This commit is contained in:
Adrian Schmid 2023-07-01 16:03:22 +02:00
parent ca65c69fdc
commit 4a0eddf3e9
4 changed files with 22 additions and 8 deletions

View File

@ -49,7 +49,7 @@ func is_in_dropzone(to_check: Node) -> bool:
else: else:
return true return true
func handle_mouse_button(to_handle: Node, input: InputEvent, dragableType: int): func handle_mouse_button(to_handle: Area2D, input: InputEvent, dragableType: int):
# No two areas can be dragged at the same time. # No two areas can be dragged at the same time.
# Make sure that only the same area is dragged. # Make sure that only the same area is dragged.
@ -80,7 +80,15 @@ func handle_mouse_button(to_handle: Node, input: InputEvent, dragableType: int):
area_dict["dropzone_content"].push_back(to_handle) area_dict["dropzone_content"].push_back(to_handle)
# TODO: Add function to rearrange the array based on positions in the dropzone # TODO: Add function to rearrange the array based on positions in the dropzone
else: else:
if !is_in_dropzone(to_handle): if is_in_dropzone(to_handle):
if to_handle.has_overlapping_areas():
var overlaps = to_handle.get_overlapping_areas()
for area in overlaps:
if area.get_meta("type") == "card":
to_handle.reparent(area)
to_handle.set_owner(self)
to_handle.position = area.get_child(3).position
else:
for panel in area_dict["post_it_panels"]: for panel in area_dict["post_it_panels"]:
if panel.get_child_count() == 1: if panel.get_child_count() == 1:
to_handle.reparent(panel) to_handle.reparent(panel)

View File

@ -52,6 +52,9 @@ var scale_tween
var is_dragged: bool = false var is_dragged: bool = false
func _ready(): func _ready():
self.set_meta("type", "card") # set type information to find out if this node is a card
_handle_wiggle(0) _handle_wiggle(0)
if not Engine.is_editor_hint() and is_inside_tree(): if not Engine.is_editor_hint() and is_inside_tree():
for postit in self.get_children(): for postit in self.get_children():

View File

@ -40,13 +40,13 @@ mouse_filter = 1
[node name="card3" parent="HBoxContainer/dropzone" instance=ExtResource("3_mg053")] [node name="card3" parent="HBoxContainer/dropzone" instance=ExtResource("3_mg053")]
z_as_relative = false z_as_relative = false
position = Vector2(371, 290) position = Vector2(371, 290)
rotation = -0.0292664 rotation = 0.00381354
collision_layer = 2147483649 collision_layer = 2147483649
is_dragable = true is_dragable = true
[node name="card" parent="HBoxContainer/dropzone" instance=ExtResource("3_mg053")] [node name="card" parent="HBoxContainer/dropzone" instance=ExtResource("3_mg053")]
position = Vector2(640, 659) position = Vector2(640, 659)
rotation = -0.0217244 rotation = -0.0287091
is_dragable = true is_dragable = true
[node name="ScrollContainer" type="ScrollContainer" parent="HBoxContainer"] [node name="ScrollContainer" type="ScrollContainer" parent="HBoxContainer"]
@ -123,7 +123,7 @@ shape = SubResource("CircleShape2D_x8rl2")
position = Vector2(-151, -107) position = Vector2(-151, -107)
[node name="card2" parent="Node2D/RigidBody2D/ancor" instance=ExtResource("3_mg053")] [node name="card2" parent="Node2D/RigidBody2D/ancor" instance=ExtResource("3_mg053")]
rotation = 0.00128374 rotation = -0.0498721
collision_layer = 2 collision_layer = 2
[node name="RigidBody2D2" type="Area2D" parent="Node2D"] [node name="RigidBody2D2" type="Area2D" parent="Node2D"]
@ -137,7 +137,7 @@ shape = SubResource("CircleShape2D_x8rl2")
position = Vector2(-151, -107) position = Vector2(-151, -107)
[node name="card2" parent="Node2D/RigidBody2D2/ancor" instance=ExtResource("3_mg053")] [node name="card2" parent="Node2D/RigidBody2D2/ancor" instance=ExtResource("3_mg053")]
rotation = 0.0767116 rotation = -0.0210958
collision_layer = 2 collision_layer = 2
[node name="RigidBody2D3" type="Area2D" parent="Node2D"] [node name="RigidBody2D3" type="Area2D" parent="Node2D"]
@ -151,5 +151,5 @@ shape = SubResource("CircleShape2D_x8rl2")
position = Vector2(-151, -107) position = Vector2(-151, -107)
[node name="card2" parent="Node2D/RigidBody2D3/ancor" instance=ExtResource("3_mg053")] [node name="card2" parent="Node2D/RigidBody2D3/ancor" instance=ExtResource("3_mg053")]
rotation = 0.00437383 rotation = -0.00481569
collision_layer = 2 collision_layer = 2

View File

@ -49,6 +49,9 @@ var modulate_tween
var is_dragged = false var is_dragged = false
func _ready() -> void: func _ready() -> void:
self.set_meta("type", "post-it") # set type information to find out if this node is a post-it
$Content/Label.text = self.text $Content/Label.text = self.text
$Content/BackgroundSprite.frame = text.hash() % $Content/BackgroundSprite.sprite_frames.get_frame_count($Content/BackgroundSprite.animation) $Content/BackgroundSprite.frame = text.hash() % $Content/BackgroundSprite.sprite_frames.get_frame_count($Content/BackgroundSprite.animation)