summaryrefslogtreecommitdiff
path: root/cursor.gd
blob: b8aac5772fde302778cb2f2ab901d6a4946aa6e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
extends Node2D


var sprite: Sprite

var current_action_idx := 0
var last_action_idx := 0


func _ready() -> void:
	sprite = preload("res://sprite.tscn").instantiate()
	sprite.load_file("res://data/extracted/data/sprite/cursors.spr")
	add_child(sprite)
	
	sprite.action_data.frame_times[0] *= 2.0
	for idx in sprite.action_data.frame_times.size():
		sprite.action_data.frame_times[idx] *= 1.0
	
	Input.mouse_mode = Input.MOUSE_MODE_HIDDEN


func _process(_delta: float) -> void:
	sprite.global_position = get_global_mouse_position()
	
	if Input.get_current_cursor_shape() == Input.CURSOR_ARROW:
		current_action_idx = 0
	elif Input.get_current_cursor_shape() == Input.CURSOR_POINTING_HAND:
		current_action_idx = 2
	else:
		current_action_idx = -1
	
	if current_action_idx == -1:
		Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
		sprite.visible = false
	elif current_action_idx != last_action_idx:
		sprite.set_current_action(current_action_idx)
		Input.mouse_mode = Input.MOUSE_MODE_HIDDEN
		sprite.visible = true
	
	if current_action_idx == 0 and sprite.get_node("%SpriteLayers").get_child_count() == 1:
		Input.set_custom_mouse_cursor(sprite.get_node("%SpriteLayers").get_child(0).texture.get_image())
		Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
		sprite.visible = false
	
	last_action_idx = current_action_idx


func _input(event: InputEvent) -> void:
	if event is InputEventMouseButton:
		pass