From e3c185e05823e30eccd7728ceda2ee57cc66fd4d Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Wed, 11 Dec 2024 12:55:08 +0100 Subject: next commit --- cursor.gd | 59 ++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 23 deletions(-) (limited to 'cursor.gd') diff --git a/cursor.gd b/cursor.gd index 851441d..b8aac57 100644 --- a/cursor.gd +++ b/cursor.gd @@ -1,35 +1,48 @@ -extends Node +extends Node2D -@export var arrow_images: Array[Texture2D] -@export_range(1.0, 10.0, 0.1) var arrow_speed := 7.0 -var arrow_idx := 0.0 +var sprite: Sprite -@export var click_images: Array[Texture2D] -@export_range(1.0, 10.0, 0.1) var click_speed := 4.0 -var click_idx := 0.0 +var current_action_idx := 0 +var last_action_idx := 0 -class CurrentCursor: - var images: Array[Texture2D] - var speed: float - var idx: float +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: + +func _process(_delta: float) -> void: + sprite.global_position = get_global_mouse_position() + if Input.get_current_cursor_shape() == Input.CURSOR_ARROW: - arrow_idx += (delta * arrow_speed) - if arrow_idx > arrow_images.size(): - arrow_idx = 0 - - Input.set_custom_mouse_cursor(arrow_images[floor(arrow_idx)], Input.CURSOR_ARROW) + current_action_idx = 0 elif Input.get_current_cursor_shape() == Input.CURSOR_POINTING_HAND: - click_idx += (delta * click_speed) - if click_idx > click_images.size(): - click_idx = 0 - - Input.set_custom_mouse_cursor(click_images[floor(click_idx)], Input.CURSOR_POINTING_HAND) + current_action_idx = 2 else: - Input.set_custom_mouse_cursor(null, Input.get_current_cursor_shape()) + 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: -- cgit v1.2.3