Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cursor Implementation #232

Merged
merged 2 commits into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions autoloads/controller_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ var _last_nonzero_joystick_aim := Vector2.RIGHT

func _input(event: InputEvent) -> void:
if event is InputEventKey || event is InputEventMouse:
#Run once when switching modes
if is_controller && Cursor.instance != null:
Cursor.instance.mouse_mode();
is_controller = false
return
if event is InputEventJoypadButton || event is InputEventJoypadMotion:
#Run once when switching modes
if not is_controller && Cursor.instance != null:
Cursor.instance.controller_mode();
is_controller = true

func _process(_delta: float) -> void:
Expand Down
8 changes: 7 additions & 1 deletion player/player.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=113 format=3 uid="uid://c7ck7ril2jix2"]
[gd_scene load_steps=114 format=3 uid="uid://c7ck7ril2jix2"]

[ext_resource type="Script" path="res://player/player.gd" id="1_x43mx"]
[ext_resource type="Script" path="res://player/x_ray.gd" id="3_f3hsb"]
Expand Down Expand Up @@ -30,6 +30,7 @@
[ext_resource type="Texture2D" uid="uid://bu43rimfp3dcg" path="res://player/sprites/margarita/Margarita_RollRight_Spritesheet.png" id="23_3dfgs"]
[ext_resource type="Texture2D" uid="uid://f6oohtm5b6x0" path="res://player/sprites/margarita/Margarita_RunLeft_Spritesheet.png" id="24_0ukfm"]
[ext_resource type="Texture2D" uid="uid://cv7to2pfrgt3m" path="res://player/sprites/margarita/Margarita_RunRight_Spritesheet.png" id="25_73gv5"]
[ext_resource type="PackedScene" uid="uid://c5k5rgonv1752" path="res://ui/mouse_cursor/cursor.tscn" id="29_60imv"]

[sub_resource type="AtlasTexture" id="AtlasTexture_yvtba"]
atlas = ExtResource("10_7q0er")
Expand Down Expand Up @@ -789,6 +790,11 @@ one_shot = true
[node name="HoleDetector" parent="." instance=ExtResource("6_eb6gp")]
scale = Vector2(3.3, 3.3)

[node name="Cursor" parent="." instance=ExtResource("29_60imv")]
before_fade = 0.4
fade_time = 0.3
fade_ease = 4.28709

[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
unique_name_in_owner = true
libraries = {
Expand Down
2 changes: 2 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ history/simple_history_enabled=true
[display]

window/stretch/mode="canvas_items"
mouse_cursor/custom_image="res://ui/mouse_cursor/BoneCursorSmall.png"
mouse_cursor/custom_image_hotspot=Vector2(5, 5)

[editor_plugins]

Expand Down
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 ui/hud/Health-Stamina-Item-Points Bar/Bone Cursor.png.import
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
7 changes: 6 additions & 1 deletion ui/hud/hud.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[ext_resource type="Texture2D" uid="uid://coei1l71s6ee5" path="res://ui/hud/Health-Stamina-Item-Points Bar/Background.png" id="3_khs8t"]
[ext_resource type="Texture2D" uid="uid://bntgxqb00qldt" path="res://ui/hud/Health-Stamina-Item-Points Bar/Circle.png" id="4_gkpdi"]
[ext_resource type="Texture2D" uid="uid://b41yd4g17d23i" path="res://ui/hud/Health-Stamina-Item-Points Bar/Heart Holder.png" id="8_vopoe"]
[ext_resource type="Theme" uid="uid://drqtpgod2pibc" path="res://ui/main_ui_theme.tres" id="14_c6cuy"]
[ext_resource type="Theme" uid="uid://hft8rbf0e22b" path="res://ui/main_ui_theme.tres" id="14_c6cuy"]
[ext_resource type="Script" path="res://ui/hud/life_meter.gd" id="14_xgug3"]
[ext_resource type="Texture2D" uid="uid://ct7ni5e6ke6j3" path="res://ui/hud/Health-Stamina-Item-Points Bar/Stamina Bar.png" id="15_j4tyb"]
[ext_resource type="Texture2D" uid="uid://b7r2giesc6i34" path="res://ui/hud/Health-Stamina-Item-Points Bar/Stamina Holder.png" id="16_dyhul"]
Expand Down Expand Up @@ -40,6 +40,7 @@ texture = ExtResource("16_klhy4")

[node name="Stamina" type="NinePatchRect" parent="LifeMeter"]
unique_name_in_owner = true
layout_mode = 0
offset_left = 131.0
offset_top = 152.0
offset_right = 403.0
Expand All @@ -50,6 +51,7 @@ patch_margin_top = 36

[node name="StaminaContainer" type="NinePatchRect" parent="LifeMeter"]
unique_name_in_owner = true
layout_mode = 0
offset_left = 107.0
offset_top = 135.0
offset_right = 421.0
Expand All @@ -66,6 +68,7 @@ offset_right = 40.0
offset_bottom = 40.0

[node name="Background" type="TextureRect" parent="LifeMeter"]
layout_mode = 0
offset_left = 10.0
offset_top = 4.0
offset_right = 427.0
Expand All @@ -74,6 +77,7 @@ texture = ExtResource("3_khs8t")

[node name="HeartContainer" type="NinePatchRect" parent="LifeMeter"]
unique_name_in_owner = true
layout_mode = 0
offset_right = 444.0
offset_bottom = 201.0
texture = ExtResource("8_vopoe")
Expand All @@ -82,6 +86,7 @@ patch_margin_top = 201
patch_margin_right = 19

[node name="Circle" type="TextureRect" parent="LifeMeter"]
layout_mode = 0
offset_right = 201.0
offset_bottom = 201.0
texture = ExtResource("4_gkpdi")
Expand Down
Binary file added ui/mouse_cursor/Bone Cursor.png
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 ui/mouse_cursor/Bone Cursor.png.import
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
Binary file added ui/mouse_cursor/BoneCursorSmall.png
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 ui/mouse_cursor/BoneCursorSmall.png.import
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
48 changes: 48 additions & 0 deletions ui/mouse_cursor/cursor.gd
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)
14 changes: 14 additions & 0 deletions ui/mouse_cursor/cursor.tscn
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)
6 changes: 3 additions & 3 deletions ui/pause_menu/pause_menu.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[ext_resource type="Script" path="res://ui/pause_menu/pause_menu.gd" id="1_6mimi"]
[ext_resource type="Texture2D" uid="uid://by02hyx0mbhyv" path="res://ui/kenney_input_prompts/xbox_stick_l.svg" id="2_76ohk"]
[ext_resource type="Theme" uid="uid://hft8rbf0e22b" path="res://ui/main_ui_theme.tres" id="2_evlcd"]
[ext_resource type="Theme" uid="uid://drqtpgod2pibc" path="res://ui/main_ui_theme.tres" id="2_evlcd"]
[ext_resource type="AudioStream" uid="uid://bo7hpkhva02yb" path="res://ui/sounds/SFX UI Click 1.wav" id="2_svg3h"]
[ext_resource type="Texture2D" uid="uid://cuxosj0xqko5o" path="res://ui/kenney_input_prompts/xbox_stick_r.svg" id="3_6tfxa"]
[ext_resource type="Texture2D" uid="uid://b3mgh5kqkg4ts" path="res://ui/kenney_input_prompts/switch_buttons_down.svg" id="5_c4k42"]
Expand Down Expand Up @@ -334,8 +334,8 @@ vertical_alignment = 2
[node name="OptionsMenu" parent="." instance=ExtResource("32_pok70")]
visible = false

[connection signal="pressed" from="Panel/Resume" to="." method="_on_menu_major_button_pressed"]
[connection signal="pressed" from="Panel/Resume" to="." method="_on_resume_pressed"]
[connection signal="pressed" from="Panel/Quit" to="." method="_on_menu_major_button_pressed"]
[connection signal="pressed" from="Panel/Resume" to="." method="_on_menu_major_button_pressed"]
[connection signal="pressed" from="Panel/Quit" to="." method="_on_quit_pressed"]
[connection signal="pressed" from="Panel/Quit" to="." method="_on_menu_major_button_pressed"]
[connection signal="pressed" from="Panel/OptionsMenuButton" to="." method="_on_menu_major_button_pressed"]
2 changes: 1 addition & 1 deletion ui/title/title_screen.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,6 @@ visible = false
[connection signal="pressed" from="ContinueGame" to="." method="_on_menu_major_button_pressed"]
[connection signal="pressed" from="Quit" to="." method="_on_quit_pressed"]
[connection signal="pressed" from="Quit" to="." method="_on_menu_major_button_pressed"]
[connection signal="pressed" from="NewGame" to="." method="_on_menu_major_button_pressed"]
[connection signal="pressed" from="NewGame" to="." method="_on_new_game_pressed"]
[connection signal="pressed" from="NewGame" to="." method="_on_menu_major_button_pressed"]
[connection signal="pressed" from="Options" to="." method="_on_menu_major_button_pressed"]
Loading