From f04ceaf23cad01a7dc3a66a78664823de104b251 Mon Sep 17 00:00:00 2001 From: m Date: Sat, 16 Nov 2024 13:46:25 -0600 Subject: [PATCH] add sens slider & vc settings --- data/cdata/ui_scripts/options/__init__.lua | 25 ++++ .../cdata/ui_scripts/options/lookcontrols.lua | 46 +++++++ data/cdata/ui_scripts/options/pcaudio.lua | 126 ++++++++++++++++++ data/zonetool/localizedstrings/english.json | 7 +- 4 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 data/cdata/ui_scripts/options/__init__.lua create mode 100644 data/cdata/ui_scripts/options/lookcontrols.lua create mode 100644 data/cdata/ui_scripts/options/pcaudio.lua diff --git a/data/cdata/ui_scripts/options/__init__.lua b/data/cdata/ui_scripts/options/__init__.lua new file mode 100644 index 00000000..33cc7130 --- /dev/null +++ b/data/cdata/ui_scripts/options/__init__.lua @@ -0,0 +1,25 @@ +function createdivider(menu, text) + local element = LUI.UIElement.new({ + leftAnchor = true, + rightAnchor = true, + left = 0, + right = 0, + topAnchor = true, + bottomAnchor = false, + top = 0, + bottom = 33.33 + }) + + element.scrollingToNext = true + element:addElement(LUI.MenuBuilder.BuildRegisteredType("h1_option_menu_titlebar", { + title_bar_text = text + })) + + menu.list:addElement(element) +end + +-- change PC sensitivity to slider instead +require("lookcontrols") + +-- add additional voice chat settings +require("pcaudio") diff --git a/data/cdata/ui_scripts/options/lookcontrols.lua b/data/cdata/ui_scripts/options/lookcontrols.lua new file mode 100644 index 00000000..7a0ea48c --- /dev/null +++ b/data/cdata/ui_scripts/options/lookcontrols.lua @@ -0,0 +1,46 @@ +local lookcontrols = luiglobals.require("LUI.LookControls") + +local function get_sensitivity() + return (Engine.GetDvarFloat("sensitivity") - SliderBounds.MouseSensitivity.Min) / + (SliderBounds.MouseSensitivity.Max - SliderBounds.MouseSensitivity.Min) +end + +local function change_sens(value) + Engine.SetDvarFloat("sensitivity", math.min(SliderBounds.MouseSensitivity.Max, math.max( + SliderBounds.MouseSensitivity.Min, Engine.GetDvarFloat("sensitivity") + value))) +end + +local create_options_og = lookcontrols.CreateOptions +lookcontrols.CreateOptions = function(menu) + LUI.Options.AddButtonOptionVariant(menu, GenericButtonSettings.Variants.Slider, "@MENU_MOUSE_SENSITIVITY", + "@MENU_MOUSE_SENSITIVITY_DESC", get_sensitivity, function() -- less + change_sens(-SliderBounds.MouseSensitivity.Step) + end, function() -- more + change_sens(SliderBounds.MouseSensitivity.Step) + end) + + -- not much code to even reimplement, so just paste it all + LUI.Options.CreateOptionButton(menu, "ui_mousePitch", "@MENU_INVERT_MOUSE", "@MENU_INVERT_MOUSE_DESC", + lookcontrols.GetPitchValues(), lookcontrols.UpdateMousePitch) + LUI.Options.CreateOptionButton(menu, "m_filter", "@MENU_SMOOTH_MOUSE", "@MENU_SMOOTH_MOUSE_DESC", {{ + text = "@LUA_MENU_YES", + value = true + }, { + text = "@LUA_MENU_NO", + value = false + }}) + LUI.Options.CreateOptionButton(menu, "cl_freelook", "@MENU_FREE_LOOK", "@MENU_FREE_LOOK_DESC", {{ + text = "@LUA_MENU_YES", + value = true + }, { + text = "@LUA_MENU_NO", + value = false + }}) + LUI.Options.CreateControlBindButton(menu, "@MENU_LEAN_LEFT", "@MENU_LEAN_LEFT_DESC", "+leanleft") + LUI.Options.CreateControlBindButton(menu, "@MENU_LEAN_RIGHT", "@MENU_LEAN_RIGHT_DESC", "+leanright") + LUI.Options.CreateControlBindButton(menu, "@MENU_LOOK_UP", "@MENU_LOOK_UP_DESC", "+lookup") + LUI.Options.CreateControlBindButton(menu, "@MENU_LOOK_DOWN", "@MENU_LOOK_DOWN_DESC", "+lookdown") + LUI.Options.CreateControlBindButton(menu, "@MENU_HOLD_MOUSE_LOOK", "@MENU_HOLD_MOUSE_LOOK_DESC", "+mlook") + LUI.Options.CreateControlBindButton(menu, "@MENU_CENTER_VIEW", "@MENU_CENTER_VIEW_DESC", "centerview") + LUI.Options.InitScrollingList(menu.list, nil) +end diff --git a/data/cdata/ui_scripts/options/pcaudio.lua b/data/cdata/ui_scripts/options/pcaudio.lua new file mode 100644 index 00000000..38025f3d --- /dev/null +++ b/data/cdata/ui_scripts/options/pcaudio.lua @@ -0,0 +1,126 @@ +local function GetVolume() + return (Engine.GetProfileData("snd_volume") - SliderBounds.Volume.Min) / + (SliderBounds.Volume.Max - SliderBounds.Volume.Min) +end + +local function VolumeLess(f2_arg0) + LUI.Options.ProfileDataMenuOption(f2_arg0, SliderBounds.Volume.Min, SliderBounds.Volume.Max, + -SliderBounds.Volume.Step, "snd_volume") +end + +local function VolumeMore(f3_arg0) + LUI.Options.ProfileDataMenuOption(f3_arg0, SliderBounds.Volume.Min, SliderBounds.Volume.Max, + SliderBounds.Volume.Step, "snd_volume") +end + +local function get_mic_volume() + return (Engine.GetDvarFloat("winvoice_mic_reclevel") - SliderBounds.VoiceRecord.Min) / + (SliderBounds.VoiceRecord.Max - SliderBounds.VoiceRecord.Min) +end + +local function mic_levels_more(index) + local current = get_mic_volume() * SliderBounds.VoiceRecord.Max + Engine.SetDvarFloat("winvoice_mic_reclevel", current + SliderBounds.VoiceRecord.Step) +end + +local function mic_levels_less(index) + local current = get_mic_volume() * SliderBounds.VoiceRecord.Max + Engine.SetDvarFloat("winvoice_mic_reclevel", current - SliderBounds.VoiceRecord.Step) +end + +local function pc_audio(f4_arg0, f4_arg1) + local menu = LUI.MenuTemplate.new(f4_arg0, { + menu_title = Engine.ToUpperCase(Engine.Localize("@LUA_MENU_AUDIO_OPTIONS")), + menu_top_indent = Engine.IsMultiplayer() and 0 or LUI.MenuTemplate.spMenuOffset, + menu_width = GenericMenuDims.OptionMenuWidth + }) + + LUI.Options.AddButtonOptionVariant(menu, GenericButtonSettings.Variants.Slider, "@MENU_MASTER_VOLUME", + "@MENU_MASTER_VOLUME_DESC", GetVolume, VolumeLess, VolumeMore) + + local f4_local1 = {{ + text = "@LUA_MENU_AUTODETECT_SPEAKERS", + value = 0 + }} + local f4_local2 = Engine.GetDvarInt("snd_detectedSpeakerConfig") + if f4_local2 > 1 then + f4_local1[#f4_local1 + 1] = { + text = "@LUA_MENU_STEREO", + value = 2 + } + f4_local1[#f4_local1 + 1] = { + text = "@LUA_MENU_HEADPHONE", + value = 50 + } + end + if f4_local2 > 2 then + f4_local1[#f4_local1 + 1] = { + text = "@LUA_MENU_FOUR_SPEAKERS", + value = 4 + } + end + if f4_local2 > 4 then + f4_local1[#f4_local1 + 1] = { + text = "@LUA_MENU_FIVE_ONE_SPEAKERS", + value = 6 + } + end + if f4_local2 > 6 then + f4_local1[#f4_local1 + 1] = { + text = "@LUA_MENU_SEVEN_ONE_SPEAKERS", + value = 8 + } + end + + LUI.Options.CreateOptionButton(menu, "snd_speakerConfig", "@LUA_MENU_SPEAKER_CONFIG", + "@LUA_MENU_SPEAKER_CONFIG_DESC", f4_local1) + + if Engine.IsMultiplayer() then + LUI.Options.AddButtonOptionVariant(menu, GenericButtonSettings.Variants.Select, "@LUA_MENU_MUSIC", + "@LUA_MENU_MUSIC_DESC", LUI.Options.GetDvarEnableTextFunc("snd_musicDisabled", true), + LUI.Options.ToggleDvarFunc("snd_musicDisabled"), LUI.Options.ToggleDvarFunc("snd_musicDisabled")) + LUI.Options.AddButtonOptionVariant(menu, GenericButtonSettings.Variants.Select, "@LUA_MENU_ANNOUNCER", + "@LUA_MENU_ANNOUNCER_DESC", LUI.Options.GetDvarEnableTextFunc("snd_announcerDisabled", true), + LUI.Options.ToggleDvarFunc("snd_announcerDisabled"), LUI.Options.ToggleDvarFunc("snd_announcerDisabled")) + LUI.Options.AddButtonOptionVariant(menu, GenericButtonSettings.Variants.Select, "@LUA_MENU_BATTLECHATTER", + "@LUA_MENU_BATTLECHATTER_DESC", LUI.Options.GetDvarEnableTextFunc("snd_battleChatterDisabled", true), + LUI.Options.ToggleDvarFunc("snd_battleChatterDisabled"), + LUI.Options.ToggleDvarFunc("snd_battleChatterDisabled")) + end + + LUI.Options.AddButtonOptionVariant(menu, GenericButtonSettings.Variants.Select, "@LUA_MENU_HITSOUND", + "@LUA_MENU_HITSOUND_DESC", LUI.Options.GetDvarEnableTextFunc("snd_hitsoundDisabled", true), + LUI.Options.ToggleDvarFunc("snd_hitsoundDisabled"), LUI.Options.ToggleDvarFunc("snd_hitsoundDisabled")) + + if Engine.IsPC() and Engine.GetDvarBool("snd_wasapiSampleRateConverterNeeded") then + LUI.Options.AddButtonOptionVariant(menu, GenericButtonSettings.Variants.Select, "@LUA_MENU_LOWQUALITYAUDIO", + "@LUA_MENU_LOWQUALITYAUDIO_DESC", LUI.Options.GetDvarEnableTextFunc("snd_lowQualityAudio", false), + LUI.Options.ToggleDvarFunc("snd_lowQualityAudio"), LUI.Options.ToggleDvarFunc("snd_lowQualityAudio")) + end + + -- voice chat options + createdivider(menu, Engine.Localize("@LUA_MENU_VOICE_CHAT")) + + LUI.Options.AddButtonOptionVariant(menu, GenericButtonSettings.Variants.Select, "@LUA_MENU_VOICE_CHAT", + "@LUA_MENU_VOICE_CHAT_DESC", LUI.Options.GetDvarEnableTextFunc("cl_voice", false), + LUI.Options.ToggleDvarFunc("cl_voice"), LUI.Options.ToggleDvarFunc("cl_voice")) + LUI.Options.AddButtonOptionVariant(menu, GenericButtonSettings.Variants.Select, "@LUA_MENU_PUSH_TO_TALK", + "@LUA_MENU_PUSH_TO_TALK_DESC", LUI.Options.GetDvarEnableTextFunc("cl_pushToTalk", false), + LUI.Options.ToggleDvarFunc("cl_pushToTalk"), LUI.Options.ToggleDvarFunc("cl_pushToTalk")) + + LUI.Options.AddButtonOptionVariant(menu, GenericButtonSettings.Variants.Slider, "@LUA_MENU_MIC_REC_VOLUME", + "@LUA_MENU_MIC_REC_VOLUME_DESC", get_mic_volume, mic_levels_less, mic_levels_more) + + LUI.Options.InitScrollingList(menu.list, nil) + LUI.Options.AddOptionTextInfo(menu) + + menu:AddBackButton(function(f5_arg0, f5_arg1) + Engine.ExecNow("profile_menuDvarsFinish", f5_arg1.controller) + Engine.Exec("updategamerprofile") + LUI.FlowManager.RequestLeaveMenu(f5_arg0) + end) + + return menu +end + +LUI.MenuBuilder.m_types_build["pc_audio"] = pc_audio diff --git a/data/zonetool/localizedstrings/english.json b/data/zonetool/localizedstrings/english.json index 726e5cf0..f1d9703c 100644 --- a/data/zonetool/localizedstrings/english.json +++ b/data/zonetool/localizedstrings/english.json @@ -7,5 +7,10 @@ "LUA_MENU_DISCORD_REQUEST": "&&1^7 requested to join your game!", "LUA_MENU_DISCORD_REQUEST_DISCRIMINATOR": "&&1^7#&&2 requested to join your game!", "LUA_MENU_DISCORD_ACCEPT": "[&&1] Accept", - "LUA_MENU_DISCORD_DENY": "[&&1] Deny" + "LUA_MENU_DISCORD_DENY": "[&&1] Deny", + + "LUA_MENU_VOICE_CHAT": "Voice Chat", + "LUA_MENU_VOICE_CHAT_DESC": "Enable or disable voice chat.", + "LUA_MENU_MIC_REC_VOLUME": "Voice Volume", + "LUA_MENU_MIC_REC_VOLUME_DESC": "Move the slider to adjust voice volume." } \ No newline at end of file