added same handling for cards + anchor for postIts

This commit is contained in:
Adrian Schmid 2023-07-01 15:20:50 +02:00
parent ea67614da2
commit ca65c69fdc
3 changed files with 34 additions and 12 deletions

View File

@ -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
@ -47,9 +49,14 @@ func is_in_dropzone(to_check: Node) -> bool:
else:
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

View File

@ -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)

View File

@ -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