summaryrefslogtreecommitdiff
path: root/ui/cursor.gd
blob: 126478958a49c32d57ca769c893f98a35535ad72 (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
extends Node2D


var current_action_idx := 0
var last_action_idx := 0

var actions: Actions


func _ready() -> void:
	if not FileAccess.file_exists("res://client_data/data/sprite/cursors/actions.tscn"):
		return
	
	actions = load("res://client_data/data/sprite/cursors/actions.tscn").instantiate()
	add_child(actions)
	
	Input.mouse_mode = Input.MOUSE_MODE_HIDDEN
	actions.play("000")


func _process(_delta: float) -> void:
	if not actions:
		return
	
	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:
		# use default OS cursor
		current_action_idx = -1
	
	if current_action_idx != last_action_idx:
		if current_action_idx == -1:
			Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
			actions.visible = false
		else:
			Input.mouse_mode = Input.MOUSE_MODE_HIDDEN
			actions.visible = true
			actions.play(str(current_action_idx).pad_zeros(3))
	
	last_action_idx = current_action_idx