Added ability to adjust mouse settings in game

This commit is contained in:
2024-08-09 01:23:47 -05:00
parent 028a04bff7
commit ef1af747ba
6 changed files with 94 additions and 31 deletions

View File

@ -63,6 +63,7 @@ text = "Quit
" "
[node name="Settings" type="Control" parent="."] [node name="Settings" type="Control" parent="."]
visible = false
layout_mode = 1 layout_mode = 1
anchors_preset = 15 anchors_preset = 15
anchor_right = 1.0 anchor_right = 1.0
@ -112,39 +113,29 @@ offset_bottom = -16.0
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
[node name="HBoxContainer" parent="Settings/ColorRect/VBoxContainer" instance=ExtResource("4_6nahw")] [node name="Setting Option" parent="Settings/ColorRect/VBoxContainer" instance=ExtResource("4_6nahw")]
layout_mode = 2 layout_mode = 2
Setting = 0
[node name="HBoxContainer4" parent="Settings/ColorRect/VBoxContainer" instance=ExtResource("4_6nahw")] [node name="Setting Option2" parent="Settings/ColorRect/VBoxContainer" instance=ExtResource("4_6nahw")]
layout_mode = 2 layout_mode = 2
SettingName = "Joystick Settings" Setting = 1
SettingLabel = "Joystick_Settings"
[node name="HBoxContainer2" type="HBoxContainer" parent="Settings/ColorRect/VBoxContainer"] [node name="Setting Option3" parent="Settings/ColorRect/VBoxContainer" instance=ExtResource("4_6nahw")]
layout_mode = 2 layout_mode = 2
alignment = 1 Setting = 2
[node name="Label" type="Label" parent="Settings/ColorRect/VBoxContainer/HBoxContainer2"] [node name="Setting Option4" parent="Settings/ColorRect/VBoxContainer" instance=ExtResource("4_6nahw")]
custom_minimum_size = Vector2(400, 0)
layout_mode = 2 layout_mode = 2
text = "Joystick Sensativity" Setting = 3
horizontal_alignment = 1
vertical_alignment = 1
[node name="HSlider" type="HSlider" parent="Settings/ColorRect/VBoxContainer/HBoxContainer2"] [node name="Setting Option5" parent="Settings/ColorRect/VBoxContainer" instance=ExtResource("4_6nahw")]
custom_minimum_size = Vector2(200, 0)
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 Setting = 4
size_flags_vertical = 4
[node name="HBoxContainer3" type="HBoxContainer" parent="Settings/ColorRect/VBoxContainer"] [node name="Setting Option6" parent="Settings/ColorRect/VBoxContainer" instance=ExtResource("4_6nahw")]
layout_mode = 2
[node name="Label" type="Label" parent="Settings/ColorRect/VBoxContainer/HBoxContainer3"]
layout_mode = 2
[node name="HSlider" type="HSlider" parent="Settings/ColorRect/VBoxContainer/HBoxContainer3"]
layout_mode = 2 layout_mode = 2
Setting = 5
[connection signal="pressed" from="Pause Menu/Menu/Resume" to="." method="_on_resume_pressed"] [connection signal="pressed" from="Pause Menu/Menu/Resume" to="." method="_on_resume_pressed"]
[connection signal="pressed" from="Pause Menu/Menu/Settings" to="." method="_on_settings_pressed"] [connection signal="pressed" from="Pause Menu/Menu/Settings" to="." method="_on_settings_pressed"]

View File

@ -2,7 +2,7 @@
[ext_resource type="Script" path="res://Assets/scripts/Component Scripts/Settings_Option.gd" id="1_aieqa"] [ext_resource type="Script" path="res://Assets/scripts/Component Scripts/Settings_Option.gd" id="1_aieqa"]
[node name="HBoxContainer" type="HBoxContainer"] [node name="Setting Option" type="HBoxContainer"]
custom_minimum_size = Vector2(0, 40) custom_minimum_size = Vector2(0, 40)
alignment = 1 alignment = 1
script = ExtResource("1_aieqa") script = ExtResource("1_aieqa")
@ -10,7 +10,7 @@ script = ExtResource("1_aieqa")
[node name="Label" type="Label" parent="."] [node name="Label" type="Label" parent="."]
custom_minimum_size = Vector2(400, 0) custom_minimum_size = Vector2(400, 0)
layout_mode = 2 layout_mode = 2
text = "Mouse Sensitity" text = "Temp String"
horizontal_alignment = 1 horizontal_alignment = 1
vertical_alignment = 1 vertical_alignment = 1

View File

@ -0,0 +1,11 @@
extends HBoxContainer
@export var Setting:GlobalSettings.Setting = GlobalSettings.Setting.Test_Value
# Called when the node enters the scene tree for the first time.
func _ready():
$Label.text = GlobalSettings.GetSettingName(Setting)
$HSlider.value = GlobalSettings.GetSetting(Setting)
func _on_setting_slider_value_changed(value:float):
GlobalSettings.SetSetting(Setting, value)

View File

@ -7,14 +7,14 @@ var max_angle_radians = 1.5
func _process(delta): func _process(delta):
var look_velocity = Input.get_vector("look_left", "look_right", "look_up", "look_down") var look_velocity = Input.get_vector("look_left", "look_right", "look_up", "look_down")
var rotate_degree = -look_velocity.y * GlobalSettings.Joystick_Sensitivity var rotate_degree = -look_velocity.y * GlobalSettings.GetSetting(GlobalSettings.Setting.Joystick_Speed)
rotate_x(rotate_degree) rotate_x(rotate_degree)
func _unhandled_input(event): func _unhandled_input(event):
if event is InputEventMouseMotion: if event is InputEventMouseMotion:
var mouse_movement = -event.relative.y var mouse_movement = -event.relative.y
var rotate_amount = mouse_movement * GlobalSettings.Mouse_Sensitivity var rotate_amount = mouse_movement * GlobalSettings.GetSetting(GlobalSettings.Setting.Mouse_Speed)
var rotation_after = rotate_amount + rotation.x var rotation_after = rotate_amount + rotation.x
if rotation_after <= max_angle_radians and rotate_amount > 0: if rotation_after <= max_angle_radians and rotate_amount > 0:
rotate_x(rotate_amount) rotate_x(rotate_amount)

View File

@ -1,17 +1,78 @@
extends Node extends Node
enum Setting{Mouse_Speed, Joystick_Speed, SFX_Volume, Music_Volume, Voice_Volume, FOV, Test_Value}
var DEVMODE = true var DEVMODE = true
var is_paused = false var is_paused = false
var Joystick_Sensitivity = 2
var Mouse_Sensitivity = 0.02
var current_map = "" var current_map = ""
var SpawnPoint:Vector3 var SpawnPoint:Vector3
var Player_Last_Location = Vector3(0,0,0) var Player_Last_Location = Vector3(0,0,0)
var HasGeneratorKey = false var HasGeneratorKey = false
var Settings:Dictionary = {
Setting.Mouse_Speed: {
"value": 0.02,
"text": "Mouse Speed",
"range": Vector2(0.0001, 0.09)
},
Setting.Joystick_Speed: {
"value": 2,
"text": "Mouse Speed",
"range": Vector2(0.5, 4)
},
Setting.SFX_Volume: {
"value": 100,
"text": "SFX Volume",
"range": Vector2(0,100)
},
Setting.Music_Volume: {
"value": 100,
"text": "Music Volume",
"range": Vector2(0,100)
},
Setting.Voice_Volume: {
"value": 100,
"text": "Voice Volume",
"range": Vector2(0,100)
},
Setting.FOV: {
"value": 95,
"text": "FOV",
"range": Vector2(75,115)
},
Setting.Test_Value: {
"value": 69,
"text": "Test Value",
"range": Vector2(0,100)
}
}
var GlobalData:Dictionary = {
"SpawnPoint": Vector3(),
"Player_Last_Location": Vector3()
}
func GetSetting(SettingName):
return Settings.get(SettingName).get("value")
func GetSettingName(SettingName):
return Settings.get(SettingName).get("text")
func GetSettingRange(SettingName):
return Settings.get(SettingName).get("range")
func SetSetting(SettingName, value):
Settings[SettingName]["value"] = value
func PrintSettings():
for setting in Settings.keys():
print(setting, ":", Settings.get(setting))
func SetCurrentMap(selected_map): func SetCurrentMap(selected_map):
current_map = selected_map current_map = selected_map

View File

@ -50,7 +50,7 @@ func _physics_process(delta):
move_and_slide() move_and_slide()
var look_velocity = Input.get_vector("look_left", "look_right", "look_up", "look_down") var look_velocity = Input.get_vector("look_left", "look_right", "look_up", "look_down")
rotate_y(-look_velocity.x * GlobalSettings.Joystick_Sensitivity * delta) rotate_y(-look_velocity.x * GlobalSettings.GetSetting(GlobalSettings.Setting.Joystick_Speed) * delta)
func _process(delta): func _process(delta):
#Calculations for seeing if you vaped too many times within a short span #Calculations for seeing if you vaped too many times within a short span
@ -72,7 +72,7 @@ func _input(event):
respawn() respawn()
if not is_paused: if not is_paused:
if event is InputEventMouseMotion: if event is InputEventMouseMotion:
rotate_y(-event.relative.x * GlobalSettings.Mouse_Sensitivity) rotate_y(-event.relative.x * GlobalSettings.GetSetting(GlobalSettings.Setting.Mouse_Speed))
if event.is_action_pressed("vape"): if event.is_action_pressed("vape"):
if current_condition == CONDITION.NORMAL: if current_condition == CONDITION.NORMAL: