Correction edge scroll cursors + Debug tool + some documentation
This commit is contained in:
parent
2c9e1d6dab
commit
77662bf652
10 changed files with 137 additions and 19 deletions
|
@ -7,7 +7,7 @@
|
|||
[ext_resource type="ArrayMesh" uid="uid://dj5nhomlun7km" path="res://packs/Kaykit-Proto/obj/Box_B.obj" id="5_ipipj"]
|
||||
[ext_resource type="Texture2D" uid="uid://bsnc11pwypbny" path="res://packs/Kaykit-Proto/obj/prototypebits_texture.png" id="6_anror"]
|
||||
[ext_resource type="ArrayMesh" uid="uid://clfdc3wo1fn0c" path="res://packs/Kaykit-Proto/obj/Cube_Prototype_Small.obj" id="7_f8cpb"]
|
||||
[ext_resource type="PackedScene" uid="uid://djj1fc8qm10t6" path="res://core/player.tscn" id="8_mqp7f"]
|
||||
[ext_resource type="PackedScene" uid="uid://djj1fc8qm10t6" path="res://core/base-classes/player.tscn" id="8_mqp7f"]
|
||||
[ext_resource type="VoxelGIData" uid="uid://cubwphu04tyr4" path="res://generated/gym.VoxelGI_data.res" id="9_ipipj"]
|
||||
[ext_resource type="ArrayMesh" uid="uid://c0uahqnc6dx6r" path="res://packs/Kaykit-Proto/obj/Box_C.obj" id="10_iyjuv"]
|
||||
[ext_resource type="ArrayMesh" uid="uid://bde4cc1kjchsk" path="res://packs/Kaykit-Proto/obj/Door_A_Decorated.obj" id="11_gfgny"]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<svg width="32" height="32" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<defs/>
|
||||
<g>
|
||||
<path stroke="none" fill="#000000" d="M12 8.6 L11.55 8.15 10.95 8.05 Q10.65 8.15 10.45 8.35 L10.1 8.9 8.05 23.75 Q7.95 24.15 8.15 24.35 L8.55 24.75 9.15 24.85 24 22.8 24.55 22.45 24.85 21.95 24.75 21.35 24.3 20.9 16.1 16.8 12 8.6 M8.2 8.3 Q8.45 7.55 9.05 6.95 9.55 6.4 10.35 6.15 L10.95 6 12.2 6.25 12.35 6.3 Q13.45 6.8 13.8 7.7 L17.6 15.3 25.15 19.1 25.2 19.1 Q26.1 19.45 26.6 20.55 L26.65 20.75 26.85 21.95 26.75 22.6 26 23.9 24.65 24.7 24.3 24.8 9.65 26.8 Q8.05 27.25 7.25 26.35 L6.6 25.65 Q5.7 24.85 6.1 23.3 L8.15 8.65 8.2 8.3"/>
|
||||
<path stroke="none" fill="#FFFFFF" d="M12 8.6 L16.1 16.8 24.3 20.9 24.75 21.35 24.85 21.95 24.55 22.45 24 22.8 9.15 24.85 8.55 24.75 8.15 24.35 Q7.95 24.15 8.05 23.75 L10.1 8.9 10.45 8.35 Q10.65 8.15 10.95 8.05 L11.55 8.15 12 8.6"/>
|
||||
<path stroke="cursor" fill="#000000" d="M12 8.6 L11.55 8.15 10.95 8.05 Q10.65 8.15 10.45 8.35 L10.1 8.9 8.05 23.75 Q7.95 24.15 8.15 24.35 L8.55 24.75 9.15 24.85 24 22.8 24.55 22.45 24.85 21.95 24.75 21.35 24.3 20.9 16.1 16.8 12 8.6 M8.2 8.3 Q8.45 7.55 9.05 6.95 9.55 6.4 10.35 6.15 L10.95 6 12.2 6.25 12.35 6.3 Q13.45 6.8 13.8 7.7 L17.6 15.3 25.15 19.1 25.2 19.1 Q26.1 19.45 26.6 20.55 L26.65 20.75 26.85 21.95 26.75 22.6 26 23.9 24.65 24.7 24.3 24.8 9.65 26.8 Q8.05 27.25 7.25 26.35 L6.6 25.65 Q5.7 24.85 6.1 23.3 L8.15 8.65 8.2 8.3"/>
|
||||
<path stroke="outline" fill="#FFFFFF" d="M12 8.6 L16.1 16.8 24.3 20.9 24.75 21.35 24.85 21.95 24.55 22.45 24 22.8 9.15 24.85 8.55 24.75 8.15 24.35 Q7.95 24.15 8.05 23.75 L10.1 8.9 10.45 8.35 Q10.65 8.15 10.95 8.05 L11.55 8.15 12 8.6"/>
|
||||
</g>
|
||||
</svg>
|
Before Width: | Height: | Size: 912 B After Width: | Height: | Size: 917 B |
|
@ -1,24 +1,53 @@
|
|||
extends Node
|
||||
## Handle all the cursor appareance related stuff.
|
||||
|
||||
# Mapping 8 primary directions to custom cursor images
|
||||
@export var NOCUSTOM := false
|
||||
|
||||
## A dictionary mapping 9 directional vectors to custom cursor configurations for edgescroll navigation.
|
||||
##[br][br]
|
||||
## This constant defines custom cursor images and their hotspots for 8 primary directions and a neutral state,
|
||||
## used with [method Input.set_custom_mouse_cursor] to override the default mouse cursor based on
|
||||
## edgescroll direction. Each key is a [Vector2] representing a normalized direction (e.g., [code](-1, -1)[/code]
|
||||
## for top-left). Each value is an array where:[br]
|
||||
## - [b]Index 0[/b]: A preloaded [Texture2D] resource for the cursor image.[br]
|
||||
## - [b]Index 1[/b]: A [Vector2] specifying the hotspot (the pixel within the image that aligns with the mouse position).[br]
|
||||
##[br]
|
||||
##
|
||||
## [b]Direction Details:[/b][br]
|
||||
## - [code](-1, -1)[/code]: up-left.[br]
|
||||
## - [code](0, -1)[/code]: up.[br]
|
||||
## - [code](1, -1)[/code]: up-right.[br]
|
||||
## - [code](1, 0)[/code]: right.[br]
|
||||
## - [code](1, 1)[/code]: down-right.[br]
|
||||
## - [code](0, 1)[/code]: down.[br]
|
||||
## - [code](-1, 1)[/code]: down-left.[br]
|
||||
## - [code](-1, 0)[/code]: left.[br]
|
||||
## - [code](0, 0)[/code]: Neutral state (no scroll, default cursor, sued for resetting purpose).[br]
|
||||
const DIRECTION_CURSOR_MAP = {
|
||||
Vector2(-1, -1): preload("uid://bnwb6728ln3ae"),
|
||||
Vector2(0, -1): preload("uid://cgx332aowj6dn"),
|
||||
Vector2(1, -1): preload("uid://dmn7dlir4ohff"),
|
||||
Vector2(1, 0): preload("uid://bwfy3euyxmi7j"),
|
||||
Vector2(1, 1): preload("uid://cpklilc6jmw0d"),
|
||||
Vector2(0, 1): preload("uid://cbr6j5g1ipdi4"),
|
||||
Vector2(-1, 1): preload("uid://doia8nobwmv4n"),
|
||||
Vector2(-1, 0): preload("uid://bqg7s8lukudkc"),
|
||||
Vector2(0, 0): preload("uid://dp4ed16rb1754"),
|
||||
Vector2(-1, -1): [preload("uid://bnwb6728ln3ae"), Vector2(6,22)],
|
||||
Vector2(0, -1): [preload("uid://cgx332aowj6dn"),Vector2(16,22)],
|
||||
Vector2(1, -1): [preload("uid://dmn7dlir4ohff"), Vector2(22,22)],
|
||||
Vector2(1, 0): [preload("uid://bwfy3euyxmi7j"),Vector2(22,16)],
|
||||
Vector2(1, 1): [preload("uid://cpklilc6jmw0d"),Vector2(22,6)],
|
||||
Vector2(0, 1): [preload("uid://cbr6j5g1ipdi4"),Vector2(16,6)],
|
||||
Vector2(-1, 1): [preload("uid://doia8nobwmv4n"), Vector2(6,6)],
|
||||
Vector2(-1, 0): [preload("uid://bqg7s8lukudkc"),Vector2(6,16)],
|
||||
Vector2(0, 0): [preload("uid://dp4ed16rb1754"),Vector2(7,3)],
|
||||
}
|
||||
var edge_scroll_vector = Vector2(1,1)
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
if NOCUSTOM:
|
||||
Input.set_default_cursor_shape(Input.CURSOR_DRAG)
|
||||
|
||||
|
||||
func _on_player_root_cursor_edge_scrolling(direction: Vector2) -> void:
|
||||
if NOCUSTOM:return
|
||||
if direction.length() > 0 or edge_scroll_vector.length() != 0:
|
||||
#print("direction lenght = ",direction.length()," and stored vector is ", edge_scroll_vector.length())
|
||||
edge_scroll_vector = direction
|
||||
Input.set_custom_mouse_cursor(DIRECTION_CURSOR_MAP.get(direction))
|
||||
Input.set_custom_mouse_cursor(DIRECTION_CURSOR_MAP.get(direction)[0],Input.CURSOR_ARROW,DIRECTION_CURSOR_MAP.get(direction)[1])
|
||||
if OS.is_debug_build():
|
||||
DebugTools.MouseOverlay.update_cursor(DIRECTION_CURSOR_MAP.get(direction)[0],Input.CURSOR_ARROW,DIRECTION_CURSOR_MAP.get(direction)[1])
|
||||
|
||||
print(direction)
|
||||
|
|
|
@ -63,7 +63,6 @@ func _notification(what: int):
|
|||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseMotion and rotation_mode:
|
||||
print("Mouse Motion at: ", event.screen_relative)
|
||||
mouse_velocity = event.screen_relative
|
||||
cam_rotation(event.screen_relative)
|
||||
else:
|
||||
|
@ -73,7 +72,6 @@ func _input(event: InputEvent) -> void:
|
|||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event.is_action("scroll_up"):
|
||||
zoom_direction = -1
|
||||
print("scroll")
|
||||
if event.is_action("scroll_down"):
|
||||
zoom_direction = 1
|
||||
if event.is_action_pressed("rotation_mode"):
|
||||
|
@ -133,8 +131,7 @@ func cam_zoom(delta:float) -> void:
|
|||
if zoom_disabled:return
|
||||
|
||||
var new_zoom: float = clamp(cam.position.z + (zoom_speed * zoom_direction * delta),zoom_min,zoom_max)
|
||||
if new_zoom != cam.position.z and abs(zoom_direction) > 0.001:
|
||||
print("new zoom : ", new_zoom, " because zoom_direction = ",zoom_direction)
|
||||
if new_zoom != cam.position.z and abs(zoom_direction) > 0.001: # TODO: Magic Number
|
||||
cam.position.z = new_zoom
|
||||
zoom_direction *= zoom_speed_damp #Smooth the deceleration
|
||||
|
||||
|
|
8
dev/debug_tools.gd
Normal file
8
dev/debug_tools.gd
Normal file
|
@ -0,0 +1,8 @@
|
|||
extends Control
|
||||
@export var MouseOverlay: Node
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
if !OS.is_debug_build():
|
||||
self.queue_free()
|
1
dev/debug_tools.gd.uid
Normal file
1
dev/debug_tools.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://dj3iov1nypjpm
|
52
dev/debug_tools.tscn
Normal file
52
dev/debug_tools.tscn
Normal file
|
@ -0,0 +1,52 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://d363j4yjxcgw4"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cmvyyl6g5kgwu" path="res://dev/debugtool_mouse_overlay.gd" id="1_j07kd"]
|
||||
[ext_resource type="Script" uid="uid://dj3iov1nypjpm" path="res://dev/debug_tools.gd" id="1_xqln8"]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_xqln8"]
|
||||
content_margin_left = 0.0
|
||||
content_margin_top = 0.0
|
||||
content_margin_right = 0.0
|
||||
content_margin_bottom = 0.0
|
||||
bg_color = Color(0.10196078, 0.10196078, 0.10196078, 0.27450982)
|
||||
corner_radius_top_left = 3
|
||||
corner_radius_top_right = 3
|
||||
corner_radius_bottom_right = 3
|
||||
corner_radius_bottom_left = 3
|
||||
corner_detail = 5
|
||||
|
||||
[node name="DebugTools" type="Control" node_paths=PackedStringArray("MouseOverlay")]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
pivot_offset = Vector2(960, 540)
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
script = ExtResource("1_xqln8")
|
||||
MouseOverlay = NodePath("MouseCursorOverlay")
|
||||
|
||||
[node name="MouseCursorOverlay" type="CanvasLayer" parent="."]
|
||||
script = ExtResource("1_j07kd")
|
||||
|
||||
[node name="PanelContainer" type="Panel" parent="MouseCursorOverlay"]
|
||||
offset_right = 32.0
|
||||
offset_bottom = 32.0
|
||||
mouse_filter = 2
|
||||
theme_override_styles/panel = SubResource("StyleBoxFlat_xqln8")
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="MouseCursorOverlay/PanelContainer"]
|
||||
layout_mode = 0
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
stretch_mode = 2
|
||||
|
||||
[node name="HotSpotMarker" type="ColorRect" parent="MouseCursorOverlay/PanelContainer/TextureRect"]
|
||||
custom_minimum_size = Vector2(1, 1)
|
||||
layout_mode = 0
|
||||
offset_right = 4.0
|
||||
offset_bottom = 4.0
|
||||
pivot_offset = Vector2(2, 2)
|
||||
color = Color(1, 0.3137255, 1, 1)
|
27
dev/debugtool_mouse_overlay.gd
Normal file
27
dev/debugtool_mouse_overlay.gd
Normal file
|
@ -0,0 +1,27 @@
|
|||
extends CanvasLayer
|
||||
|
||||
# Track the current cursor shape
|
||||
var current_shape: int = -1
|
||||
# References to child nodes (automatically set via $ syntax)
|
||||
@onready var texture_rect = $PanelContainer/TextureRect
|
||||
@onready var hotspot_marker = $PanelContainer/TextureRect/HotSpotMarker
|
||||
|
||||
|
||||
func _process(_delta):
|
||||
# Check the current cursor shape
|
||||
var shape = Input.get_current_cursor_shape()
|
||||
#Input.set_custom_mouse_cursor()
|
||||
if shape != current_shape:
|
||||
current_shape = shape
|
||||
#update_cursor(shape)
|
||||
|
||||
|
||||
func update_cursor(image: Resource, shape: Input.CursorShape = 0, hotspot: Vector2 = Vector2(0, 0)):
|
||||
# Get the custom cursor data from the main script
|
||||
if image != null:
|
||||
texture_rect.texture = image
|
||||
# Position the hotspot marker (assuming a 4x4 marker)
|
||||
hotspot_marker.position = hotspot
|
||||
else:
|
||||
# Clear the texture if no custom cursor is set for this shape
|
||||
texture_rect.texture = null
|
1
dev/debugtool_mouse_overlay.gd.uid
Normal file
1
dev/debugtool_mouse_overlay.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://cmvyyl6g5kgwu
|
|
@ -17,6 +17,9 @@ config/project_settings_override="settings.cfg"
|
|||
config/features=PackedStringArray("4.5", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
[autoload]
|
||||
|
||||
DebugTools="*res://dev/debug_tools.tscn"
|
||||
|
||||
[display]
|
||||
|
||||
|
|
Loading…
Reference in a new issue