2024-07-25 16:26:18 +00:00
|
|
|
[gd_scene load_steps=8 format=3 uid="uid://524sv8spw6go"]
|
2024-07-25 12:08:44 +00:00
|
|
|
|
2024-07-25 14:36:40 +00:00
|
|
|
[ext_resource type="Texture2D" uid="uid://q1rdbr8uh78r" path="res://textures/cursor_default.tres" id="1_50ts1"]
|
2024-07-25 16:26:18 +00:00
|
|
|
[ext_resource type="Texture2D" uid="uid://bdstohvc7pvot" path="res://textures/cursor_click.tres" id="1_h0do2"]
|
2024-07-25 14:36:40 +00:00
|
|
|
[ext_resource type="Texture2D" uid="uid://buxws7r3kn0d7" path="res://textures/cursor_grab_01.tres" id="3_fj3w4"]
|
|
|
|
[ext_resource type="Texture2D" uid="uid://pbahcjllgjjq" path="res://textures/cursor_grab_02.tres" id="4_153q8"]
|
|
|
|
[ext_resource type="Texture2D" uid="uid://6fajq480n7se" path="res://textures/cursor_grab_03.tres" id="5_tsejy"]
|
2024-07-25 12:08:44 +00:00
|
|
|
|
|
|
|
[sub_resource type="GDScript" id="GDScript_h2l04"]
|
|
|
|
script/source = "extends Node2D
|
|
|
|
|
|
|
|
const Speed:float = 900
|
|
|
|
|
2024-07-25 14:36:40 +00:00
|
|
|
var spaceState
|
|
|
|
var query
|
|
|
|
var CastResult
|
|
|
|
var old_result
|
|
|
|
var selectedSticker
|
2024-07-25 16:26:18 +00:00
|
|
|
enum CURSOR_STATE {DEFAULT, CLICK, GRAB, GRABBED}
|
|
|
|
var currentCursorState:CURSOR_STATE
|
|
|
|
var oldCursorState:CURSOR_STATE
|
2024-07-25 14:36:40 +00:00
|
|
|
|
2024-07-25 12:08:44 +00:00
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready():
|
2024-07-25 14:36:40 +00:00
|
|
|
if not OS.is_debug_build():
|
|
|
|
Input.set_mouse_mode(Input.MOUSE_MODE_CONFINED_HIDDEN)
|
|
|
|
query = PhysicsPointQueryParameters2D.new()
|
|
|
|
spaceState = get_world_2d()
|
2024-07-25 12:08:44 +00:00
|
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
|
|
func _process(delta):
|
2024-07-25 14:36:40 +00:00
|
|
|
|
|
|
|
#region Mouse Position
|
|
|
|
position = get_global_mouse_position()
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
pointcast()
|
|
|
|
cursor_look()
|
|
|
|
|
|
|
|
|
2024-07-26 09:50:52 +00:00
|
|
|
func isSticker(selectedObject:Node):
|
|
|
|
var _isSticker:bool = false
|
|
|
|
var _tags = getTags(selectedObject)
|
|
|
|
if (_tags.size() > 0):
|
|
|
|
if (_tags.find(\"sticker\") != -1):
|
|
|
|
_isSticker = true
|
|
|
|
|
|
|
|
return _isSticker
|
|
|
|
|
|
|
|
func getTags(selectedObject:Node):
|
|
|
|
var _tags: Array
|
|
|
|
if (selectedObject.has_meta(\"tags\")):
|
|
|
|
_tags = selectedObject.get_meta(\"tags\")
|
|
|
|
return _tags
|
|
|
|
else:
|
|
|
|
printerr(\"no tags inside %\",selectedObject)
|
|
|
|
return _tags
|
|
|
|
|
|
|
|
|
2024-07-25 14:36:40 +00:00
|
|
|
func pointcast():
|
|
|
|
query.collide_with_areas = true
|
|
|
|
query.position = get_global_mouse_position()
|
|
|
|
CastResult = spaceState.direct_space_state.intersect_point(query)
|
|
|
|
if ( (CastResult.size() > 0) and (old_result != CastResult) ):
|
|
|
|
old_result = CastResult
|
2024-07-26 09:50:52 +00:00
|
|
|
if (CastResult.size()> 2):
|
|
|
|
breakpoint # should not detect multiple areas
|
2024-07-25 14:36:40 +00:00
|
|
|
for _result in CastResult:
|
|
|
|
if (_result.collider.input_pickable == true):
|
|
|
|
selectedSticker = _result.collider.get_parent()
|
2024-07-26 09:50:52 +00:00
|
|
|
if (isSticker(selectedSticker)):
|
|
|
|
print(\"selected sticker %\",selectedSticker)
|
|
|
|
else:
|
|
|
|
selectedSticker = null
|
|
|
|
if (CastResult.size() == 0 ):
|
2024-07-25 14:36:40 +00:00
|
|
|
CastResult.clear()
|
|
|
|
old_result = null
|
|
|
|
selectedSticker = null
|
|
|
|
|
|
|
|
func cursor_look():
|
2024-07-25 16:26:18 +00:00
|
|
|
|
|
|
|
if (Input.is_action_pressed(\"select\")):
|
|
|
|
if (selectedSticker):
|
|
|
|
currentCursorState = CURSOR_STATE.GRABBED
|
|
|
|
else:
|
|
|
|
currentCursorState = CURSOR_STATE.CLICK
|
2024-07-25 14:36:40 +00:00
|
|
|
else:
|
2024-07-25 16:26:18 +00:00
|
|
|
if (selectedSticker):
|
|
|
|
currentCursorState = CURSOR_STATE.GRAB
|
|
|
|
else:
|
|
|
|
currentCursorState = CURSOR_STATE.DEFAULT
|
|
|
|
|
|
|
|
if (currentCursorState != oldCursorState):
|
|
|
|
oldCursorState = currentCursorState
|
|
|
|
match oldCursorState:
|
|
|
|
CURSOR_STATE.DEFAULT:
|
|
|
|
$AnimatedSprite2D.play(\"default\")
|
|
|
|
CURSOR_STATE.CLICK:
|
|
|
|
$AnimatedSprite2D.play(\"click\")
|
|
|
|
CURSOR_STATE.GRAB:
|
|
|
|
$AnimatedSprite2D.play(\"grab_intro\")
|
|
|
|
CURSOR_STATE.GRABBED:
|
|
|
|
$AnimatedSprite2D.play(\"grab\")
|
2024-07-25 12:08:44 +00:00
|
|
|
"
|
|
|
|
|
2024-07-25 14:36:40 +00:00
|
|
|
[sub_resource type="SpriteFrames" id="SpriteFrames_u3xkr"]
|
|
|
|
resource_local_to_scene = true
|
|
|
|
animations = [{
|
|
|
|
"frames": [{
|
|
|
|
"duration": 1.0,
|
2024-07-25 16:26:18 +00:00
|
|
|
"texture": ExtResource("1_h0do2")
|
|
|
|
}],
|
|
|
|
"loop": true,
|
|
|
|
"name": &"click",
|
|
|
|
"speed": 5.0
|
|
|
|
}, {
|
|
|
|
"frames": [{
|
|
|
|
"duration": 1.0,
|
2024-07-25 14:36:40 +00:00
|
|
|
"texture": ExtResource("1_50ts1")
|
|
|
|
}],
|
|
|
|
"loop": true,
|
|
|
|
"name": &"default",
|
|
|
|
"speed": 5.0
|
|
|
|
}, {
|
|
|
|
"frames": [{
|
|
|
|
"duration": 1.0,
|
|
|
|
"texture": ExtResource("3_fj3w4")
|
|
|
|
}, {
|
|
|
|
"duration": 1.0,
|
|
|
|
"texture": ExtResource("4_153q8")
|
|
|
|
}, {
|
|
|
|
"duration": 1.0,
|
|
|
|
"texture": ExtResource("5_tsejy")
|
|
|
|
}],
|
|
|
|
"loop": false,
|
|
|
|
"name": &"grab",
|
|
|
|
"speed": 7.0
|
|
|
|
}, {
|
|
|
|
"frames": [{
|
|
|
|
"duration": 1.0,
|
|
|
|
"texture": ExtResource("3_fj3w4")
|
|
|
|
}],
|
|
|
|
"loop": true,
|
|
|
|
"name": &"grab_intro",
|
|
|
|
"speed": 5.0
|
|
|
|
}]
|
2024-07-25 12:08:44 +00:00
|
|
|
|
|
|
|
[node name="Cursor" type="Node2D"]
|
|
|
|
top_level = true
|
|
|
|
script = SubResource("GDScript_h2l04")
|
|
|
|
|
2024-07-25 14:36:40 +00:00
|
|
|
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
|
|
|
scale = Vector2(1.5, 1.5)
|
|
|
|
sprite_frames = SubResource("SpriteFrames_u3xkr")
|
2024-07-25 16:26:18 +00:00
|
|
|
animation = &"grab"
|
|
|
|
autoplay = "grab"
|
|
|
|
frame = 2
|
|
|
|
frame_progress = 1.0
|
2024-07-25 12:08:44 +00:00
|
|
|
centered = false
|
2024-07-25 14:36:40 +00:00
|
|
|
offset = Vector2(-80, -190)
|