-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from ligen131/feat-20240215-cursor-manager
添加用于管理鼠标指针动画的类 CursorManager
- Loading branch information
Showing
6 changed files
with
60 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
## 用于检测与鼠标重合的、[member Area2D.z_index] 最高的 [Area2D],并根据其状态设置鼠标光标形状。 | ||
class_name CursorManager extends Area2D | ||
|
||
|
||
const CURSOR_ARROW := preload("res://bg/cursor/cursor_arrow.png") ## 鼠标光标为指针时的素材。 | ||
const CURSOR_POINTING_HAND := preload("res://bg/cursor/cursor_pointing_hand.png") ## 鼠标光标为指向时的素材。 | ||
const CURSOR_DRAG := preload("res://bg/cursor/cursor_drag.png") ## 鼠标光标为拖拽时的素材。 | ||
|
||
|
||
func _ready(): | ||
Input.set_custom_mouse_cursor(CURSOR_ARROW) | ||
Input.set_custom_mouse_cursor(CURSOR_POINTING_HAND, Input.CURSOR_POINTING_HAND) | ||
Input.set_custom_mouse_cursor(CURSOR_DRAG, Input.CURSOR_DRAG) | ||
|
||
|
||
func _process(_delta): | ||
self.global_position = get_global_mouse_position() | ||
|
||
# 获取 z_index 最高的 Area2D | ||
var top_area: Area2D = null | ||
for area in get_overlapping_areas(): | ||
if top_area == null or area.z_index > top_area.z_index: | ||
top_area = area | ||
|
||
if top_area == null: | ||
Input.set_custom_mouse_cursor(CURSOR_ARROW) | ||
elif top_area is Card: | ||
if top_area.is_dragging: | ||
Input.set_custom_mouse_cursor(CURSOR_DRAG) | ||
else: | ||
Input.set_custom_mouse_cursor(CURSOR_POINTING_HAND) | ||
elif top_area is CardBase: | ||
if top_area.get_card_count() > 0: | ||
Input.set_custom_mouse_cursor(CURSOR_POINTING_HAND) | ||
else: | ||
Input.set_custom_mouse_cursor(CURSOR_ARROW) | ||
else: | ||
Input.set_custom_mouse_cursor(CURSOR_ARROW) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[gd_scene load_steps=3 format=3 uid="uid://prht3u5pnjls"] | ||
|
||
[ext_resource type="Script" path="res://scripts/cursor_manager/cursor_manager.gd" id="1_v3lev"] | ||
|
||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_stfy2"] | ||
size = Vector2(0, 0) | ||
|
||
[node name="CursorManager" type="Area2D"] | ||
script = ExtResource("1_v3lev") | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] | ||
shape = SubResource("RectangleShape2D_stfy2") |