-
Notifications
You must be signed in to change notification settings - Fork 1
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 #232 from gmuGADIG/cursor
Cursor Implementation
- Loading branch information
Showing
15 changed files
with
367 additions
and
184 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions
34
ui/hud/Health-Stamina-Item-Points Bar/Bone Cursor.png.import
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,34 @@ | ||
[remap] | ||
|
||
importer="texture" | ||
type="CompressedTexture2D" | ||
uid="uid://cjircwm8tdu4d" | ||
path="res://.godot/imported/Bone Cursor.png-f281118d653885d4311a33641512cf32.ctex" | ||
metadata={ | ||
"vram_texture": false | ||
} | ||
|
||
[deps] | ||
|
||
source_file="res://ui/hud/Health-Stamina-Item-Points Bar/Bone Cursor.png" | ||
dest_files=["res://.godot/imported/Bone Cursor.png-f281118d653885d4311a33641512cf32.ctex"] | ||
|
||
[params] | ||
|
||
compress/mode=0 | ||
compress/high_quality=false | ||
compress/lossy_quality=0.7 | ||
compress/hdr_compression=1 | ||
compress/normal_map=0 | ||
compress/channel_pack=0 | ||
mipmaps/generate=false | ||
mipmaps/limit=-1 | ||
roughness/mode=0 | ||
roughness/src_normal="" | ||
process/fix_alpha_border=true | ||
process/premult_alpha=false | ||
process/normal_map_invert_y=false | ||
process/hdr_as_srgb=false | ||
process/hdr_clamp_exposure=false | ||
process/size_limit=0 | ||
detect_3d/compress_to=1 |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,34 @@ | ||
[remap] | ||
|
||
importer="texture" | ||
type="CompressedTexture2D" | ||
uid="uid://7b1ppph6fblr" | ||
path="res://.godot/imported/Bone Cursor.png-c183921bf6e5b58afaf2a59597748520.ctex" | ||
metadata={ | ||
"vram_texture": false | ||
} | ||
|
||
[deps] | ||
|
||
source_file="res://ui/mouse_cursor/Bone Cursor.png" | ||
dest_files=["res://.godot/imported/Bone Cursor.png-c183921bf6e5b58afaf2a59597748520.ctex"] | ||
|
||
[params] | ||
|
||
compress/mode=0 | ||
compress/high_quality=false | ||
compress/lossy_quality=0.7 | ||
compress/hdr_compression=1 | ||
compress/normal_map=0 | ||
compress/channel_pack=0 | ||
mipmaps/generate=false | ||
mipmaps/limit=-1 | ||
roughness/mode=0 | ||
roughness/src_normal="" | ||
process/fix_alpha_border=true | ||
process/premult_alpha=false | ||
process/normal_map_invert_y=false | ||
process/hdr_as_srgb=false | ||
process/hdr_clamp_exposure=false | ||
process/size_limit=0 | ||
detect_3d/compress_to=1 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,34 @@ | ||
[remap] | ||
|
||
importer="texture" | ||
type="CompressedTexture2D" | ||
uid="uid://cbet2d24bw22v" | ||
path="res://.godot/imported/BoneCursorSmall.png-0ef3607bd33bea91cc8be9d5f6d562f1.ctex" | ||
metadata={ | ||
"vram_texture": false | ||
} | ||
|
||
[deps] | ||
|
||
source_file="res://ui/mouse_cursor/BoneCursorSmall.png" | ||
dest_files=["res://.godot/imported/BoneCursorSmall.png-0ef3607bd33bea91cc8be9d5f6d562f1.ctex"] | ||
|
||
[params] | ||
|
||
compress/mode=0 | ||
compress/high_quality=false | ||
compress/lossy_quality=0.7 | ||
compress/hdr_compression=1 | ||
compress/normal_map=0 | ||
compress/channel_pack=0 | ||
mipmaps/generate=false | ||
mipmaps/limit=-1 | ||
roughness/mode=0 | ||
roughness/src_normal="" | ||
process/fix_alpha_border=true | ||
process/premult_alpha=false | ||
process/normal_map_invert_y=false | ||
process/hdr_as_srgb=false | ||
process/hdr_clamp_exposure=false | ||
process/size_limit=0 | ||
detect_3d/compress_to=1 |
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,48 @@ | ||
extends Node2D | ||
class_name Cursor | ||
|
||
## Number of seconds before the cursor starts to fade after no controller input | ||
@export var before_fade: float = .2 | ||
## Number of seconds the cursor fades over after no controller input | ||
@export var fade_time: float = .5 | ||
## Curve to ease out the fading | ||
@export_exp_easing var fade_ease: float = 1. | ||
|
||
|
||
static var instance : Cursor | ||
|
||
var time_since_controller_input: float = INF | ||
|
||
# Called when the node enters the scene tree for the first time. | ||
func _init() -> void: | ||
instance = self | ||
|
||
#Sets the cursor mode to controller, hides the actual cursor and replaces it with a sprite | ||
func controller_mode() -> void: | ||
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) | ||
visible = true | ||
|
||
#Sets the cursor mode to mouse, hides the fake cursor sprite and shows the real cursor | ||
func mouse_mode() -> void: | ||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) | ||
visible = false | ||
|
||
# if t < before_fade, then alpha = 1 | ||
# if before_fade < t < fade_time, then alpha is linearly going down over fade_time | ||
# if t > fade_time, then alpha is zero | ||
func alpha_from_time(t: float) -> float: | ||
t -= before_fade | ||
return clampf(remap(t, 0, fade_time, 1, 0), 0, 1) | ||
|
||
func _process(delta: float) -> void: | ||
var input := Input.get_vector("look_left", "look_right", "look_up", "look_down").normalized() | ||
var is_moving := ControllerManager.is_controller and input != Vector2.ZERO | ||
print("input = ", input, " is_moving = ", is_moving, " t = ", time_since_controller_input, " alpha = ", modulate.a) | ||
|
||
if is_moving: | ||
rotation = ControllerManager.get_joystick_aim().angle() | ||
time_since_controller_input = 0 | ||
else: | ||
time_since_controller_input += delta | ||
|
||
modulate.a = ease(alpha_from_time(time_since_controller_input), fade_ease) |
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,14 @@ | ||
[gd_scene load_steps=3 format=3 uid="uid://c5k5rgonv1752"] | ||
|
||
[ext_resource type="Script" path="res://ui/mouse_cursor/cursor.gd" id="1_7v6mf"] | ||
[ext_resource type="Texture2D" uid="uid://cbet2d24bw22v" path="res://ui/mouse_cursor/BoneCursorSmall.png" id="2_rr5dk"] | ||
|
||
[node name="Cursor" type="Node2D"] | ||
script = ExtResource("1_7v6mf") | ||
|
||
[node name="ControllerCursorSprite" type="Sprite2D" parent="."] | ||
position = Vector2(90, 0) | ||
rotation = 1.9635 | ||
scale = Vector2(1.5, 1.5) | ||
texture = ExtResource("2_rr5dk") | ||
offset = Vector2(2, 0) |
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
Oops, something went wrong.