From 27d3497fdece430dae5fa2361c637c7fd4a756e0 Mon Sep 17 00:00:00 2001 From: Adrian Schmid Date: Sat, 1 Jul 2023 13:41:19 +0200 Subject: [PATCH 01/13] set anchor for post-it on card --- src/logic-scenes/board/card.tscn | 12 ++++-------- src/logic-scenes/board/physics-board.tscn | 12 ++++++------ src/logic-scenes/board/post-it.tscn | 1 - 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/logic-scenes/board/card.tscn b/src/logic-scenes/board/card.tscn index 89f6a60..6c28017 100644 --- a/src/logic-scenes/board/card.tscn +++ b/src/logic-scenes/board/card.tscn @@ -146,7 +146,7 @@ func _process(_delta): " [node name="card" type="Area2D"] -rotation = -0.0714123 +rotation = 0.00585123 script = ExtResource("1_emip0") [node name="CollisionShape2D" type="CollisionShape2D" parent="."] @@ -158,6 +158,7 @@ shape = SubResource("CapsuleShape2D_foovg") clip_children = 2 scale = Vector2(0.6, 0.6) sprite_frames = SubResource("SpriteFrames_ckivt") +frame = 1 script = SubResource("GDScript_8bs16") [node name="GPUParticles2D" type="GPUParticles2D" parent="BackgroundSprite"] @@ -194,13 +195,8 @@ theme = ExtResource("3_rktsa") theme_type_variation = &"card_text" autowrap_mode = 3 -[node name="postit anchor" type="Control" parent="."] -layout_mode = 3 -anchors_preset = 0 -offset_left = 100.0 -offset_top = 148.0 -offset_right = 140.0 -offset_bottom = 188.0 +[node name="postit anchor" type="Node2D" parent="."] +position = Vector2(-65.6478, 60.3852) [connection signal="input_event" from="." to="." method="_on_input_event"] [connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"] diff --git a/src/logic-scenes/board/physics-board.tscn b/src/logic-scenes/board/physics-board.tscn index 4b1b0c5..3b1dd32 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.00712087 +rotation = -0.0292664 collision_layer = 2147483649 +is_dragable = true [node name="card" parent="HBoxContainer/dropzone" instance=ExtResource("3_mg053")] position = Vector2(640, 659) -rotation = 0.0714344 -scale = Vector2(1, 1) +rotation = -0.0217244 is_dragable = true [node name="ScrollContainer" type="ScrollContainer" parent="HBoxContainer"] @@ -111,7 +111,7 @@ shape = SubResource("CircleShape2D_x8rl2") position = Vector2(-151, -107) [node name="card2" parent="Node2D/RigidBody2D/ancor" instance=ExtResource("3_mg053")] -rotation = -0.0180459 +rotation = 0.00128374 collision_layer = 2 [node name="RigidBody2D2" type="Area2D" parent="Node2D"] @@ -125,7 +125,7 @@ shape = SubResource("CircleShape2D_x8rl2") position = Vector2(-151, -107) [node name="card2" parent="Node2D/RigidBody2D2/ancor" instance=ExtResource("3_mg053")] -rotation = 0.0612526 +rotation = 0.0767116 collision_layer = 2 [node name="RigidBody2D3" type="Area2D" parent="Node2D"] @@ -139,5 +139,5 @@ shape = SubResource("CircleShape2D_x8rl2") position = Vector2(-151, -107) [node name="card2" parent="Node2D/RigidBody2D3/ancor" instance=ExtResource("3_mg053")] -rotation = 0.0528008 +rotation = 0.00437383 collision_layer = 2 diff --git a/src/logic-scenes/board/post-it.tscn b/src/logic-scenes/board/post-it.tscn index 15f49b0..b31e579 100644 --- a/src/logic-scenes/board/post-it.tscn +++ b/src/logic-scenes/board/post-it.tscn @@ -103,7 +103,6 @@ animations = [{ [node name="post-it" type="Area2D"] script = ExtResource("1_yvh5n") highlight_color = Color(1.2, 1.2, 1.2, 1) -is_dragable = null [node name="CollisionShape2D" type="CollisionShape2D" parent="."] position = Vector2(99.5, 0) From 00ca4abc1f6198f6f9b07fda83f379d202f44a72 Mon Sep 17 00:00:00 2001 From: Adrian Schmid Date: Sat, 1 Jul 2023 13:43:27 +0200 Subject: [PATCH 02/13] card-board dictionary + move post-its to dropboard --- src/logic-scenes/board/card-board.gd | 35 +++++++++++++++++++++++++++- src/logic-scenes/board/card.gd | 3 ++- src/logic-scenes/board/post-it.gd | 3 ++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/logic-scenes/board/card-board.gd b/src/logic-scenes/board/card-board.gd index fdb37db..8123f9a 100644 --- a/src/logic-scenes/board/card-board.gd +++ b/src/logic-scenes/board/card-board.gd @@ -1,11 +1,44 @@ extends PanelContainer +var obj_dict = {} +@onready var dropzone = $HBoxContainer/dropzone # Called when the node enters the scene tree for the first time. func _ready(): - pass + + # TODO: Currently populating the dictionary with the Nodes currently in the scene + # When opening the scene we need to pass some kind of collection to the Board + # Then it can display the Card/PostIts and populate its dictionary at the same time + var cards = dropzone.get_children() + var post_it_panels = get_child(0).get_child(1).get_child(0).get_children() + var post_its = Array() + + for panel in post_it_panels: + post_its.push_back(panel.get_child(0)) + + obj_dict["Cards"] = cards + obj_dict["Post_it_panels"] = post_it_panels + obj_dict["Post_its"] = post_its # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): pass + +func populate_board(): + pass + +func handle_mouse_button(to_handle: Node, input: InputEvent, dragableType: int): + print_debug(input) + + # TODO: We need a better way to recognize + # whether to_handle is a Card or a Post-It + # (Tried checking for a script, didn't work, because script has no name attached. + # Alternative might be to check for specific values within the script ("is_card" f.e)) + match dragableType: + 1: # 1 = Card + print_debug("I'm a card") + 2: # 2 = PostIt + print_debug("I'm a Post-It") + to_handle.reparent(dropzone) + to_handle.set_owner(self) # needs to be here otherwise the owner disappears diff --git a/src/logic-scenes/board/card.gd b/src/logic-scenes/board/card.gd index 0516a92..432b6f0 100644 --- a/src/logic-scenes/board/card.gd +++ b/src/logic-scenes/board/card.gd @@ -101,6 +101,7 @@ func _on_mouse_exited(): highlighted = false func _on_input_event(viewport, event, shape_idx): + if event is InputEventMouseMotion and is_dragged: position += event.relative @@ -109,5 +110,5 @@ func _on_input_event(viewport, event, shape_idx): if is_dragable: is_dragged = event.pressed if "handle_mouse_button" in owner: - owner.handle_mouse_button(self, event) + owner.handle_mouse_button(self, event, 1) diff --git a/src/logic-scenes/board/post-it.gd b/src/logic-scenes/board/post-it.gd index c9f705c..1df9fd0 100644 --- a/src/logic-scenes/board/post-it.gd +++ b/src/logic-scenes/board/post-it.gd @@ -85,4 +85,5 @@ func _on_input_event(viewport, event, shape_idx): if is_dragable: is_dragged = event.pressed if "handle_mouse_button" in owner: - owner.handle_mouse_button(self, event) + owner.handle_mouse_button(self, event, 2) + From ea67614da226bc7a28a29490870661d40ddb682c Mon Sep 17 00:00:00 2001 From: Adrian Schmid Date: Sat, 1 Jul 2023 15:19:54 +0200 Subject: [PATCH 03/13] moved drag handling to board to avoid issues --- src/logic-scenes/board/card-board.gd | 65 +++++++++++++++++++++++----- src/logic-scenes/board/post-it.gd | 4 +- 2 files changed, 54 insertions(+), 15 deletions(-) diff --git a/src/logic-scenes/board/card-board.gd b/src/logic-scenes/board/card-board.gd index 8123f9a..6f7484a 100644 --- a/src/logic-scenes/board/card-board.gd +++ b/src/logic-scenes/board/card-board.gd @@ -1,8 +1,12 @@ extends PanelContainer -var obj_dict = {} +var area_dict = {} @onready var dropzone = $HBoxContainer/dropzone +var currently_selected_node: Area2D = null +var is_area_dragged: bool = false +var currently_dragged_area: Area2D + # Called when the node enters the scene tree for the first time. func _ready(): @@ -16,29 +20,66 @@ func _ready(): for panel in post_it_panels: post_its.push_back(panel.get_child(0)) - obj_dict["Cards"] = cards - obj_dict["Post_it_panels"] = post_it_panels - obj_dict["Post_its"] = post_its + area_dict["dropzone_content"] = cards # will be selected on the left side + area_dict["post_it_panels"] = post_it_panels # to remember panel positions + area_dict["post_its_in_list"] = post_its # will be selected on the right side + currently_selected_node = area_dict["dropzone_content"][0] # set first Card as currently selected node by default # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): - pass + + if !Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT) and is_area_dragged: + currently_dragged_area.is_dragged = false + is_area_dragged = Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT) + currently_dragged_area = null +# Will be used later to spawn Cards and Post-Its and remember them in the dictionary func populate_board(): pass -func handle_mouse_button(to_handle: Node, input: InputEvent, dragableType: int): - print_debug(input) +# Checks if a Node is currently inside the dropzone +func is_in_dropzone(to_check: Node) -> bool: + if (dropzone.size.x < to_check.position.x or dropzone.size.y < to_check.position.y): + return false + elif (to_check.position.x < 0 or to_check.position.y < 0): + return false + else: + return true - # TODO: We need a better way to recognize - # whether to_handle is a Card or a Post-It + +func handle_mouse_button(to_handle: Node, input: InputEvent, dragableType: int): + + currently_selected_node = to_handle # update currently selected + currently_dragged_area = to_handle + to_handle.is_dragged = input.pressed + is_area_dragged = input.pressed + + # TODO: We need a better way to recognize whether "to_handle" is a Card or a Post-It. # (Tried checking for a script, didn't work, because script has no name attached. # Alternative might be to check for specific values within the script ("is_card" f.e)) match dragableType: 1: # 1 = Card print_debug("I'm a card") 2: # 2 = PostIt - print_debug("I'm a Post-It") - to_handle.reparent(dropzone) - to_handle.set_owner(self) # needs to be here otherwise the owner disappears + if input.is_pressed(): + to_handle.reparent(dropzone) + to_handle.set_owner(self) # needs to be here otherwise the owner disappears + area_dict["post_its_in_list"].erase(to_handle) + area_dict["dropzone_content"].push_back(to_handle) + # TODO: Add function to rearrange the arrays based on positions in the dropzone + else: + if !is_in_dropzone(to_handle): + for panel in area_dict["post_it_panels"]: + if panel.get_child(0) == null: + to_handle.reparent(panel) + to_handle.set_owner(self) + area_dict["dropzone_content"].erase(to_handle) + area_dict["post_its_in_list"].push_back(to_handle) + # TODO: Add function to rearrange the array based on taken panel spot + to_handle.position = panel.position + break + + + + diff --git a/src/logic-scenes/board/post-it.gd b/src/logic-scenes/board/post-it.gd index 1df9fd0..4c5c7e8 100644 --- a/src/logic-scenes/board/post-it.gd +++ b/src/logic-scenes/board/post-it.gd @@ -82,8 +82,6 @@ func _on_input_event(viewport, event, shape_idx): if event is InputEventMouseButton: if event.button_index == MOUSE_BUTTON_LEFT: - if is_dragable: - is_dragged = event.pressed - if "handle_mouse_button" in owner: + if is_dragable and "handle_mouse_button" in owner: owner.handle_mouse_button(self, event, 2) From ca65c69fdca852ce0e57f1c476f98771e9eeda27 Mon Sep 17 00:00:00 2001 From: Adrian Schmid Date: Sat, 1 Jul 2023 15:20:50 +0200 Subject: [PATCH 04/13] added same handling for cards + anchor for postIts --- src/logic-scenes/board/card-board.gd | 30 ++++++++++++++++------- src/logic-scenes/board/card.gd | 4 +-- src/logic-scenes/board/physics-board.tscn | 12 +++++++++ 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/logic-scenes/board/card-board.gd b/src/logic-scenes/board/card-board.gd index 6f7484a..a0d5253 100644 --- a/src/logic-scenes/board/card-board.gd +++ b/src/logic-scenes/board/card-board.gd @@ -18,7 +18,7 @@ func _ready(): var post_its = Array() for panel in post_it_panels: - post_its.push_back(panel.get_child(0)) + post_its.push_back(panel.get_child(1)) area_dict["dropzone_content"] = cards # will be selected on the left side area_dict["post_it_panels"] = post_it_panels # to remember panel positions @@ -29,9 +29,11 @@ func _ready(): # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): + # Reset information about Areas being dragged, if the mouse is not longer pressed. + # Needed because otherwise it can happen that the areas don't register if you stop clicking on them. if !Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT) and is_area_dragged: currently_dragged_area.is_dragged = false - is_area_dragged = Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT) + is_area_dragged = false currently_dragged_area = null # Will be used later to spawn Cards and Post-Its and remember them in the dictionary @@ -45,11 +47,16 @@ func is_in_dropzone(to_check: Node) -> bool: elif (to_check.position.x < 0 or to_check.position.y < 0): return false else: - return true - + return true func handle_mouse_button(to_handle: Node, input: InputEvent, dragableType: int): - + + # No two areas can be dragged at the same time. + # Make sure that only the same area is dragged. + # Otherwise overlapping areas are dragged at the same time. + if currently_dragged_area != null and to_handle != currently_dragged_area: + return + currently_selected_node = to_handle # update currently selected currently_dragged_area = to_handle to_handle.is_dragged = input.pressed @@ -60,25 +67,30 @@ func handle_mouse_button(to_handle: Node, input: InputEvent, dragableType: int): # Alternative might be to check for specific values within the script ("is_card" f.e)) match dragableType: 1: # 1 = Card - print_debug("I'm a card") + if input.is_pressed(): + # TODO: Add function to rearrange the array based on positions in the dropzone + print_debug(":)") + else: + currently_dragged_area = null 2: # 2 = PostIt if input.is_pressed(): to_handle.reparent(dropzone) to_handle.set_owner(self) # needs to be here otherwise the owner disappears area_dict["post_its_in_list"].erase(to_handle) area_dict["dropzone_content"].push_back(to_handle) - # TODO: Add function to rearrange the arrays based on positions in the dropzone + # TODO: Add function to rearrange the array based on positions in the dropzone else: if !is_in_dropzone(to_handle): for panel in area_dict["post_it_panels"]: - if panel.get_child(0) == null: + if panel.get_child_count() == 1: to_handle.reparent(panel) to_handle.set_owner(self) area_dict["dropzone_content"].erase(to_handle) area_dict["post_its_in_list"].push_back(to_handle) # TODO: Add function to rearrange the array based on taken panel spot - to_handle.position = panel.position + 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 432b6f0..7347684 100644 --- a/src/logic-scenes/board/card.gd +++ b/src/logic-scenes/board/card.gd @@ -107,8 +107,6 @@ func _on_input_event(viewport, event, shape_idx): if event is InputEventMouseButton: if event.button_index == MOUSE_BUTTON_LEFT: - if is_dragable: - is_dragged = event.pressed - if "handle_mouse_button" in owner: + if is_dragable and "handle_mouse_button" in owner: owner.handle_mouse_button(self, event, 1) diff --git a/src/logic-scenes/board/physics-board.tscn b/src/logic-scenes/board/physics-board.tscn index 3b1dd32..b3ba118 100644 --- a/src/logic-scenes/board/physics-board.tscn +++ b/src/logic-scenes/board/physics-board.tscn @@ -61,6 +61,9 @@ custom_minimum_size = Vector2(400, 120) layout_mode = 2 mouse_filter = 1 +[node name="post-it_anchor1" type="Node2D" parent="HBoxContainer/ScrollContainer/VBoxContainer/Panel"] +position = Vector2(105, 57) + [node name="post-it" parent="HBoxContainer/ScrollContainer/VBoxContainer/Panel" instance=ExtResource("5_048k0")] z_index = 1 position = Vector2(105, 57) @@ -71,6 +74,9 @@ custom_minimum_size = Vector2(400, 120) layout_mode = 2 mouse_filter = 1 +[node name="post-it_anchor2" type="Node2D" parent="HBoxContainer/ScrollContainer/VBoxContainer/Panel2"] +position = Vector2(105, 57) + [node name="post-it" parent="HBoxContainer/ScrollContainer/VBoxContainer/Panel2" instance=ExtResource("5_048k0")] position = Vector2(105, 57) is_dragable = true @@ -80,6 +86,9 @@ custom_minimum_size = Vector2(400, 120) layout_mode = 2 mouse_filter = 1 +[node name="post-it_anchor3" type="Node2D" parent="HBoxContainer/ScrollContainer/VBoxContainer/Panel3"] +position = Vector2(105, 57) + [node name="post-it" parent="HBoxContainer/ScrollContainer/VBoxContainer/Panel3" instance=ExtResource("5_048k0")] position = Vector2(105, 57) is_dragable = true @@ -89,6 +98,9 @@ custom_minimum_size = Vector2(400, 120) layout_mode = 2 mouse_filter = 1 +[node name="post-it_anchor4" type="Node2D" parent="HBoxContainer/ScrollContainer/VBoxContainer/Panel4"] +position = Vector2(105, 57) + [node name="post-it" parent="HBoxContainer/ScrollContainer/VBoxContainer/Panel4" instance=ExtResource("5_048k0")] position = Vector2(105, 57) is_dragable = true From 4a0eddf3e9d5980282aa3f357e36dbe411a6963f Mon Sep 17 00:00:00 2001 From: Adrian Schmid Date: Sat, 1 Jul 2023 16:03:22 +0200 Subject: [PATCH 05/13] 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) From 5c88414c480687b092f3d8674c1b56f4b24aa756 Mon Sep 17 00:00:00 2001 From: Adrian Schmid Date: Sat, 1 Jul 2023 16:59:13 +0200 Subject: [PATCH 06/13] added func to sort dict entries on y pos --- src/logic-scenes/board/card-board.gd | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/logic-scenes/board/card-board.gd b/src/logic-scenes/board/card-board.gd index ee4aa32..a55a2b2 100644 --- a/src/logic-scenes/board/card-board.gd +++ b/src/logic-scenes/board/card-board.gd @@ -25,12 +25,14 @@ func _ready(): area_dict["post_its_in_list"] = post_its # will be selected on the right side currently_selected_node = area_dict["dropzone_content"][0] # set first Card as currently selected node by default - + + reorder_areas("dropzone_content") + # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): # Reset information about Areas being dragged, if the mouse is not longer pressed. - # Needed because otherwise it can happen that the areas don't register if you stop clicking on them. + # Needed because otherwise it can happen that the areas don't register it if you stop clicking on them. if !Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT) and is_area_dragged: currently_dragged_area.is_dragged = false is_area_dragged = false @@ -99,7 +101,24 @@ func handle_mouse_button(to_handle: Area2D, input: InputEvent, dragableType: int to_handle.position = panel.get_child(0).position break currently_dragged_area = null - +func handle_hover(to_handle: Area2D): + currently_selected_node = to_handle + pass +# Reorders the areas in any of the dictionaries entries +# Pass the entries key in order to reorder it +func reorder_areas(reorder: String): + var old_order = area_dict[reorder] + var new_order = Array() + + for obj in old_order: + var i = 0 + if !new_order.is_empty(): + for obj_2 in new_order: + if obj_2.position.y < obj.position.y: + i += 1 + new_order.insert(i, obj) + + print_debug(new_order) From c2188316abcce6e2a2ea01c7b2f99ba6f97716ec Mon Sep 17 00:00:00 2001 From: Adrian Schmid Date: Sun, 2 Jul 2023 10:11:54 +0200 Subject: [PATCH 07/13] moved dictionary populating to its own function --- src/logic-scenes/board/card-board.gd | 33 +++++++++++++++------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/logic-scenes/board/card-board.gd b/src/logic-scenes/board/card-board.gd index a55a2b2..b5e3c53 100644 --- a/src/logic-scenes/board/card-board.gd +++ b/src/logic-scenes/board/card-board.gd @@ -10,6 +10,24 @@ var currently_dragged_area: Area2D # Called when the node enters the scene tree for the first time. func _ready(): + populate_board() + reorder_areas("dropzone_content") + + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + + # Reset information about Areas being dragged, if the mouse is not longer pressed. + # Needed because otherwise it can happen that the areas don't register it if you stop clicking on them. + if !Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT) and is_area_dragged: + currently_dragged_area.is_dragged = false + is_area_dragged = false + currently_dragged_area = null + +# Will be used later to spawn Cards and Post-Its and remember them in the dictionary +func populate_board(): + # TODO: Currently populating the dictionary with the Nodes currently in the scene # When opening the scene we need to pass some kind of collection to the Board # Then it can display the Card/PostIts and populate its dictionary at the same time @@ -26,21 +44,6 @@ func _ready(): currently_selected_node = area_dict["dropzone_content"][0] # set first Card as currently selected node by default - reorder_areas("dropzone_content") - -# Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(delta): - - # Reset information about Areas being dragged, if the mouse is not longer pressed. - # Needed because otherwise it can happen that the areas don't register it if you stop clicking on them. - if !Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT) and is_area_dragged: - currently_dragged_area.is_dragged = false - is_area_dragged = false - currently_dragged_area = null - -# Will be used later to spawn Cards and Post-Its and remember them in the dictionary -func populate_board(): - pass # Checks if a Node is currently inside the dropzone func is_in_dropzone(to_check: Node) -> bool: From 45fb225e549c8e8e81c3d4f13cd2b25378d375b2 Mon Sep 17 00:00:00 2001 From: Adrian Schmid Date: Sun, 2 Jul 2023 10:19:15 +0200 Subject: [PATCH 08/13] remove dragableType and replace it with meta-type --- src/logic-scenes/board/card-board.gd | 11 +++++------ src/logic-scenes/board/card.gd | 2 +- src/logic-scenes/board/post-it.gd | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/logic-scenes/board/card-board.gd b/src/logic-scenes/board/card-board.gd index b5e3c53..c4334d5 100644 --- a/src/logic-scenes/board/card-board.gd +++ b/src/logic-scenes/board/card-board.gd @@ -54,7 +54,7 @@ func is_in_dropzone(to_check: Node) -> bool: else: return true -func handle_mouse_button(to_handle: Area2D, input: InputEvent, dragableType: int): +func handle_mouse_button(to_handle: Area2D, input: InputEvent): # No two areas can be dragged at the same time. # Make sure that only the same area is dragged. @@ -70,14 +70,13 @@ func handle_mouse_button(to_handle: Area2D, input: InputEvent, dragableType: int # TODO: We need a better way to recognize whether "to_handle" is a Card or a Post-It. # (Tried checking for a script, didn't work, because script has no name attached. # Alternative might be to check for specific values within the script ("is_card" f.e)) - match dragableType: - 1: # 1 = Card + match to_handle.get_meta("type"): + "card": # 1 = Card if input.is_pressed(): - # TODO: Add function to rearrange the array based on positions in the dropzone - print_debug(":)") + reorder_areas("dropzone_content") else: currently_dragged_area = null - 2: # 2 = PostIt + "post-it": # 2 = PostIt if input.is_pressed(): to_handle.reparent(dropzone) to_handle.set_owner(self) # needs to be here otherwise the owner disappears diff --git a/src/logic-scenes/board/card.gd b/src/logic-scenes/board/card.gd index 13ca4cf..134ccc3 100644 --- a/src/logic-scenes/board/card.gd +++ b/src/logic-scenes/board/card.gd @@ -111,5 +111,5 @@ func _on_input_event(viewport, event, shape_idx): if event is InputEventMouseButton: if event.button_index == MOUSE_BUTTON_LEFT: if is_dragable and "handle_mouse_button" in owner: - owner.handle_mouse_button(self, event, 1) + owner.handle_mouse_button(self, event) diff --git a/src/logic-scenes/board/post-it.gd b/src/logic-scenes/board/post-it.gd index 08a82a9..b19bcd5 100644 --- a/src/logic-scenes/board/post-it.gd +++ b/src/logic-scenes/board/post-it.gd @@ -86,5 +86,5 @@ func _on_input_event(viewport, event, shape_idx): if event is InputEventMouseButton: if event.button_index == MOUSE_BUTTON_LEFT: if is_dragable and "handle_mouse_button" in owner: - owner.handle_mouse_button(self, event, 2) + owner.handle_mouse_button(self, event) From 72825ecae62cf10b21f97aa077ec2672a5a353c7 Mon Sep 17 00:00:00 2001 From: Adrian Schmid Date: Sun, 2 Jul 2023 10:42:58 +0200 Subject: [PATCH 09/13] improved area movement --- src/logic-scenes/board/card.gd | 9 +++++++-- src/logic-scenes/board/post-it.gd | 11 ++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/logic-scenes/board/card.gd b/src/logic-scenes/board/card.gd index 134ccc3..15fbef4 100644 --- a/src/logic-scenes/board/card.gd +++ b/src/logic-scenes/board/card.gd @@ -76,6 +76,8 @@ func _process(delta: float) -> void: if highlighted: _handle_wiggle(delta) + + _move_card() func _handle_wiggle(delta): wiggle_pos += delta * wiggle_speed * wiggle_intensity @@ -105,11 +107,14 @@ func _on_mouse_exited(): func _on_input_event(viewport, event, shape_idx): - if event is InputEventMouseMotion and is_dragged: - position += event.relative + if event is InputEventMouseMotion: + _move_card() if event is InputEventMouseButton: if event.button_index == MOUSE_BUTTON_LEFT: if is_dragable and "handle_mouse_button" in owner: owner.handle_mouse_button(self, event) +func _move_card(): + if is_dragged: + position += get_viewport().get_mouse_position() - position diff --git a/src/logic-scenes/board/post-it.gd b/src/logic-scenes/board/post-it.gd index b19bcd5..c808d39 100644 --- a/src/logic-scenes/board/post-it.gd +++ b/src/logic-scenes/board/post-it.gd @@ -62,7 +62,8 @@ func replace_with(postit: PostIt): self.sibling = postit.sibling func _process(delta: float) -> void: - pass + _move_post_it() + func _on_focus_entered(): print(self, "is focused") @@ -80,11 +81,15 @@ func _on_mouse_exited(): highlighted = false func _on_input_event(viewport, event, shape_idx): - if event is InputEventMouseMotion and is_dragged: - position += event.relative + if event is InputEventMouseMotion: + _move_post_it() if event is InputEventMouseButton: if event.button_index == MOUSE_BUTTON_LEFT: if is_dragable and "handle_mouse_button" in owner: owner.handle_mouse_button(self, event) +func _move_post_it(): + if is_dragged: + position += get_viewport().get_mouse_position() - position + From 0c8e3557ae1363cddd9b2fd02064e38ba9ad4317 Mon Sep 17 00:00:00 2001 From: Adrian Schmid Date: Sun, 2 Jul 2023 11:01:04 +0200 Subject: [PATCH 10/13] reset rot./scale after removing post it from card --- src/logic-scenes/board/card-board.gd | 9 +++++++-- src/logic-scenes/board/post-it.gd | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/logic-scenes/board/card-board.gd b/src/logic-scenes/board/card-board.gd index c4334d5..a0771b2 100644 --- a/src/logic-scenes/board/card-board.gd +++ b/src/logic-scenes/board/card-board.gd @@ -82,7 +82,7 @@ func handle_mouse_button(to_handle: Area2D, input: InputEvent): to_handle.set_owner(self) # needs to be here otherwise the owner disappears area_dict["post_its_in_list"].erase(to_handle) area_dict["dropzone_content"].push_back(to_handle) - # TODO: Add function to rearrange the array based on positions in the dropzone + # TODO (if needed): Add function to rearrange the array based on positions in the dropzone else: if is_in_dropzone(to_handle): if to_handle.has_overlapping_areas(): @@ -92,6 +92,9 @@ func handle_mouse_button(to_handle: Area2D, input: InputEvent): to_handle.reparent(area) to_handle.set_owner(self) to_handle.position = area.get_child(3).position + else: + to_handle.rotation = to_handle.base_rotation + to_handle.scale = to_handle.base_scale else: for panel in area_dict["post_it_panels"]: if panel.get_child_count() == 1: @@ -99,8 +102,10 @@ func handle_mouse_button(to_handle: Area2D, input: InputEvent): to_handle.set_owner(self) area_dict["dropzone_content"].erase(to_handle) area_dict["post_its_in_list"].push_back(to_handle) - # TODO: Add function to rearrange the array based on taken panel spot to_handle.position = panel.get_child(0).position + to_handle.rotation = to_handle.base_rotation + to_handle.scale = to_handle.base_scale + reorder_areas("post_its_in_list") break currently_dragged_area = null diff --git a/src/logic-scenes/board/post-it.gd b/src/logic-scenes/board/post-it.gd index c808d39..cd37efd 100644 --- a/src/logic-scenes/board/post-it.gd +++ b/src/logic-scenes/board/post-it.gd @@ -46,11 +46,15 @@ var modulate_tween @export var voice_line: AudioStream = null @export var is_dragable: bool = false +var base_rotation = null +var base_scale = null 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 + base_rotation = rotation + base_scale = scale $Content/Label.text = self.text $Content/BackgroundSprite.frame = text.hash() % $Content/BackgroundSprite.sprite_frames.get_frame_count($Content/BackgroundSprite.animation) From 4be04710181308308138c96ad77bcf9ec7d859f3 Mon Sep 17 00:00:00 2001 From: Adrian Schmid Date: Sun, 2 Jul 2023 11:50:19 +0200 Subject: [PATCH 11/13] prevent putting multiple post its on one card --- src/logic-scenes/board/card-board.gd | 9 +++++---- src/logic-scenes/board/card.gd | 8 ++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/logic-scenes/board/card-board.gd b/src/logic-scenes/board/card-board.gd index a0771b2..d6b7a24 100644 --- a/src/logic-scenes/board/card-board.gd +++ b/src/logic-scenes/board/card-board.gd @@ -89,9 +89,10 @@ func handle_mouse_button(to_handle: Area2D, input: InputEvent): 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 + if !area.has_postit_attached(): + to_handle.reparent(area) + to_handle.set_owner(self) + to_handle.position = area.get_child(3).position else: to_handle.rotation = to_handle.base_rotation to_handle.scale = to_handle.base_scale @@ -127,5 +128,5 @@ func reorder_areas(reorder: String): i += 1 new_order.insert(i, obj) - print_debug(new_order) + #print_debug(new_order) diff --git a/src/logic-scenes/board/card.gd b/src/logic-scenes/board/card.gd index 15fbef4..ee4e6ca 100644 --- a/src/logic-scenes/board/card.gd +++ b/src/logic-scenes/board/card.gd @@ -118,3 +118,11 @@ func _on_input_event(viewport, event, shape_idx): func _move_card(): if is_dragged: position += get_viewport().get_mouse_position() - position + +func has_postit_attached() -> bool: + var all_children = get_children() + print_debug(all_children) + for child in all_children: + if child.get_meta("type") == "post-it": + return true + return false From bfd6649ce91680d8e2a8ead2342e0f0a2d6d8a67 Mon Sep 17 00:00:00 2001 From: Adrian Schmid Date: Sun, 2 Jul 2023 15:10:33 +0200 Subject: [PATCH 12/13] keyboard controls for the card board --- src/logic-scenes/board/card-board.gd | 208 ++++++++++++++++++++++----- src/logic-scenes/board/card.gd | 1 - src/logic-scenes/board/post-it.gd | 5 + 3 files changed, 180 insertions(+), 34 deletions(-) diff --git a/src/logic-scenes/board/card-board.gd b/src/logic-scenes/board/card-board.gd index d6b7a24..3130171 100644 --- a/src/logic-scenes/board/card-board.gd +++ b/src/logic-scenes/board/card-board.gd @@ -1,33 +1,43 @@ extends PanelContainer var area_dict = {} +enum ui_context {DROPZONE, POST_IT_LIST, ASSIGN_POST_IT} + @onready var dropzone = $HBoxContainer/dropzone +@onready var active_context = ui_context.DROPZONE # 0 = dropzone, 1 = post it list var currently_selected_node: Area2D = null +var currently_selected_card_for_assigning: Area2D = null var is_area_dragged: bool = false var currently_dragged_area: Area2D +var selected_dropzone_element: int = -1 +var selected_postit_list_element: int = 0 +var selected_card_for_assignment + # Called when the node enters the scene tree for the first time. func _ready(): - populate_board() reorder_areas("dropzone_content") - - + + active_context = ui_context.DROPZONE + # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): - # Reset information about Areas being dragged, if the mouse is not longer pressed. # Needed because otherwise it can happen that the areas don't register it if you stop clicking on them. if !Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT) and is_area_dragged: currently_dragged_area.is_dragged = false is_area_dragged = false currently_dragged_area = null + + #if active_context == ui_context.ASSIGN_POST_IT: + + # Will be used later to spawn Cards and Post-Its and remember them in the dictionary func populate_board(): - # TODO: Currently populating the dictionary with the Nodes currently in the scene # When opening the scene we need to pass some kind of collection to the Board # Then it can display the Card/PostIts and populate its dictionary at the same time @@ -43,19 +53,19 @@ func populate_board(): area_dict["post_its_in_list"] = post_its # will be selected on the right side currently_selected_node = area_dict["dropzone_content"][0] # set first Card as currently selected node by default - + # Checks if a Node is currently inside the dropzone func is_in_dropzone(to_check: Node) -> bool: - if (dropzone.size.x < to_check.position.x or dropzone.size.y < to_check.position.y): + if (dropzone.size.x < to_check.global_position.x or dropzone.size.y < to_check.global_position.y): return false - elif (to_check.position.x < 0 or to_check.position.y < 0): + elif (to_check.global_position.x < 0 or to_check.global_position.y < 0): return false else: return true + func handle_mouse_button(to_handle: Area2D, input: InputEvent): - # No two areas can be dragged at the same time. # Make sure that only the same area is dragged. # Otherwise overlapping areas are dragged at the same time. @@ -72,6 +82,7 @@ func handle_mouse_button(to_handle: Area2D, input: InputEvent): # Alternative might be to check for specific values within the script ("is_card" f.e)) match to_handle.get_meta("type"): "card": # 1 = Card + active_context = ui_context.DROPZONE if input.is_pressed(): reorder_areas("dropzone_content") else: @@ -85,34 +96,46 @@ func handle_mouse_button(to_handle: Area2D, input: InputEvent): # TODO (if needed): Add function to rearrange the array based on positions in the dropzone else: 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": - if !area.has_postit_attached(): - to_handle.reparent(area) - to_handle.set_owner(self) - to_handle.position = area.get_child(3).position - else: - to_handle.rotation = to_handle.base_rotation - to_handle.scale = to_handle.base_scale - else: - for panel in area_dict["post_it_panels"]: - if panel.get_child_count() == 1: - to_handle.reparent(panel) - to_handle.set_owner(self) - area_dict["dropzone_content"].erase(to_handle) - area_dict["post_its_in_list"].push_back(to_handle) - to_handle.position = panel.get_child(0).position + if to_handle.has_overlapping_areas(): + for area in to_handle.get_overlapping_areas(): + if area.get_meta("type") == "card": + if !area.has_postit_attached(): + attach_postit_to_card(to_handle, area) + else: to_handle.rotation = to_handle.base_rotation to_handle.scale = to_handle.base_scale - reorder_areas("post_its_in_list") - break + else: + active_context = ui_context.POST_IT_LIST + _return_postit_to_panels(to_handle) currently_dragged_area = null + +# Logic for attaching a postit to a card. Also reset postit positions if the card cannot be attached +func attach_postit_to_card(postit: Area2D, card: Area2D, update_dict = false): + postit.reparent(card) + postit.set_owner(self) + postit.position = card.get_child(3).position + + if update_dict: + area_dict["post_its_in_list"].erase(postit) + area_dict["dropzone_content"].push_back(postit) + + reorder_areas("dropzone_content") + reorder_areas("post_its_in_list") + + +# Mark area that was hovered over as currently selected func handle_hover(to_handle: Area2D): + currently_selected_node.highlighted = false currently_selected_node = to_handle - pass + + if is_in_dropzone(to_handle): + selected_dropzone_element = area_dict["dropzone_content"].find(to_handle) + active_context = ui_context.DROPZONE + else: + selected_postit_list_element = area_dict["post_its_in_list"].find(to_handle) + active_context = ui_context.POST_IT_LIST + # Reorders the areas in any of the dictionaries entries # Pass the entries key in order to reorder it @@ -127,6 +150,125 @@ func reorder_areas(reorder: String): if obj_2.position.y < obj.position.y: i += 1 new_order.insert(i, obj) - - #print_debug(new_order) + + +# Takes the inputs for control inputs +func _input(event): + # Return, if the input is a mouse event (mouse events are handled separately) + if event is InputEventMouse: return + + if event.is_action_pressed("ui_up"): # up to select an element above + match active_context: + ui_context.DROPZONE: + selected_dropzone_element -= 1 + ui_context.POST_IT_LIST: + selected_postit_list_element -= 1 + ui_context.ASSIGN_POST_IT: + selected_card_for_assignment -= 1 + + elif event.is_action_pressed("ui_down"): # down to select an element beneath + match active_context: + ui_context.DROPZONE: + selected_dropzone_element += 1 + ui_context.POST_IT_LIST: + selected_postit_list_element += 1 + ui_context.ASSIGN_POST_IT: + selected_card_for_assignment += 1 + + elif event.is_action_pressed("ui_left"): # left to switch context to the left + active_context -= 1 + if active_context < 0: + active_context = ui_context.POST_IT_LIST + + elif event.is_action_pressed("ui_right"): # right to switch context to the right + active_context += 1 + if active_context > 2: + active_context = ui_context.DROPZONE + + elif event.is_action_pressed("ui_select"): # select the selected post it + if active_context == ui_context.ASSIGN_POST_IT: # to assign it to a card + attach_postit_to_card(currently_selected_node, + currently_selected_card_for_assigning, true) + _leave_assignment_context() + else: + _enter_assignment_context() + + + # do some adjustments to loop elements (after last element, select first one etc.) + if selected_dropzone_element < 0: + selected_dropzone_element = area_dict["dropzone_content"].size()-1 + elif selected_dropzone_element > area_dict["dropzone_content"].size()-1: + selected_dropzone_element = 0 + + if selected_postit_list_element < 0: + selected_postit_list_element = area_dict["post_its_in_list"].size()-1 + elif selected_postit_list_element > area_dict["post_its_in_list"].size()-1: + selected_postit_list_element = 0 + + if active_context == ui_context.ASSIGN_POST_IT: # skip this if we're not in assign post it context + if selected_card_for_assignment < 0: + selected_card_for_assignment = area_dict["dropzone_content"].size()-1 + elif selected_card_for_assignment > area_dict["dropzone_content"].size()-1: + selected_card_for_assignment = 0 + + # highlight the selected element + match active_context: + ui_context.DROPZONE: + currently_selected_node.highlighted = false + currently_selected_node = area_dict["dropzone_content"][selected_dropzone_element] + currently_selected_node.highlighted = true + ui_context.POST_IT_LIST: + currently_selected_node.highlighted = false + currently_selected_node = area_dict["post_its_in_list"][selected_postit_list_element] + currently_selected_node.highlighted = true + ui_context.ASSIGN_POST_IT: + currently_selected_card_for_assigning.highlighted = false + currently_selected_card_for_assigning = area_dict["dropzone_content"][selected_card_for_assignment] + currently_selected_card_for_assigning.highlighted = true + + # update dictiornary orders + reorder_areas("dropzone_content") + reorder_areas("post_its_in_list") + + +# Sets everything up to enter the context where postits can be assigned via button controls +func _enter_assignment_context(): + # cards are currently not moved, only post its. Exit function if a card should be moved. + if currently_selected_node == null or currently_selected_node.get_meta("type") != "post-it" : return + + # if the postit is already attached, remove it and return it to the post it panels + if currently_selected_node.is_postit_attached(): + _return_postit_to_panels(currently_selected_node) + active_context = ui_context.POST_IT_LIST + return + + # adjust everything for the post it to select its attach-target + active_context = ui_context.ASSIGN_POST_IT + selected_card_for_assignment = 0 + currently_selected_card_for_assigning = area_dict["dropzone_content"][0] + currently_selected_card_for_assigning.highlighted = true + + +# leaves the context for assigning postit via button controls +func _leave_assignment_context(): + currently_selected_node.highlighted = false + active_context = ui_context.DROPZONE + currently_selected_node = currently_selected_card_for_assigning + + +# handles everything to return a post it to the panels +func _return_postit_to_panels(postit: Area2D): + for panel in area_dict["post_it_panels"]: + if panel.get_child_count() == 1: + postit.reparent(panel) + postit.set_owner(self) + area_dict["dropzone_content"].erase(postit) + area_dict["post_its_in_list"].push_back(postit) + postit.position = panel.get_child(0).position + postit.rotation = postit.base_rotation + postit.scale = postit.base_scale + reorder_areas("dropzone_content") + reorder_areas("post_its_in_list") + break + diff --git a/src/logic-scenes/board/card.gd b/src/logic-scenes/board/card.gd index ee4e6ca..34c5338 100644 --- a/src/logic-scenes/board/card.gd +++ b/src/logic-scenes/board/card.gd @@ -121,7 +121,6 @@ func _move_card(): func has_postit_attached() -> bool: var all_children = get_children() - print_debug(all_children) for child in all_children: if child.get_meta("type") == "post-it": return true diff --git a/src/logic-scenes/board/post-it.gd b/src/logic-scenes/board/post-it.gd index cd37efd..246cf8c 100644 --- a/src/logic-scenes/board/post-it.gd +++ b/src/logic-scenes/board/post-it.gd @@ -97,3 +97,8 @@ func _move_post_it(): if is_dragged: position += get_viewport().get_mouse_position() - position +func is_postit_attached() -> bool: + if self.get_parent().get_meta("type") == "card": + return true + return false + From daf073c6b42fbed9fbd87894c5c08175577679f0 Mon Sep 17 00:00:00 2001 From: Adrian Schmid Date: Mon, 3 Jul 2023 20:27:09 +0200 Subject: [PATCH 13/13] populate_board() to spawn cards/postits --- src/logic-scenes/board/card-board.gd | 83 ++++++++++++++++++++-------- src/logic-scenes/board/post-it.gd | 6 +- 2 files changed, 61 insertions(+), 28 deletions(-) diff --git a/src/logic-scenes/board/card-board.gd b/src/logic-scenes/board/card-board.gd index 3130171..6478ab6 100644 --- a/src/logic-scenes/board/card-board.gd +++ b/src/logic-scenes/board/card-board.gd @@ -4,6 +4,8 @@ var area_dict = {} enum ui_context {DROPZONE, POST_IT_LIST, ASSIGN_POST_IT} @onready var dropzone = $HBoxContainer/dropzone +@onready var postit_container = $HBoxContainer/ScrollContainer/VBoxContainer +@onready var board_of_devs = $"board of devs" @onready var active_context = ui_context.DROPZONE # 0 = dropzone, 1 = post it list var currently_selected_node: Area2D = null @@ -17,9 +19,11 @@ var selected_card_for_assignment # Called when the node enters the scene tree for the first time. func _ready(): - populate_board() - reorder_areas("dropzone_content") + var test_arr = ["c_Joy","p_effort","c_backlash","c_body","c_hit","p_slut","p_worried_mother","p_cross_friend"] + + populate_board(test_arr) + reorder_areas("dropzone_content") active_context = ui_context.DROPZONE @@ -31,29 +35,60 @@ func _process(delta): currently_dragged_area.is_dragged = false is_area_dragged = false currently_dragged_area = null - - #if active_context == ui_context.ASSIGN_POST_IT: # Will be used later to spawn Cards and Post-Its and remember them in the dictionary -func populate_board(): - # TODO: Currently populating the dictionary with the Nodes currently in the scene - # When opening the scene we need to pass some kind of collection to the Board - # Then it can display the Card/PostIts and populate its dictionary at the same time - var cards = dropzone.get_children() - var post_it_panels = get_child(0).get_child(1).get_child(0).get_children() - var post_its = Array() +func populate_board(card_names: Array): + var all_cards = Array() + var all_postits = Array() + + # define entries in dictionary + area_dict["dropzone_content"] = Array() + area_dict["post_its_in_list"] = Array() + + # to remember panel positions + area_dict["post_it_panels"] = get_child(0).get_child(1).get_child(0).get_children() + + # get all the cards and post-its from the board of devs + for child in board_of_devs.get_children(): + for child_2 in child.get_children(): # put all cards in all_cards array + all_cards.push_back(child_2) + for child_3 in child_2.get_children(): # put all post-its in all_postits array + if "p_" in child_3.name: # post-its are currently children of cards. + all_postits.push_back(child_3) # If this changes, this logic needs to be adjusted. + + # spawning the cards and adding them to the dictionary + for card_name in card_names: + if "c_" in card_name: # spawning a card + var new_card = _find_area_by_string(all_cards, card_name).duplicate() + for child in new_card.get_children(): # We need to clear all the post-its from the cards on the dev-board + if "p_" in child.name: + new_card.remove_child(child) # dev-board has post-its attached to the cards, which need to be removed + dropzone.add_child(new_card) + new_card.set_owner(self) + area_dict["dropzone_content"].push_back(new_card) + new_card.global_position = Vector2(300, 200) # using hard-coded position because I'm lazy + new_card.is_dragable = true + if "p_" in card_name: # spawning a post-it + var new_postit = _find_area_by_string(all_postits, card_name).duplicate() + for panel in area_dict["post_it_panels"]: # still mad I can't use the return_postit-func for this... + if panel.get_child_count() == 1: + panel.add_child(new_postit) + new_postit.set_owner(self) + area_dict["post_its_in_list"].push_back(new_postit) + new_postit.position = panel.get_child(0).position + new_postit.is_dragable = true + break - for panel in post_it_panels: - post_its.push_back(panel.get_child(1)) - - area_dict["dropzone_content"] = cards # will be selected on the left side - area_dict["post_it_panels"] = post_it_panels # to remember panel positions - area_dict["post_its_in_list"] = post_its # will be selected on the right side - currently_selected_node = area_dict["dropzone_content"][0] # set first Card as currently selected node by default +# Handy function to filter an array of areas by the name of a card +func _find_area_by_string(area_arr: Array, name: String) -> Area2D: + for area in area_arr: + if area.name == name: + return area + return null # Checks if a Node is currently inside the dropzone func is_in_dropzone(to_check: Node) -> bool: @@ -64,7 +99,7 @@ func is_in_dropzone(to_check: Node) -> bool: else: return true - +# called if a mouse button is pressed func handle_mouse_button(to_handle: Area2D, input: InputEvent): # No two areas can be dragged at the same time. # Make sure that only the same area is dragged. @@ -126,7 +161,8 @@ func attach_postit_to_card(postit: Area2D, card: Area2D, update_dict = false): # Mark area that was hovered over as currently selected func handle_hover(to_handle: Area2D): - currently_selected_node.highlighted = false + if to_handle != currently_selected_node: + currently_selected_node.highlighted = false currently_selected_node = to_handle if is_in_dropzone(to_handle): @@ -138,7 +174,7 @@ func handle_hover(to_handle: Area2D): # Reorders the areas in any of the dictionaries entries -# Pass the entries key in order to reorder it +# Pass the entry's key in order to reorder it func reorder_areas(reorder: String): var old_order = area_dict[reorder] var new_order = Array() @@ -192,7 +228,8 @@ func _input(event): _leave_assignment_context() else: _enter_assignment_context() - + + # TODO: I forgor the HECKING RIGHT-CLICK!!!!111 AAAAAAAAAAAAAAAAAAAA # do some adjustments to loop elements (after last element, select first one etc.) if selected_dropzone_element < 0: @@ -248,14 +285,12 @@ func _enter_assignment_context(): currently_selected_card_for_assigning = area_dict["dropzone_content"][0] currently_selected_card_for_assigning.highlighted = true - # leaves the context for assigning postit via button controls func _leave_assignment_context(): currently_selected_node.highlighted = false active_context = ui_context.DROPZONE currently_selected_node = currently_selected_card_for_assigning - # handles everything to return a post it to the panels func _return_postit_to_panels(postit: Area2D): for panel in area_dict["post_it_panels"]: diff --git a/src/logic-scenes/board/post-it.gd b/src/logic-scenes/board/post-it.gd index 246cf8c..e426b24 100644 --- a/src/logic-scenes/board/post-it.gd +++ b/src/logic-scenes/board/post-it.gd @@ -46,15 +46,13 @@ var modulate_tween @export var voice_line: AudioStream = null @export var is_dragable: bool = false -var base_rotation = null -var base_scale = null +@onready var base_rotation = rotation +@onready var base_scale = scale 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 - base_rotation = rotation - base_scale = scale $Content/Label.text = self.text $Content/BackgroundSprite.frame = text.hash() % $Content/BackgroundSprite.sprite_frames.get_frame_count($Content/BackgroundSprite.animation)