mirror of
https://github.com/tonytins/dressupzack
synced 2025-05-05 13:34:48 -04:00
Advanced drag and drop system finished
This commit is contained in:
parent
ed75c25fef
commit
9ff5c5aae3
6 changed files with 28 additions and 9 deletions
|
@ -45,6 +45,7 @@ enabled=PackedStringArray("res://addons/SpritesheetGenerator/plugin.cfg", "res:/
|
|||
|
||||
folder_colors={
|
||||
"res://addons/": "blue",
|
||||
"res://fonts/": "teal",
|
||||
"res://resources/": "orange",
|
||||
"res://scenes/": "purple",
|
||||
"res://scripts/": "green",
|
||||
|
@ -52,6 +53,10 @@ folder_colors={
|
|||
"res://sprites/": "yellow"
|
||||
}
|
||||
|
||||
[filesystem]
|
||||
|
||||
import/blender/enabled=false
|
||||
|
||||
[importer_defaults]
|
||||
|
||||
texture={
|
||||
|
@ -89,7 +94,6 @@ ui_pause={
|
|||
click={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null)
|
||||
, Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":2,"canceled":false,"pressed":false,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
|
@ -133,7 +133,7 @@ position = Vector2(12, 81)
|
|||
texture = ExtResource("2_p4oam")
|
||||
metadata/_edit_lock_ = true
|
||||
|
||||
[node name="Bottom" type="TextureRect" parent="."]
|
||||
[node name="Bottom" type="TextureRect" parent="." groups=["bottoms"]]
|
||||
offset_left = -49.0
|
||||
offset_top = 116.0
|
||||
offset_right = 62.0
|
||||
|
|
|
@ -5,14 +5,14 @@
|
|||
|
||||
[node name="Demo" type="Node2D"]
|
||||
|
||||
[node name="Platform" parent="." instance=ExtResource("1_31w52")]
|
||||
[node name="Platform" parent="." groups=["dropable"] instance=ExtResource("1_31w52")]
|
||||
position = Vector2(170, 92)
|
||||
|
||||
[node name="Platform2" parent="." instance=ExtResource("1_31w52")]
|
||||
[node name="Platform2" parent="." groups=["dropable"] instance=ExtResource("1_31w52")]
|
||||
position = Vector2(419, 84)
|
||||
|
||||
[node name="Platform3" parent="." instance=ExtResource("1_31w52")]
|
||||
[node name="Platform3" parent="." groups=["dropable"] instance=ExtResource("1_31w52")]
|
||||
position = Vector2(296, 286)
|
||||
|
||||
[node name="Object" parent="." instance=ExtResource("2_cgl4f")]
|
||||
position = Vector2(301, 146)
|
||||
position = Vector2(169, 90)
|
||||
|
|
|
@ -50,6 +50,7 @@ grow_horizontal = 2
|
|||
grow_vertical = 2
|
||||
theme = ExtResource("5_gf1vk")
|
||||
script = ExtResource("4_pqv2p")
|
||||
metadata/_edit_use_anchors_ = true
|
||||
metadata/_edit_lock_ = true
|
||||
|
||||
[node name="Panel" type="Panel" parent="GUI"]
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
# See the LICENSE file in the project root for more information.
|
||||
extends Node2D
|
||||
|
||||
@export var group: String = "dropable"
|
||||
|
||||
var is_draggable = false
|
||||
var is_inside_dropable = false
|
||||
var body_ref
|
||||
|
@ -11,19 +13,31 @@ var offset: Vector2
|
|||
func _process(delta):
|
||||
if is_draggable:
|
||||
if Input.is_action_just_pressed("click"):
|
||||
offset = get_global_mouse_position() - global_position
|
||||
offset = global_position - get_global_mouse_position()
|
||||
Global.is_dragging = true
|
||||
|
||||
if Input.is_action_pressed("click"):
|
||||
global_position = get_global_mouse_position() - offset
|
||||
elif Input.is_action_just_released("click"):
|
||||
Global.is_dragging = false
|
||||
var tween = get_tree().create_tween()
|
||||
if is_inside_dropable:
|
||||
tween.tween_property(self, "position", body_ref.position, 0.2).set_ease(Tween.EASE_OUT)
|
||||
else:
|
||||
tween.tween_property(self, "global_position", body_ref.position, 0.2).set_ease(Tween.EASE_OUT)
|
||||
|
||||
|
||||
func _on_area_2d_body_entered(body):
|
||||
if body.is_in_group('dropable'):
|
||||
if body.is_in_group(group):
|
||||
is_inside_dropable = true
|
||||
body.modulate = Color(Color.REBECCA_PURPLE, 1)
|
||||
scale = Vector2(1.05, 1.05)
|
||||
body_ref = body
|
||||
|
||||
func _on_area_2d_body_exited(body:StaticBody2D):
|
||||
if body.is_in_group('dropable'):
|
||||
if body.is_in_group(group):
|
||||
is_inside_dropable = false
|
||||
body.modulate = Color(Color.MEDIUM_PURPLE, .7)
|
||||
scale = Vector2(1.05, 1.05)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue