diff --git a/Maps/gym.tscn b/Maps/gym.tscn index b379b35..b32747e 100644 --- a/Maps/gym.tscn +++ b/Maps/gym.tscn @@ -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"] diff --git a/Packs/Kenney-cursors/Outline/navigation_sw.svg b/Packs/Kenney-cursors/Outline/navigation_sw.svg index e6fac9f..7a1457c 100644 --- a/Packs/Kenney-cursors/Outline/navigation_sw.svg +++ b/Packs/Kenney-cursors/Outline/navigation_sw.svg @@ -1,7 +1,7 @@ - - + + \ No newline at end of file diff --git a/core/scripts/cursor_behaviour.gd b/core/scripts/cursor_behaviour.gd index 208f544..30b6e38 100644 --- a/core/scripts/cursor_behaviour.gd +++ b/core/scripts/cursor_behaviour.gd @@ -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) diff --git a/core/scripts/player.gd b/core/scripts/player.gd index a65f631..ed165dd 100644 --- a/core/scripts/player.gd +++ b/core/scripts/player.gd @@ -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 diff --git a/dev/debug_tools.gd b/dev/debug_tools.gd new file mode 100644 index 0000000..f2de210 --- /dev/null +++ b/dev/debug_tools.gd @@ -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() diff --git a/dev/debug_tools.gd.uid b/dev/debug_tools.gd.uid new file mode 100644 index 0000000..4dce25e --- /dev/null +++ b/dev/debug_tools.gd.uid @@ -0,0 +1 @@ +uid://dj3iov1nypjpm diff --git a/dev/debug_tools.tscn b/dev/debug_tools.tscn new file mode 100644 index 0000000..4acbc71 --- /dev/null +++ b/dev/debug_tools.tscn @@ -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) diff --git a/dev/debugtool_mouse_overlay.gd b/dev/debugtool_mouse_overlay.gd new file mode 100644 index 0000000..74e4ea3 --- /dev/null +++ b/dev/debugtool_mouse_overlay.gd @@ -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 diff --git a/dev/debugtool_mouse_overlay.gd.uid b/dev/debugtool_mouse_overlay.gd.uid new file mode 100644 index 0000000..bd56c87 --- /dev/null +++ b/dev/debugtool_mouse_overlay.gd.uid @@ -0,0 +1 @@ +uid://cmvyyl6g5kgwu diff --git a/project.godot b/project.godot index 708db52..4da982f 100644 --- a/project.godot +++ b/project.godot @@ -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]