added same handling for cards + anchor for postIts
This commit is contained in:
parent
ea67614da2
commit
ca65c69fdc
|
|
@ -18,7 +18,7 @@ func _ready():
|
||||||
var post_its = Array()
|
var post_its = Array()
|
||||||
|
|
||||||
for panel in post_it_panels:
|
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["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_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.
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
func _process(delta):
|
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:
|
if !Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT) and is_area_dragged:
|
||||||
currently_dragged_area.is_dragged = false
|
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
|
currently_dragged_area = null
|
||||||
|
|
||||||
# Will be used later to spawn Cards and Post-Its and remember them in the dictionary
|
# Will be used later to spawn Cards and Post-Its and remember them in the dictionary
|
||||||
|
|
@ -45,11 +47,16 @@ func is_in_dropzone(to_check: Node) -> bool:
|
||||||
elif (to_check.position.x < 0 or to_check.position.y < 0):
|
elif (to_check.position.x < 0 or to_check.position.y < 0):
|
||||||
return false
|
return false
|
||||||
else:
|
else:
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
|
||||||
func handle_mouse_button(to_handle: Node, input: InputEvent, dragableType: int):
|
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_selected_node = to_handle # update currently selected
|
||||||
currently_dragged_area = to_handle
|
currently_dragged_area = to_handle
|
||||||
to_handle.is_dragged = input.pressed
|
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))
|
# Alternative might be to check for specific values within the script ("is_card" f.e))
|
||||||
match dragableType:
|
match dragableType:
|
||||||
1: # 1 = Card
|
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
|
2: # 2 = PostIt
|
||||||
if input.is_pressed():
|
if input.is_pressed():
|
||||||
to_handle.reparent(dropzone)
|
to_handle.reparent(dropzone)
|
||||||
to_handle.set_owner(self) # needs to be here otherwise the owner disappears
|
to_handle.set_owner(self) # needs to be here otherwise the owner disappears
|
||||||
area_dict["post_its_in_list"].erase(to_handle)
|
area_dict["post_its_in_list"].erase(to_handle)
|
||||||
area_dict["dropzone_content"].push_back(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:
|
else:
|
||||||
if !is_in_dropzone(to_handle):
|
if !is_in_dropzone(to_handle):
|
||||||
for panel in area_dict["post_it_panels"]:
|
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.reparent(panel)
|
||||||
to_handle.set_owner(self)
|
to_handle.set_owner(self)
|
||||||
area_dict["dropzone_content"].erase(to_handle)
|
area_dict["dropzone_content"].erase(to_handle)
|
||||||
area_dict["post_its_in_list"].push_back(to_handle)
|
area_dict["post_its_in_list"].push_back(to_handle)
|
||||||
# TODO: Add function to rearrange the array based on taken panel spot
|
# 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
|
break
|
||||||
|
currently_dragged_area = null
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -107,8 +107,6 @@ func _on_input_event(viewport, event, shape_idx):
|
||||||
|
|
||||||
if event is InputEventMouseButton:
|
if event is InputEventMouseButton:
|
||||||
if event.button_index == MOUSE_BUTTON_LEFT:
|
if event.button_index == MOUSE_BUTTON_LEFT:
|
||||||
if is_dragable:
|
if is_dragable and "handle_mouse_button" in owner:
|
||||||
is_dragged = event.pressed
|
|
||||||
if "handle_mouse_button" in owner:
|
|
||||||
owner.handle_mouse_button(self, event, 1)
|
owner.handle_mouse_button(self, event, 1)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,9 @@ custom_minimum_size = Vector2(400, 120)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
mouse_filter = 1
|
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")]
|
[node name="post-it" parent="HBoxContainer/ScrollContainer/VBoxContainer/Panel" instance=ExtResource("5_048k0")]
|
||||||
z_index = 1
|
z_index = 1
|
||||||
position = Vector2(105, 57)
|
position = Vector2(105, 57)
|
||||||
|
|
@ -71,6 +74,9 @@ custom_minimum_size = Vector2(400, 120)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
mouse_filter = 1
|
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")]
|
[node name="post-it" parent="HBoxContainer/ScrollContainer/VBoxContainer/Panel2" instance=ExtResource("5_048k0")]
|
||||||
position = Vector2(105, 57)
|
position = Vector2(105, 57)
|
||||||
is_dragable = true
|
is_dragable = true
|
||||||
|
|
@ -80,6 +86,9 @@ custom_minimum_size = Vector2(400, 120)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
mouse_filter = 1
|
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")]
|
[node name="post-it" parent="HBoxContainer/ScrollContainer/VBoxContainer/Panel3" instance=ExtResource("5_048k0")]
|
||||||
position = Vector2(105, 57)
|
position = Vector2(105, 57)
|
||||||
is_dragable = true
|
is_dragable = true
|
||||||
|
|
@ -89,6 +98,9 @@ custom_minimum_size = Vector2(400, 120)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
mouse_filter = 1
|
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")]
|
[node name="post-it" parent="HBoxContainer/ScrollContainer/VBoxContainer/Panel4" instance=ExtResource("5_048k0")]
|
||||||
position = Vector2(105, 57)
|
position = Vector2(105, 57)
|
||||||
is_dragable = true
|
is_dragable = true
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue