add Debug draw + grab logic
This commit is contained in:
parent
0d315e3f90
commit
e4e21741c1
5 changed files with 88 additions and 22 deletions
|
@ -12,6 +12,7 @@ var grabbedSticker
|
|||
enum CURSOR_STATE {DEFAULT, CLICK, GRAB, GRABBED}
|
||||
var currentCursorState:CURSOR_STATE = CURSOR_STATE.DEFAULT
|
||||
var oldCursorState:CURSOR_STATE = CURSOR_STATE.DEFAULT
|
||||
var cursorPlaying:bool
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
|
@ -56,7 +57,7 @@ func pointcast():
|
|||
# CastResult is not reliable. Objects are added randomly in the array
|
||||
# so we need to filter/sort the trace result
|
||||
if ( CastResult.size() > 0 and (grabbedSticker == null)):
|
||||
#hoveredObjects.clear()
|
||||
|
||||
#region Fill HoveredObjects
|
||||
for _object in CastResult:
|
||||
if(_object.collider.input_pickable == true):
|
||||
|
@ -71,6 +72,8 @@ func pointcast():
|
|||
if (isSticker(hoveredObject)):
|
||||
hoveredSticker = hoveredObject
|
||||
print("Current hovered sticker :", hoveredSticker)
|
||||
if (hoveredSticker.has_method("on_hover")):
|
||||
hoveredSticker.on_hover()
|
||||
else:
|
||||
hoveredSticker = null
|
||||
else:
|
||||
|
@ -99,23 +102,29 @@ func comparePosY(a, b):
|
|||
#print("Compare ",a," at ",a.position.y, " and ",b," at ",b.position.y )
|
||||
return a.position.y < b.position.y
|
||||
|
||||
func cursor_look():
|
||||
|
||||
if (Input.is_action_pressed("select")):
|
||||
if (hoveredSticker):
|
||||
currentCursorState = CURSOR_STATE.GRABBED
|
||||
if ($GrabTimer.is_stopped() and not grabbedSticker):
|
||||
func _input(rawInputEvent:InputEvent):
|
||||
if (rawInputEvent.is_action_pressed("select")):
|
||||
cursorClick()
|
||||
$GrabTimer.start()
|
||||
else:
|
||||
currentCursorState = CURSOR_STATE.CLICK
|
||||
if(hoveredObject):
|
||||
hoveredObject.click.emit()
|
||||
else:
|
||||
if (hoveredSticker):
|
||||
currentCursorState = CURSOR_STATE.GRAB
|
||||
else:
|
||||
currentCursorState = CURSOR_STATE.DEFAULT
|
||||
if (rawInputEvent.is_action_released("select")):
|
||||
$GrabTimer.stop()
|
||||
if (grabbedSticker):
|
||||
grab_end()
|
||||
|
||||
func grab_end():
|
||||
grabbedSticker.on_released()
|
||||
grabbedSticker = null
|
||||
print("stopg grabbin at ",query.position )
|
||||
DebugDraw.points.append(query.position)
|
||||
DebugDraw.drawPoints()
|
||||
#TODO: Drop the sticker
|
||||
|
||||
func cursorClick():
|
||||
if (hoveredObject and hoveredObject.has_method("on_click")):
|
||||
hoveredObject.on_click()
|
||||
|
||||
func cursor_look():
|
||||
|
||||
if (currentCursorState != oldCursorState):
|
||||
oldCursorState = currentCursorState
|
||||
|
@ -134,3 +143,11 @@ func _on_grab_timer_timeout():
|
|||
if (hoveredSticker):
|
||||
grabbedSticker = hoveredSticker
|
||||
print("Grabbed ", grabbedSticker)
|
||||
|
||||
|
||||
func _on_animated_sprite_2d_animation_changed():
|
||||
cursorPlaying = true
|
||||
|
||||
|
||||
func _on_animated_sprite_2d_animation_finished():
|
||||
cursorPlaying = false
|
||||
|
|
|
@ -14,7 +14,7 @@ animations = [{
|
|||
"duration": 1.0,
|
||||
"texture": ExtResource("1_h0do2")
|
||||
}],
|
||||
"loop": true,
|
||||
"loop": false,
|
||||
"name": &"click",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
|
@ -22,7 +22,7 @@ animations = [{
|
|||
"duration": 1.0,
|
||||
"texture": ExtResource("1_50ts1")
|
||||
}],
|
||||
"loop": true,
|
||||
"loop": false,
|
||||
"name": &"default",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
|
@ -44,7 +44,7 @@ animations = [{
|
|||
"duration": 1.0,
|
||||
"texture": ExtResource("3_fj3w4")
|
||||
}],
|
||||
"loop": true,
|
||||
"loop": false,
|
||||
"name": &"grab_intro",
|
||||
"speed": 5.0
|
||||
}]
|
||||
|
@ -56,7 +56,6 @@ script = ExtResource("1_b5uuj")
|
|||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||
scale = Vector2(1.5, 1.5)
|
||||
sprite_frames = SubResource("SpriteFrames_u3xkr")
|
||||
autoplay = "grab"
|
||||
centered = false
|
||||
offset = Vector2(-80, -190)
|
||||
|
||||
|
@ -64,4 +63,6 @@ offset = Vector2(-80, -190)
|
|||
wait_time = 0.5
|
||||
one_shot = true
|
||||
|
||||
[connection signal="animation_changed" from="AnimatedSprite2D" to="." method="_on_animated_sprite_2d_animation_changed"]
|
||||
[connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animated_sprite_2d_animation_finished"]
|
||||
[connection signal="timeout" from="GrabTimer" to="." method="_on_grab_timer_timeout"]
|
||||
|
|
42
core/debugDraw.tscn
Normal file
42
core/debugDraw.tscn
Normal file
|
@ -0,0 +1,42 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://c8ncblufqk10x"]
|
||||
|
||||
[sub_resource type="GDScript" id="GDScript_t63le"]
|
||||
script/source = "extends Node2D
|
||||
|
||||
@export var points:Array
|
||||
@export var duration:float = 1
|
||||
var radius
|
||||
var color
|
||||
|
||||
func _draw():
|
||||
for _point in points:
|
||||
draw_circle(_point,radius,color)
|
||||
|
||||
func drawPoints(_points:Array = points,_radius:float = 50.0,_color:Color = Color.CRIMSON,_duration:float = 1):
|
||||
if(_points):
|
||||
points = _points
|
||||
duration = _duration
|
||||
radius = _radius
|
||||
color = _color
|
||||
$Timer.wait_time = duration
|
||||
$Timer.start()
|
||||
queue_redraw()
|
||||
|
||||
|
||||
func _on_timer_timeout():
|
||||
points.clear()
|
||||
queue_redraw()
|
||||
|
||||
|
||||
func _on_draw():
|
||||
pass # Replace with function body.
|
||||
"
|
||||
|
||||
[node name="DebugDraw" type="Node2D"]
|
||||
script = SubResource("GDScript_t63le")
|
||||
|
||||
[node name="Timer" type="Timer" parent="."]
|
||||
one_shot = true
|
||||
|
||||
[connection signal="draw" from="." to="." method="_on_draw"]
|
||||
[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]
|
|
@ -27,6 +27,9 @@ extends Sprite2D
|
|||
$Area2D/CollisionShape2D.rotation = Rotation
|
||||
$Area2D/CollisionShape2D.queue_redraw()
|
||||
|
||||
|
||||
func on_released():
|
||||
print(self,\" released\")
|
||||
"
|
||||
|
||||
[node name="FreeSticker1" type="Sprite2D"]
|
||||
|
@ -35,7 +38,6 @@ texture = SubResource("AtlasTexture_2wdar")
|
|||
centered = false
|
||||
offset = Vector2(-161.055, -179.785)
|
||||
script = SubResource("GDScript_uqtu8")
|
||||
Rotation = Vector2(0, 0)
|
||||
metadata/tags = ["sticker"]
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="."]
|
||||
|
|
|
@ -17,6 +17,10 @@ config/features=PackedStringArray("4.2", "Mobile")
|
|||
config/icon="res://extracted/Texture2D/Map.png"
|
||||
config/windows_native_icon="res://extracted/Texture2D/Map.png"
|
||||
|
||||
[autoload]
|
||||
|
||||
DebugDraw="*res://core/debugDraw.tscn"
|
||||
|
||||
[editor_plugins]
|
||||
|
||||
enabled=PackedStringArray("res://addons/Todo_Manager/plugin.cfg")
|
||||
|
@ -60,7 +64,7 @@ sticker_mode={
|
|||
select={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":true,"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":1,"position":Vector2(143, 14),"global_position":Vector2(147, 55),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"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":1,"position":Vector2(111, 16),"global_position":Vector2(115, 57),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194309,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue