From 00ca4abc1f6198f6f9b07fda83f379d202f44a72 Mon Sep 17 00:00:00 2001 From: Adrian Schmid Date: Sat, 1 Jul 2023 13:43:27 +0200 Subject: [PATCH] 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) +