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
|
|
|
|
2023-07-02 08:11:54 +00:00
|
|
|
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():
|
|
|
|
|
|
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-07-01 14:59:13 +00:00
|
|
|
|
2023-07-01 11:43:27 +00:00
|
|
|
|
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-02 08:19:15 +00:00
|
|
|
func handle_mouse_button(to_handle: Area2D, input: InputEvent):
|
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))
|
2023-07-02 08:19:15 +00:00
|
|
|
match to_handle.get_meta("type"):
|
|
|
|
|
"card": # 1 = Card
|
2023-07-01 13:20:50 +00:00
|
|
|
if input.is_pressed():
|
2023-07-02 08:19:15 +00:00
|
|
|
reorder_areas("dropzone_content")
|
2023-07-01 13:20:50 +00:00
|
|
|
else:
|
|
|
|
|
currently_dragged_area = null
|
2023-07-02 08:19:15 +00:00
|
|
|
"post-it": # 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-02 09:01:04 +00:00
|
|
|
# TODO (if needed): Add function to rearrange the array based on positions in the dropzone
|
2023-07-01 13:19:54 +00:00
|
|
|
else:
|
2023-07-01 14:03:22 +00:00
|
|
|
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":
|
2023-07-02 09:50:19 +00:00
|
|
|
if !area.has_postit_attached():
|
|
|
|
|
to_handle.reparent(area)
|
|
|
|
|
to_handle.set_owner(self)
|
|
|
|
|
to_handle.position = area.get_child(3).position
|
2023-07-02 09:01:04 +00:00
|
|
|
else:
|
|
|
|
|
to_handle.rotation = to_handle.base_rotation
|
|
|
|
|
to_handle.scale = to_handle.base_scale
|
2023-07-01 14:03:22 +00:00
|
|
|
else:
|
2023-07-01 13:19:54 +00:00
|
|
|
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)
|
2023-07-01 13:20:50 +00:00
|
|
|
to_handle.position = panel.get_child(0).position
|
2023-07-02 09:01:04 +00:00
|
|
|
to_handle.rotation = to_handle.base_rotation
|
|
|
|
|
to_handle.scale = to_handle.base_scale
|
|
|
|
|
reorder_areas("post_its_in_list")
|
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
|
|
|
|
2023-07-01 14:59:13 +00:00
|
|
|
func handle_hover(to_handle: Area2D):
|
|
|
|
|
currently_selected_node = to_handle
|
|
|
|
|
pass
|
2023-07-01 13:19:54 +00:00
|
|
|
|
2023-07-01 14:59:13 +00:00
|
|
|
# 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)
|
|
|
|
|
|
2023-07-02 09:50:19 +00:00
|
|
|
#print_debug(new_order)
|
2023-07-01 13:19:54 +00:00
|
|
|
|