Compare commits
2 commits
0d315e3f90
...
06184afcb8
Author | SHA1 | Date | |
---|---|---|---|
06184afcb8 | |||
e4e21741c1 |
6 changed files with 117 additions and 29 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,7 +72,11 @@ func pointcast():
|
|||
if (isSticker(hoveredObject)):
|
||||
hoveredSticker = hoveredObject
|
||||
print("Current hovered sticker :", hoveredSticker)
|
||||
if (hoveredSticker.has_method("on_hover")):
|
||||
hoveredSticker.on_hover()
|
||||
else:
|
||||
if (hoveredSticker.has_method("on_unhover")):
|
||||
hoveredSticker.on_unhover()
|
||||
hoveredSticker = null
|
||||
else:
|
||||
resetCast(true)
|
||||
|
@ -82,6 +87,8 @@ func resetCast(bFull = false):
|
|||
CastResult.clear()
|
||||
hoveredObjects.clear()
|
||||
if bFull:
|
||||
if (hoveredObject and hoveredObject.has_method("on_unhover")):
|
||||
hoveredObject.on_unhover()
|
||||
hoveredObject = null
|
||||
hoveredSticker = null
|
||||
|
||||
|
@ -99,23 +106,36 @@ 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):
|
||||
$GrabTimer.start()
|
||||
else:
|
||||
currentCursorState = CURSOR_STATE.CLICK
|
||||
if(hoveredObject):
|
||||
hoveredObject.click.emit()
|
||||
else:
|
||||
if (hoveredSticker):
|
||||
currentCursorState = CURSOR_STATE.GRAB
|
||||
else:
|
||||
currentCursorState = CURSOR_STATE.DEFAULT
|
||||
func _input(rawInputEvent:InputEvent):
|
||||
if (rawInputEvent.is_action_pressed("select")):
|
||||
cursorClick()
|
||||
$GrabTimer.start()
|
||||
if (rawInputEvent.is_action_released("select")):
|
||||
$GrabTimer.stop()
|
||||
if (grabbedSticker):
|
||||
grab_end()
|
||||
|
||||
func grab_start():
|
||||
if (hoveredSticker):
|
||||
grabbedSticker = hoveredSticker
|
||||
print("Grabbed ", grabbedSticker)
|
||||
|
||||
func grab_end():
|
||||
grabbedSticker.on_released()
|
||||
|
||||
print("stopg grabbin at ",query.position )
|
||||
DebugDraw.points.append(query.position)
|
||||
DebugDraw.drawPoints()
|
||||
#TODO: Drop the sticker or maybe he will auto-drop ?
|
||||
|
||||
grabbedSticker = null
|
||||
|
||||
func cursorClick():
|
||||
if (hoveredObject and hoveredObject.has_method("on_click")):
|
||||
hoveredObject.on_click()
|
||||
|
||||
func cursor_look():
|
||||
|
||||
if (currentCursorState != oldCursorState):
|
||||
oldCursorState = currentCursorState
|
||||
|
@ -131,6 +151,12 @@ func cursor_look():
|
|||
|
||||
|
||||
func _on_grab_timer_timeout():
|
||||
if (hoveredSticker):
|
||||
grabbedSticker = hoveredSticker
|
||||
print("Grabbed ", grabbedSticker)
|
||||
grab_start()
|
||||
|
||||
|
||||
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"]
|
|
@ -187,7 +187,7 @@ texture = ExtResource("7_gygvy")
|
|||
offset = Vector2(-251.145, -512)
|
||||
Shape = SubResource("CapsuleShape2D_dqo8w")
|
||||
Position = Vector2(0, -253.27)
|
||||
Rotation = 0.0
|
||||
Rotation = 0.01
|
||||
|
||||
[node name="Tree2" parent="." instance=ExtResource("6_3fkbm")]
|
||||
position = Vector2(-2399, -55)
|
||||
|
@ -195,7 +195,7 @@ texture = ExtResource("7_gygvy")
|
|||
offset = Vector2(-251.145, -512)
|
||||
Shape = SubResource("CapsuleShape2D_dqo8w")
|
||||
Position = Vector2(0, -253.27)
|
||||
Rotation = 0.0
|
||||
Rotation = 0.01
|
||||
|
||||
[node name="Tree3" parent="." instance=ExtResource("6_3fkbm")]
|
||||
position = Vector2(-763, -2021)
|
||||
|
@ -203,7 +203,7 @@ texture = ExtResource("7_gygvy")
|
|||
offset = Vector2(-251.145, -512)
|
||||
Shape = SubResource("CapsuleShape2D_dqo8w")
|
||||
Position = Vector2(0, -253.27)
|
||||
Rotation = 0.0
|
||||
Rotation = 0.01
|
||||
|
||||
[node name="Tree4" parent="." instance=ExtResource("6_3fkbm")]
|
||||
position = Vector2(2365, -2258)
|
||||
|
@ -211,7 +211,7 @@ texture = ExtResource("7_gygvy")
|
|||
offset = Vector2(-251.145, -512)
|
||||
Shape = SubResource("CapsuleShape2D_dqo8w")
|
||||
Position = Vector2(0, -253.27)
|
||||
Rotation = 0.0
|
||||
Rotation = 0.01
|
||||
|
||||
[node name="Bush6" parent="." instance=ExtResource("6_3fkbm")]
|
||||
position = Vector2(-1556, 293)
|
||||
|
|
|
@ -27,6 +27,22 @@ extends Sprite2D
|
|||
$Area2D/CollisionShape2D.rotation = Rotation
|
||||
$Area2D/CollisionShape2D.queue_redraw()
|
||||
|
||||
|
||||
func on_released():
|
||||
print(self,\" released\")
|
||||
|
||||
func on_click():
|
||||
print(self,\" clicked\")
|
||||
|
||||
func on_hover():
|
||||
var OutlineMat:ShaderMaterial
|
||||
OutlineMat = load(\"res://shaders/shaderMaterial_Outline.tres\")
|
||||
material = OutlineMat
|
||||
queue_redraw()
|
||||
|
||||
func on_unhover():
|
||||
material = null
|
||||
queue_redraw()
|
||||
"
|
||||
|
||||
[node name="FreeSticker1" type="Sprite2D"]
|
||||
|
@ -35,7 +51,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