From 0bee8c5f9ca10c3b39b4d171934bc0b3db6faec8 Mon Sep 17 00:00:00 2001 From: Nitwel Date: Fri, 10 May 2024 13:16:17 +0200 Subject: [PATCH] improve cursor and add cursor themes --- app/assets/cursors/old.png | 3 + app/assets/cursors/old.png.import | 36 +++++ app/assets/{materials => cursors}/pointer.png | 0 .../{materials => cursors}/pointer.png.import | 8 +- app/content/entities/camera/camera.tscn | 3 +- app/content/system/raycast/raycast.gd | 23 ++- app/content/system/raycast/raycast.tscn | 17 ++- app/content/ui/components/tabs/tabs.gd | 17 +-- .../ui/components/tabs/tabs_content.gd | 2 +- .../ui/menu/settings/menus/features_menu.gd | 9 ++ .../ui/menu/settings/menus/features_menu.tscn | 135 +++++++++++++++++- app/lib/stores/settings.gd | 9 +- 12 files changed, 240 insertions(+), 22 deletions(-) create mode 100644 app/assets/cursors/old.png create mode 100644 app/assets/cursors/old.png.import rename app/assets/{materials => cursors}/pointer.png (100%) rename app/assets/{materials => cursors}/pointer.png.import (60%) diff --git a/app/assets/cursors/old.png b/app/assets/cursors/old.png new file mode 100644 index 0000000..aef3568 --- /dev/null +++ b/app/assets/cursors/old.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:58fcb3f5a4f3c2ba1c13952d999ceb53dc21a214f7a484efc4ddea84ddade5ce +size 220 diff --git a/app/assets/cursors/old.png.import b/app/assets/cursors/old.png.import new file mode 100644 index 0000000..d61c9dc --- /dev/null +++ b/app/assets/cursors/old.png.import @@ -0,0 +1,36 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://churthrr24yhw" +path.s3tc="res://.godot/imported/old.png-a60d47e8bc819babf135eb9ce84b124c.s3tc.ctex" +path.etc2="res://.godot/imported/old.png-a60d47e8bc819babf135eb9ce84b124c.etc2.ctex" +metadata={ +"imported_formats": ["s3tc_bptc", "etc2_astc"], +"vram_texture": true +} + +[deps] + +source_file="res://assets/cursors/old.png" +dest_files=["res://.godot/imported/old.png-a60d47e8bc819babf135eb9ce84b124c.s3tc.ctex", "res://.godot/imported/old.png-a60d47e8bc819babf135eb9ce84b124c.etc2.ctex"] + +[params] + +compress/mode=2 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=true +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=0 diff --git a/app/assets/materials/pointer.png b/app/assets/cursors/pointer.png similarity index 100% rename from app/assets/materials/pointer.png rename to app/assets/cursors/pointer.png diff --git a/app/assets/materials/pointer.png.import b/app/assets/cursors/pointer.png.import similarity index 60% rename from app/assets/materials/pointer.png.import rename to app/assets/cursors/pointer.png.import index 75ff2f3..fbd3b5b 100644 --- a/app/assets/materials/pointer.png.import +++ b/app/assets/cursors/pointer.png.import @@ -3,8 +3,8 @@ importer="texture" type="CompressedTexture2D" uid="uid://bl33klueufwja" -path.s3tc="res://.godot/imported/pointer.png-bc1b217fc800145e13fa1a1689c1f1ee.s3tc.ctex" -path.etc2="res://.godot/imported/pointer.png-bc1b217fc800145e13fa1a1689c1f1ee.etc2.ctex" +path.s3tc="res://.godot/imported/pointer.png-d044c796591a4272f0c14ca625e25d78.s3tc.ctex" +path.etc2="res://.godot/imported/pointer.png-d044c796591a4272f0c14ca625e25d78.etc2.ctex" metadata={ "imported_formats": ["s3tc_bptc", "etc2_astc"], "vram_texture": true @@ -12,8 +12,8 @@ metadata={ [deps] -source_file="res://assets/materials/pointer.png" -dest_files=["res://.godot/imported/pointer.png-bc1b217fc800145e13fa1a1689c1f1ee.s3tc.ctex", "res://.godot/imported/pointer.png-bc1b217fc800145e13fa1a1689c1f1ee.etc2.ctex"] +source_file="res://assets/cursors/pointer.png" +dest_files=["res://.godot/imported/pointer.png-d044c796591a4272f0c14ca625e25d78.s3tc.ctex", "res://.godot/imported/pointer.png-d044c796591a4272f0c14ca625e25d78.etc2.ctex"] [params] diff --git a/app/content/entities/camera/camera.tscn b/app/content/entities/camera/camera.tscn index 40fea7e..3249641 100644 --- a/app/content/entities/camera/camera.tscn +++ b/app/content/entities/camera/camera.tscn @@ -38,9 +38,10 @@ label = "videocam_off" icon = true [node name="Slider" parent="." instance=ExtResource("4_lfexu")] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.05, -0.1, 0) +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.02, -0.1, 0) min = 1.0 max = 30.0 value = 1.0 step = 1.0 label_unit = "FPS" +size = Vector3(0.1, 0.02, 0.01) diff --git a/app/content/system/raycast/raycast.gd b/app/content/system/raycast/raycast.gd index b2de215..56966bf 100644 --- a/app/content/system/raycast/raycast.gd +++ b/app/content/system/raycast/raycast.gd @@ -4,6 +4,8 @@ const Pointer = preload ("res://lib/utils/pointer/pointer.gd") const Initiator = preload ("res://lib/utils/pointer/initiator.gd") @onready var cursor: Node3D = $Cursor +@onready var default_cursor: Sprite3D = $Cursor/DefaultCursor +@onready var retro_cursor: Sprite3D = $Cursor/RetroCursor @onready var decal: Decal = $Decal @export var is_right: bool = true @@ -35,6 +37,16 @@ func _ready(): pointer.released(_event_type_map[button]) ) + R.effect(func(_arg): + match Store.settings.state.cursor_style: + 1: + default_cursor.visible=false + retro_cursor.visible=true + 0, _: + default_cursor.visible=true + retro_cursor.visible=false + ) + func _physics_process(_delta): _handle_cursor() @@ -58,4 +70,13 @@ func _handle_cursor(): cursor.visible = true decal.visible = false cursor.global_transform.origin = get_collision_point() + get_collision_normal() * 0.001 # offset to avoid z-fighting - cursor.global_transform.basis = Basis.looking_at(get_collision_normal(), Vector3.UP) + + if abs(get_collision_normal().dot(Vector3.UP)) > 0.9: + var ray_dir_inv = global_transform.basis.z + cursor.global_transform.basis = Basis.looking_at(get_collision_normal().lerp(ray_dir_inv, 0.01), Vector3.UP, true) + else: + cursor.global_transform.basis = Basis.looking_at(get_collision_normal(), Vector3.UP, true) + + var cursor_scale = clamp(distance * 1.5 - 0.75, 1.0, 3.0) + + cursor.scale = Vector3(cursor_scale, cursor_scale, cursor_scale) diff --git a/app/content/system/raycast/raycast.tscn b/app/content/system/raycast/raycast.tscn index af14d31..16eee93 100644 --- a/app/content/system/raycast/raycast.tscn +++ b/app/content/system/raycast/raycast.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=7 format=3 uid="uid://dscp8x0ari57n"] +[gd_scene load_steps=8 format=3 uid="uid://dscp8x0ari57n"] -[ext_resource type="Texture2D" uid="uid://bl33klueufwja" path="res://assets/materials/pointer.png" id="1_2f2iv"] +[ext_resource type="Texture2D" uid="uid://bl33klueufwja" path="res://assets/cursors/pointer.png" id="1_2f2iv"] [ext_resource type="Script" path="res://content/system/raycast/raycast.gd" id="1_gp8nv"] +[ext_resource type="Texture2D" uid="uid://churthrr24yhw" path="res://assets/cursors/old.png" id="3_f5ibs"] [ext_resource type="Shader" path="res://content/system/raycast/raycast.gdshader" id="3_lpfe7"] [ext_resource type="Texture2D" uid="uid://cy5dna78q6tn6" path="res://assets/models/ray/ray.png" id="4_fe8o8"] [ext_resource type="ArrayMesh" uid="uid://d3kriab522o2w" path="res://assets/models/ray/ray.obj" id="5_3o4gy"] @@ -28,12 +29,22 @@ lower_fade = 0.000919435 [node name="Cursor" type="Node3D" parent="."] -[node name="CursorSprite" type="Sprite3D" parent="Cursor"] +[node name="DefaultCursor" type="Sprite3D" parent="Cursor"] transform = Transform3D(0.03, 2.71051e-20, 0, -5.42101e-20, 0.03, -2.03288e-21, -2.46521e-33, 2.5411e-21, 0.03, 0, 0, 0) +visible = false pixel_size = 0.001 +texture_filter = 0 render_priority = 90 texture = ExtResource("1_2f2iv") +[node name="RetroCursor" type="Sprite3D" parent="Cursor"] +transform = Transform3D(0.03, 0, 0, 0, 0.03, 0, 0, 0, 0.03, 0, 0, 0) +offset = Vector2(5.835, -9.175) +pixel_size = 0.03 +texture_filter = 0 +render_priority = 90 +texture = ExtResource("3_f5ibs") + [node name="Ray" type="MeshInstance3D" parent="."] transform = Transform3D(1, -1.39624e-11, -6.10317e-19, 0, -4.37114e-08, 1, -1.39624e-11, -1, -4.37114e-08, 0, 0, -0.0182334) material_override = SubResource("ShaderMaterial_ov0gt") diff --git a/app/content/ui/components/tabs/tabs.gd b/app/content/ui/components/tabs/tabs.gd index 5239bd8..2735a9a 100644 --- a/app/content/ui/components/tabs/tabs.gd +++ b/app/content/ui/components/tabs/tabs.gd @@ -4,7 +4,7 @@ class_name Tabs3D signal on_select(selected: int) -var selected = R.state(null) +var selected = R.state(0) @export var initial_selected: Node3D @@ -15,23 +15,20 @@ func _ready(): return if initial_selected: - selected.value = initial_selected - - R.effect(func(_arg): - on_select.emit(selected.value) - ) + selected.value = initial_selected.get_index() for option in get_children(): if option is Button3D == false: continue option.on_button_down.connect(func(): - selected.value=option + selected.value=option.get_index() + on_select.emit(option.get_index()) ) R.effect(func(_arg): - option.active=option == selected.value - option.disabled=option == selected.value + option.active=option.get_index() == selected.value + option.disabled=option.get_index() == selected.value ) - option.toggleable = true + option.toggleable = true \ No newline at end of file diff --git a/app/content/ui/components/tabs/tabs_content.gd b/app/content/ui/components/tabs/tabs_content.gd index 1dd6b5d..6bf16a3 100644 --- a/app/content/ui/components/tabs/tabs_content.gd +++ b/app/content/ui/components/tabs/tabs_content.gd @@ -14,7 +14,7 @@ func _ready(): remove_child(child) R.effect(func(_arg): - if tabs.selected.value.get_index() == i: + if tabs.selected.value == i: add_child(child) elif child.get_parent() == self: remove_child(child) diff --git a/app/content/ui/menu/settings/menus/features_menu.gd b/app/content/ui/menu/settings/menus/features_menu.gd index 63a4902..0288217 100644 --- a/app/content/ui/menu/settings/menus/features_menu.gd +++ b/app/content/ui/menu/settings/menus/features_menu.gd @@ -1,6 +1,7 @@ extends Node3D @onready var voice_assist = $VoiceAssist +@onready var cursor_options = $CursorOptions func _ready(): var settings_store = Store.settings.state @@ -32,7 +33,15 @@ func _ready(): settings_store.voice_assistant=false Store.settings.save_local() + ) + cursor_options.selected.value = settings_store.cursor_style + + cursor_options.on_select.connect(func(option): + settings_store.cursor_style=option + settings_store.cursor_style=option + print("cursor_style", option) + Store.settings.save_local() ) R.bind(voice_assist, "label", button_label) diff --git a/app/content/ui/menu/settings/menus/features_menu.tscn b/app/content/ui/menu/settings/menus/features_menu.tscn index 0b4adb2..57ac73a 100644 --- a/app/content/ui/menu/settings/menus/features_menu.tscn +++ b/app/content/ui/menu/settings/menus/features_menu.tscn @@ -1,7 +1,56 @@ -[gd_scene load_steps=3 format=3 uid="uid://4hai6lp64m2o"] +[gd_scene load_steps=14 format=3 uid="uid://4hai6lp64m2o"] [ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="1_52ufi"] [ext_resource type="Script" path="res://content/ui/menu/settings/menus/features_menu.gd" id="1_imqs2"] +[ext_resource type="Script" path="res://content/ui/components/tabs/tabs.gd" id="3_cwu20"] +[ext_resource type="Shader" path="res://content/ui/components/panel/glass.gdshader" id="4_v4u0l"] +[ext_resource type="FontVariation" uid="uid://sshfnckriqxn" path="res://assets/icons/icons.tres" id="5_3vfb4"] +[ext_resource type="Texture2D" uid="uid://bl33klueufwja" path="res://assets/cursors/pointer.png" id="6_ypel5"] +[ext_resource type="Texture2D" uid="uid://churthrr24yhw" path="res://assets/cursors/old.png" id="7_un12x"] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_0hxn1"] +resource_local_to_scene = true +render_priority = 10 +shader = ExtResource("4_v4u0l") +shader_parameter/color = Color(1, 1, 1, 0.3) +shader_parameter/border_color = Color(1, 1, 1, 1) +shader_parameter/edge_color = Color(0, 0, 0, 1) +shader_parameter/size = Vector2(1, 1) +shader_parameter/border_size = 0.01 +shader_parameter/border_fade_in = 0.05 +shader_parameter/border_fade_out = 0.0 +shader_parameter/corner_radius = 0.2 +shader_parameter/roughness = 0.3 +shader_parameter/grain_amount = 0.02 + +[sub_resource type="QuadMesh" id="QuadMesh_1x032"] +size = Vector2(0.04, 0.04) + +[sub_resource type="BoxShape3D" id="BoxShape3D_01skh"] +resource_local_to_scene = true +size = Vector3(0.04, 0.04, 0.01) + +[sub_resource type="BoxShape3D" id="BoxShape3D_surd4"] +resource_local_to_scene = true +size = Vector3(0.04, 0.04, 0.03) + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_pnxr8"] +resource_local_to_scene = true +render_priority = 10 +shader = ExtResource("4_v4u0l") +shader_parameter/color = Color(1, 1, 1, 0.3) +shader_parameter/border_color = Color(1, 1, 1, 1) +shader_parameter/edge_color = Color(0, 0, 0, 1) +shader_parameter/size = Vector2(1, 1) +shader_parameter/border_size = 0.01 +shader_parameter/border_fade_in = 0.05 +shader_parameter/border_fade_out = 0.0 +shader_parameter/corner_radius = 0.2 +shader_parameter/roughness = 0.3 +shader_parameter/grain_amount = 0.02 + +[sub_resource type="QuadMesh" id="QuadMesh_6ehqp"] +size = Vector2(0.04, 0.04) [node name="FeaturesMenu" type="Node3D"] script = ExtResource("1_imqs2") @@ -21,3 +70,87 @@ text = "Voice Assistant: " font_size = 18 outline_size = 0 horizontal_alignment = 0 + +[node name="LabelCursor" type="Label3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.02, -0.13, 0) +pixel_size = 0.001 +render_priority = 15 +outline_render_priority = 14 +text = "Cursor Style: " +font_size = 18 +outline_size = 0 +horizontal_alignment = 0 + +[node name="CursorOptions" type="Node3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.17, -0.13, 0) +script = ExtResource("3_cwu20") +gap = 0.01 + +[node name="CircleCursor" parent="CursorOptions" instance=ExtResource("1_52ufi")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.02, 0, 0) +label = "" +icon = true +toggleable = true + +[node name="Panel3D" parent="CursorOptions/CircleCursor/Body" index="0"] +material_override = SubResource("ShaderMaterial_0hxn1") +mesh = SubResource("QuadMesh_1x032") + +[node name="CollisionShape3D" parent="CursorOptions/CircleCursor/Body" index="1"] +shape = SubResource("BoxShape3D_01skh") + +[node name="Label" parent="CursorOptions/CircleCursor/Body" index="2"] +text = "" +font = ExtResource("5_3vfb4") +font_size = 28 +autowrap_mode = 0 +width = 1000.0 + +[node name="Sprite3D" type="Sprite3D" parent="CursorOptions/CircleCursor/Body/Label" index="0"] +transform = Transform3D(0.05, 0, 0, 0, 0.05, 0, 0, 0, 0.05, 0, 0, 0) +pixel_size = 0.001 +double_sided = false +render_priority = 20 +texture = ExtResource("6_ypel5") + +[node name="CollisionShape3D" parent="CursorOptions/CircleCursor/FingerArea" index="0"] +shape = SubResource("BoxShape3D_surd4") + +[node name="CollisionShape3D" parent="CursorOptions/CircleCursor/TouchBody" index="0"] +shape = SubResource("BoxShape3D_01skh") + +[node name="RetroCursor" parent="CursorOptions" instance=ExtResource("1_52ufi")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.07, 0, 0) +label = "" +icon = true +toggleable = true + +[node name="Panel3D" parent="CursorOptions/RetroCursor/Body" index="0"] +material_override = SubResource("ShaderMaterial_pnxr8") +mesh = SubResource("QuadMesh_6ehqp") + +[node name="CollisionShape3D" parent="CursorOptions/RetroCursor/Body" index="1"] +shape = SubResource("BoxShape3D_01skh") + +[node name="Label" parent="CursorOptions/RetroCursor/Body" index="2"] +text = "" +font = ExtResource("5_3vfb4") +font_size = 28 +autowrap_mode = 0 +width = 1000.0 + +[node name="Sprite3D" type="Sprite3D" parent="CursorOptions/RetroCursor/Body/Label" index="0"] +pixel_size = 0.001 +double_sided = false +texture_filter = 0 +render_priority = 20 +texture = ExtResource("7_un12x") + +[node name="CollisionShape3D" parent="CursorOptions/RetroCursor/FingerArea" index="0"] +shape = SubResource("BoxShape3D_surd4") + +[node name="CollisionShape3D" parent="CursorOptions/RetroCursor/TouchBody" index="0"] +shape = SubResource("BoxShape3D_01skh") + +[editable path="CursorOptions/CircleCursor"] +[editable path="CursorOptions/RetroCursor"] diff --git a/app/lib/stores/settings.gd b/app/lib/stores/settings.gd index 4ec83c2..111c136 100644 --- a/app/lib/stores/settings.gd +++ b/app/lib/stores/settings.gd @@ -3,6 +3,11 @@ extends StoreClass const StoreClass = preload ("./store.gd") +enum CursorStyle { + DEFAULT, + RETRO +} + func _init(): _save_path = "user://settings.json" @@ -14,7 +19,8 @@ func _init(): ## If the voice assistant should be enabled "voice_assistant": false, ## If the onboarding process has been completed - "onboarding_complete": false + "onboarding_complete": false, + "cursor_style": CursorStyle.DEFAULT }) func clear(): @@ -23,3 +29,4 @@ func clear(): self.state.token = "" self.state.voice_assistant = false self.state.onboarding_complete = false + self.state.cursor_style = CursorStyle.DEFAULT