2023-06-27 11:51:23 +00:00
|
|
|
extends PanelContainer
|
|
|
|
|
|
2023-07-01 13:19:54 +00:00
|
|
|
var area_dict = {}
|
2023-07-01 11:43:27 +00:00
|
|
|
@onready var dropzone = $HBoxContainer/dropzone
|
2023-06-27 11:51:23 +00:00
|
|
|
|
2023-07-01 13:19:54 +00:00
|
|
|
var currently_selected_node: Area2D = null
|
|
|
|
|
var is_area_dragged: bool = false
|
|
|
|
|
var currently_dragged_area: Area2D
|
|
|
|
|
|
2023-06-27 11:51:23 +00:00
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
|
func _ready():
|
2023-07-01 11:43:27 +00:00
|
|
|
|
|
|
|
|
# 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:
|
2023-07-01 13:20:50 +00:00
|
|
|
post_its.push_back(panel.get_child(1))
|
2023-07-01 11:43:27 +00:00
|
|
|
|
2023-07-01 13:19:54 +00:00
|
|
|
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
|
2023-06-27 11:51:23 +00:00
|
|
|
|
2023-07-01 13:19:54 +00:00
|
|
|
currently_selected_node = area_dict["dropzone_content"][0] # set first Card as currently selected node by default
|
2023-06-27 11:51:23 +00:00
|
|
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
|
|
|
func _process(delta):
|
2023-07-01 13:19:54 +00:00
|
|
|
|
2023-07-01 13:20:50 +00:00
|
|
|
# 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.
|
2023-07-01 13:19:54 +00:00
|
|
|
if !Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT) and is_area_dragged:
|
|
|
|
|
currently_dragged_area.is_dragged = false
|
2023-07-01 13:20:50 +00:00
|
|
|
is_area_dragged = false
|
2023-07-01 13:19:54 +00:00
|
|
|
currently_dragged_area = null
|
2023-07-01 11:43:27 +00:00
|
|
|
|
2023-07-01 13:19:54 +00:00
|
|
|
# Will be used later to spawn Cards and Post-Its and remember them in the dictionary
|
2023-07-01 11:43:27 +00:00
|
|
|
func populate_board():
|
|
|
|
|
pass
|
|
|
|
|
|
2023-07-01 13:19:54 +00:00
|
|
|
# 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:
|
2023-07-01 13:20:50 +00:00
|
|
|
return true
|
2023-07-01 13:19:54 +00:00
|
|
|
|
2023-07-01 11:43:27 +00:00
|
|
|
func handle_mouse_button(to_handle: Node, input: InputEvent, dragableType: int):
|
2023-07-01 13:20:50 +00:00
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
2023-07-01 13:19:54 +00:00
|
|
|
currently_selected_node = to_handle # update currently selected
|
|
|
|
|
currently_dragged_area = to_handle
|
|
|
|
|
to_handle.is_dragged = input.pressed
|
|
|
|
|
is_area_dragged = input.pressed
|
2023-07-01 11:43:27 +00:00
|
|
|
|
2023-07-01 13:19:54 +00:00
|
|
|
# TODO: We need a better way to recognize whether "to_handle" is a Card or a Post-It.
|
2023-07-01 11:43:27 +00:00
|
|
|
# (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
|
2023-07-01 13:20:50 +00:00
|
|
|
if input.is_pressed():
|
|
|
|
|
# TODO: Add function to rearrange the array based on positions in the dropzone
|
|
|
|
|
print_debug(":)")
|
|
|
|
|
else:
|
|
|
|
|
currently_dragged_area = null
|
2023-07-01 11:43:27 +00:00
|
|
|
2: # 2 = PostIt
|
2023-07-01 13:19:54 +00:00
|
|
|
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)
|
2023-07-01 13:20:50 +00:00
|
|
|
# TODO: Add function to rearrange the array based on positions in the dropzone
|
2023-07-01 13:19:54 +00:00
|
|
|
else:
|
|
|
|
|
if !is_in_dropzone(to_handle):
|
|
|
|
|
for panel in area_dict["post_it_panels"]:
|
2023-07-01 13:20:50 +00:00
|
|
|
if panel.get_child_count() == 1:
|
2023-07-01 13:19:54 +00:00
|
|
|
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
|
2023-07-01 13:20:50 +00:00
|
|
|
to_handle.position = panel.get_child(0).position
|
2023-07-01 13:19:54 +00:00
|
|
|
break
|
2023-07-01 13:20:50 +00:00
|
|
|
currently_dragged_area = null
|
2023-07-01 13:19:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|