extends PanelContainer 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(): # 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)) 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): 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 # 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 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 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