From 4a0eddf3e9d5980282aa3f357e36dbe411a6963f Mon Sep 17 00:00:00 2001 From: Adrian Schmid Date: Sat, 1 Jul 2023 16:03:22 +0200 Subject: [PATCH] add logic to attach post-its to cards --- src/logic-scenes/board/card-board.gd | 14 +++++++++++--- src/logic-scenes/board/card.gd | 3 +++ src/logic-scenes/board/physics-board.tscn | 10 +++++----- src/logic-scenes/board/post-it.gd | 3 +++ 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/logic-scenes/board/card-board.gd b/src/logic-scenes/board/card-board.gd index a0d5253..ee4aa32 100644 --- a/src/logic-scenes/board/card-board.gd +++ b/src/logic-scenes/board/card-board.gd @@ -49,7 +49,7 @@ func is_in_dropzone(to_check: Node) -> bool: else: 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. # 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) # TODO: Add function to rearrange the array based on positions in the dropzone 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"]: if panel.get_child_count() == 1: to_handle.reparent(panel) @@ -91,7 +99,7 @@ func handle_mouse_button(to_handle: Node, input: InputEvent, dragableType: int): to_handle.position = panel.get_child(0).position break currently_dragged_area = null - + diff --git a/src/logic-scenes/board/card.gd b/src/logic-scenes/board/card.gd index 7347684..13ca4cf 100644 --- a/src/logic-scenes/board/card.gd +++ b/src/logic-scenes/board/card.gd @@ -52,6 +52,9 @@ var scale_tween var is_dragged: bool = false func _ready(): + + self.set_meta("type", "card") # set type information to find out if this node is a card + _handle_wiggle(0) if not Engine.is_editor_hint() and is_inside_tree(): for postit in self.get_children(): diff --git a/src/logic-scenes/board/physics-board.tscn b/src/logic-scenes/board/physics-board.tscn index b3ba118..d419f00 100644 --- a/src/logic-scenes/board/physics-board.tscn +++ b/src/logic-scenes/board/physics-board.tscn @@ -40,13 +40,13 @@ mouse_filter = 1 [node name="card3" parent="HBoxContainer/dropzone" instance=ExtResource("3_mg053")] z_as_relative = false position = Vector2(371, 290) -rotation = -0.0292664 +rotation = 0.00381354 collision_layer = 2147483649 is_dragable = true [node name="card" parent="HBoxContainer/dropzone" instance=ExtResource("3_mg053")] position = Vector2(640, 659) -rotation = -0.0217244 +rotation = -0.0287091 is_dragable = true [node name="ScrollContainer" type="ScrollContainer" parent="HBoxContainer"] @@ -123,7 +123,7 @@ shape = SubResource("CircleShape2D_x8rl2") position = Vector2(-151, -107) [node name="card2" parent="Node2D/RigidBody2D/ancor" instance=ExtResource("3_mg053")] -rotation = 0.00128374 +rotation = -0.0498721 collision_layer = 2 [node name="RigidBody2D2" type="Area2D" parent="Node2D"] @@ -137,7 +137,7 @@ shape = SubResource("CircleShape2D_x8rl2") position = Vector2(-151, -107) [node name="card2" parent="Node2D/RigidBody2D2/ancor" instance=ExtResource("3_mg053")] -rotation = 0.0767116 +rotation = -0.0210958 collision_layer = 2 [node name="RigidBody2D3" type="Area2D" parent="Node2D"] @@ -151,5 +151,5 @@ shape = SubResource("CircleShape2D_x8rl2") position = Vector2(-151, -107) [node name="card2" parent="Node2D/RigidBody2D3/ancor" instance=ExtResource("3_mg053")] -rotation = 0.00437383 +rotation = -0.00481569 collision_layer = 2 diff --git a/src/logic-scenes/board/post-it.gd b/src/logic-scenes/board/post-it.gd index 4c5c7e8..08a82a9 100644 --- a/src/logic-scenes/board/post-it.gd +++ b/src/logic-scenes/board/post-it.gd @@ -49,6 +49,9 @@ var modulate_tween var is_dragged = false 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/BackgroundSprite.frame = text.hash() % $Content/BackgroundSprite.sprite_frames.get_frame_count($Content/BackgroundSprite.animation)