2023-12-22 22:51:17 +00:00
|
|
|
using System;
|
|
|
|
using Dissonance;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.InputSystem;
|
|
|
|
using UnityEngine.Rendering;
|
|
|
|
using UnityEngine.Rendering.HighDefinition;
|
|
|
|
using UnityEngine.SceneManagement;
|
|
|
|
|
|
|
|
public class IngamePlayerSettings : MonoBehaviour
|
|
|
|
{
|
|
|
|
[Serializable]
|
|
|
|
public class Settings
|
|
|
|
{
|
|
|
|
public bool playerHasFinishedSetup;
|
|
|
|
|
|
|
|
public bool startInOnlineMode = true;
|
|
|
|
|
|
|
|
public float gammaSetting;
|
|
|
|
|
|
|
|
public int lookSensitivity = 10;
|
|
|
|
|
2023-12-23 00:30:32 +00:00
|
|
|
public bool invertYAxis;
|
|
|
|
|
2023-12-22 22:51:17 +00:00
|
|
|
public float masterVolume = 1f;
|
|
|
|
|
|
|
|
public int framerateCapIndex;
|
|
|
|
|
|
|
|
public FullScreenMode fullScreenType;
|
|
|
|
|
|
|
|
[Header("MIC SETTINGS")]
|
|
|
|
public bool micEnabled = true;
|
|
|
|
|
|
|
|
public bool pushToTalk;
|
|
|
|
|
|
|
|
public int micDeviceIndex;
|
|
|
|
|
|
|
|
public string micDevice = string.Empty;
|
|
|
|
|
|
|
|
[Header("BINDINGS")]
|
|
|
|
public string keyBindings = string.Empty;
|
|
|
|
|
2023-12-23 00:55:14 +00:00
|
|
|
[Header("ACCESSIBILITY")]
|
|
|
|
public bool spiderSafeMode;
|
|
|
|
|
2023-12-22 22:51:17 +00:00
|
|
|
public Settings(bool finishedSetup = true, bool onlineMode = true)
|
|
|
|
{
|
|
|
|
playerHasFinishedSetup = finishedSetup;
|
|
|
|
startInOnlineMode = onlineMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void CopySettings(Settings copyFrom)
|
|
|
|
{
|
|
|
|
playerHasFinishedSetup = copyFrom.playerHasFinishedSetup;
|
|
|
|
startInOnlineMode = copyFrom.startInOnlineMode;
|
|
|
|
gammaSetting = copyFrom.gammaSetting;
|
|
|
|
lookSensitivity = copyFrom.lookSensitivity;
|
|
|
|
micEnabled = copyFrom.micEnabled;
|
|
|
|
pushToTalk = copyFrom.pushToTalk;
|
|
|
|
micDeviceIndex = copyFrom.micDeviceIndex;
|
|
|
|
micDevice = copyFrom.micDevice;
|
|
|
|
keyBindings = copyFrom.keyBindings;
|
|
|
|
masterVolume = copyFrom.masterVolume;
|
|
|
|
framerateCapIndex = copyFrom.framerateCapIndex;
|
|
|
|
fullScreenType = copyFrom.fullScreenType;
|
2023-12-23 00:30:32 +00:00
|
|
|
invertYAxis = copyFrom.invertYAxis;
|
2023-12-23 00:55:14 +00:00
|
|
|
spiderSafeMode = copyFrom.spiderSafeMode;
|
2023-12-22 22:51:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Settings settings;
|
|
|
|
|
|
|
|
public Settings unsavedSettings;
|
|
|
|
|
|
|
|
public AudioSource SettingsAudio;
|
|
|
|
|
|
|
|
public Volume universalVolume;
|
|
|
|
|
|
|
|
private DissonanceComms comms;
|
|
|
|
|
|
|
|
public bool redoLaunchSettings;
|
|
|
|
|
|
|
|
public bool changesNotApplied;
|
|
|
|
|
|
|
|
public InputActionRebindingExtensions.RebindingOperation rebindingOperation;
|
|
|
|
|
|
|
|
private SettingsOption currentRebindingKeyUI;
|
|
|
|
|
|
|
|
public PlayerInput playerInput;
|
|
|
|
|
2023-12-23 00:30:32 +00:00
|
|
|
public bool encounteredErrorDuringSave;
|
|
|
|
|
2023-12-22 22:51:17 +00:00
|
|
|
public static IngamePlayerSettings Instance { get; private set; }
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
if (Instance == null)
|
|
|
|
{
|
|
|
|
Instance = this;
|
|
|
|
UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
|
2023-12-23 00:05:55 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
LoadSettingsFromPrefs();
|
|
|
|
UpdateGameToMatchSettings();
|
|
|
|
}
|
2023-12-23 00:30:32 +00:00
|
|
|
catch (Exception e)
|
2023-12-22 22:51:17 +00:00
|
|
|
{
|
2023-12-23 00:30:32 +00:00
|
|
|
DisplaySaveFileError(e);
|
2023-12-23 00:05:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (settings.playerHasFinishedSetup)
|
|
|
|
{
|
2023-12-23 00:30:32 +00:00
|
|
|
PreInitSceneScript preInitSceneScript = UnityEngine.Object.FindObjectOfType<PreInitSceneScript>();
|
|
|
|
if (preInitSceneScript != null)
|
2023-12-23 00:05:55 +00:00
|
|
|
{
|
2023-12-23 00:30:32 +00:00
|
|
|
preInitSceneScript.SkipToFinalSetting();
|
2023-12-22 22:51:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
UnityEngine.Object.Destroy(base.gameObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-23 00:30:32 +00:00
|
|
|
private void DisplaySaveFileError(Exception e)
|
|
|
|
{
|
|
|
|
Debug.LogError($"Error while loading general save data file!: {e}, enabling error panel for player");
|
|
|
|
encounteredErrorDuringSave = true;
|
|
|
|
PreInitSceneScript preInitSceneScript = UnityEngine.Object.FindObjectOfType<PreInitSceneScript>();
|
|
|
|
if (preInitSceneScript != null)
|
|
|
|
{
|
|
|
|
preInitSceneScript.EnableFileCorruptedScreen();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-22 22:51:17 +00:00
|
|
|
public void LoadSettingsFromPrefs()
|
|
|
|
{
|
|
|
|
string filePath = "LCGeneralSaveData";
|
|
|
|
settings.playerHasFinishedSetup = ES3.Load("PlayerFinishedSetup", filePath, defaultValue: false);
|
|
|
|
settings.startInOnlineMode = ES3.Load("StartInOnlineMode", filePath, defaultValue: false);
|
|
|
|
settings.gammaSetting = ES3.Load("Gamma", filePath, 0f);
|
|
|
|
settings.masterVolume = ES3.Load("MasterVolume", filePath, 1f);
|
|
|
|
settings.lookSensitivity = ES3.Load("LookSens", filePath, 10);
|
|
|
|
settings.micEnabled = ES3.Load("MicEnabled", filePath, defaultValue: true);
|
|
|
|
settings.pushToTalk = ES3.Load("PushToTalk", filePath, defaultValue: false);
|
|
|
|
settings.micDevice = ES3.Load("CurrentMic", filePath, "LCNoMic");
|
|
|
|
settings.keyBindings = ES3.Load("Bindings", filePath, string.Empty);
|
|
|
|
settings.framerateCapIndex = ES3.Load("FPSCap", filePath, 0);
|
|
|
|
settings.fullScreenType = (FullScreenMode)ES3.Load("ScreenMode", filePath, 1);
|
2023-12-23 00:30:32 +00:00
|
|
|
settings.invertYAxis = ES3.Load("InvertYAxis", filePath, defaultValue: false);
|
2023-12-23 00:55:14 +00:00
|
|
|
settings.spiderSafeMode = ES3.Load("SpiderSafeMode", filePath, defaultValue: false);
|
2023-12-22 22:51:17 +00:00
|
|
|
if (!string.IsNullOrEmpty(settings.keyBindings))
|
|
|
|
{
|
|
|
|
playerInput.actions.LoadBindingOverridesFromJson(settings.keyBindings);
|
|
|
|
}
|
|
|
|
unsavedSettings.CopySettings(settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SaveSettingsToPrefs()
|
|
|
|
{
|
|
|
|
string filePath = "LCGeneralSaveData";
|
2023-12-23 00:30:32 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
ES3.Save("PlayerFinishedSetup", settings.playerHasFinishedSetup, filePath);
|
|
|
|
ES3.Save("StartInOnlineMode", settings.startInOnlineMode, filePath);
|
|
|
|
ES3.Save("Gamma", settings.gammaSetting, filePath);
|
|
|
|
ES3.Save("MasterVolume", settings.masterVolume, filePath);
|
|
|
|
ES3.Save("LookSens", settings.lookSensitivity, filePath);
|
|
|
|
ES3.Save("MicEnabled", settings.micEnabled, filePath);
|
|
|
|
ES3.Save("PushToTalk", settings.pushToTalk, filePath);
|
|
|
|
ES3.Save("CurrentMic", settings.micDevice, filePath);
|
|
|
|
ES3.Save("Bindings", settings.keyBindings, filePath);
|
|
|
|
ES3.Save("FPSCap", settings.framerateCapIndex, filePath);
|
|
|
|
ES3.Save("ScreenMode", (int)settings.fullScreenType, filePath);
|
|
|
|
ES3.Save("InvertYAxis", settings.invertYAxis, filePath);
|
2023-12-23 00:55:14 +00:00
|
|
|
ES3.Save("SpiderSafeMode", settings.spiderSafeMode, filePath);
|
2023-12-23 00:30:32 +00:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
DisplaySaveFileError(e);
|
|
|
|
}
|
2023-12-22 22:51:17 +00:00
|
|
|
}
|
|
|
|
|
2023-12-23 02:05:52 +00:00
|
|
|
public void UpdateAllKeybindOptions()
|
|
|
|
{
|
|
|
|
SettingsOption[] array = UnityEngine.Object.FindObjectsOfType<SettingsOption>(includeInactive: true);
|
|
|
|
for (int i = 0; i < array.Length; i++)
|
|
|
|
{
|
|
|
|
array[i].SetBindingToCurrentSetting();
|
|
|
|
}
|
|
|
|
KepRemapPanel kepRemapPanel = UnityEngine.Object.FindObjectOfType<KepRemapPanel>();
|
|
|
|
if (kepRemapPanel != null)
|
|
|
|
{
|
|
|
|
Debug.Log("Reseting keybind UI");
|
|
|
|
kepRemapPanel.ResetKeybindsUI();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-22 22:51:17 +00:00
|
|
|
public void UpdateGameToMatchSettings()
|
|
|
|
{
|
|
|
|
ChangeGamma(0, settings.gammaSetting);
|
|
|
|
SetFramerateCap(settings.framerateCapIndex);
|
|
|
|
SetFullscreenMode((int)settings.fullScreenType);
|
|
|
|
AudioListener.volume = settings.masterVolume;
|
|
|
|
UpdateMicPushToTalkButton();
|
|
|
|
RefreshAndDisplayCurrentMicrophone();
|
|
|
|
SettingsOption[] array = UnityEngine.Object.FindObjectsOfType<SettingsOption>(includeInactive: true);
|
|
|
|
for (int i = 0; i < array.Length; i++)
|
|
|
|
{
|
|
|
|
array[i].SetValueToMatchSettings();
|
|
|
|
}
|
|
|
|
if (comms != null && StartOfRound.Instance != null)
|
|
|
|
{
|
|
|
|
comms.IsMuted = !settings.micEnabled;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetOption(SettingsOptionType optionType, int value)
|
|
|
|
{
|
|
|
|
if (GameNetworkManager.Instance != null)
|
|
|
|
{
|
|
|
|
SettingsAudio.PlayOneShot(GameNetworkManager.Instance.buttonTuneSFX);
|
|
|
|
}
|
2023-12-23 00:30:32 +00:00
|
|
|
Debug.Log($"Set settings not applied!; {optionType}");
|
2023-12-22 22:51:17 +00:00
|
|
|
SetChangesNotAppliedTextVisible();
|
|
|
|
switch (optionType)
|
|
|
|
{
|
|
|
|
case SettingsOptionType.Gamma:
|
|
|
|
ChangeGamma(value);
|
|
|
|
break;
|
|
|
|
case SettingsOptionType.MasterVolume:
|
|
|
|
ChangeMasterVolume(value);
|
|
|
|
break;
|
|
|
|
case SettingsOptionType.LookSens:
|
|
|
|
ChangeLookSens(value);
|
|
|
|
break;
|
|
|
|
case SettingsOptionType.MicDevice:
|
|
|
|
SwitchMicrophoneSetting();
|
|
|
|
break;
|
|
|
|
case SettingsOptionType.MicEnabled:
|
|
|
|
SetMicrophoneEnabled();
|
|
|
|
break;
|
|
|
|
case SettingsOptionType.MicPushToTalk:
|
|
|
|
SetMicPushToTalk();
|
|
|
|
break;
|
|
|
|
case SettingsOptionType.FramerateCap:
|
|
|
|
SetFramerateCap(value);
|
|
|
|
break;
|
|
|
|
case SettingsOptionType.FullscreenType:
|
|
|
|
SetFullscreenMode(value);
|
|
|
|
break;
|
2023-12-23 00:30:32 +00:00
|
|
|
case SettingsOptionType.InvertYAxis:
|
|
|
|
SetInvertYAxis();
|
|
|
|
break;
|
2023-12-23 00:55:14 +00:00
|
|
|
case SettingsOptionType.SpiderSafeMode:
|
|
|
|
SetSpiderSafeMode();
|
|
|
|
break;
|
2023-12-22 22:51:17 +00:00
|
|
|
case SettingsOptionType.OnlineMode:
|
|
|
|
case SettingsOptionType.ChangeBinding:
|
|
|
|
case SettingsOptionType.CancelOrConfirm:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-23 00:55:14 +00:00
|
|
|
private void SetSpiderSafeMode()
|
|
|
|
{
|
|
|
|
unsavedSettings.spiderSafeMode = !unsavedSettings.spiderSafeMode;
|
|
|
|
}
|
|
|
|
|
2023-12-23 00:30:32 +00:00
|
|
|
private void SetInvertYAxis()
|
|
|
|
{
|
|
|
|
unsavedSettings.invertYAxis = !unsavedSettings.invertYAxis;
|
|
|
|
}
|
|
|
|
|
2023-12-22 22:51:17 +00:00
|
|
|
private void SetFullscreenMode(int value)
|
|
|
|
{
|
|
|
|
Screen.fullScreenMode = (FullScreenMode)value;
|
|
|
|
unsavedSettings.fullScreenType = (FullScreenMode)value;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SetFramerateCap(int value)
|
|
|
|
{
|
|
|
|
switch (value)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
QualitySettings.vSyncCount = 1;
|
|
|
|
Application.targetFrameRate = -1;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
QualitySettings.vSyncCount = 0;
|
|
|
|
Application.targetFrameRate = 250;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
QualitySettings.vSyncCount = 0;
|
|
|
|
switch (value)
|
|
|
|
{
|
|
|
|
case 2:
|
|
|
|
Application.targetFrameRate = 144;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
Application.targetFrameRate = 120;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
Application.targetFrameRate = 60;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
Application.targetFrameRate = 30;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
unsavedSettings.framerateCapIndex = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ChangeGamma(int setTo, float overrideWithFloat = -500f)
|
|
|
|
{
|
|
|
|
Debug.Log("Changing gamma");
|
|
|
|
float num = Mathf.Clamp((float)setTo * 0.05f, -0.85f, 2f);
|
|
|
|
Debug.Log($"override float value: {overrideWithFloat}");
|
|
|
|
if (overrideWithFloat != -500f)
|
|
|
|
{
|
|
|
|
Debug.Log("Overriding float");
|
|
|
|
num = overrideWithFloat;
|
|
|
|
}
|
|
|
|
if (universalVolume.sharedProfile.TryGet<LiftGammaGain>(out var component))
|
|
|
|
{
|
|
|
|
component.gamma.SetValue(new Vector4Parameter(new Vector4(0f, 0f, 0f, num), overrideState: true));
|
|
|
|
}
|
|
|
|
Debug.Log("Gamma changed");
|
|
|
|
unsavedSettings.gammaSetting = num;
|
|
|
|
Debug.Log($"Set gamma to new value: {num}; {component.gamma}");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ChangeMasterVolume(int setTo)
|
|
|
|
{
|
|
|
|
unsavedSettings.masterVolume = (float)setTo / 100f;
|
|
|
|
AudioListener.volume = (float)setTo / 100f;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ChangeLookSens(int setTo)
|
|
|
|
{
|
|
|
|
unsavedSettings.lookSensitivity = setTo;
|
|
|
|
Debug.Log($"Set mouse sensitivity to new value: {setTo}");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void RefreshAndDisplayCurrentMicrophone(bool saveResult = true)
|
|
|
|
{
|
|
|
|
Settings settings = ((!saveResult) ? unsavedSettings : this.settings);
|
|
|
|
settings.micDeviceIndex = 0;
|
|
|
|
bool flag = false;
|
2023-12-23 00:30:32 +00:00
|
|
|
string text = ((!saveResult) ? unsavedSettings.micDevice : this.settings.micDevice);
|
2023-12-22 22:51:17 +00:00
|
|
|
for (int i = 0; i < Microphone.devices.Length; i++)
|
|
|
|
{
|
|
|
|
if (Microphone.devices[i] == text)
|
|
|
|
{
|
|
|
|
settings.micDeviceIndex = i;
|
|
|
|
settings.micDevice = Microphone.devices[i];
|
|
|
|
flag = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!flag)
|
|
|
|
{
|
|
|
|
if (Microphone.devices.Length == 0)
|
|
|
|
{
|
|
|
|
SetSettingsOptionsText(SettingsOptionType.MicDevice, "No device found \n (click to refresh)");
|
2023-12-23 00:30:32 +00:00
|
|
|
settings.micDevice = "LCNoMic";
|
2023-12-22 22:51:17 +00:00
|
|
|
Debug.Log("No recording devices found");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
settings.micDevice = Microphone.devices[0];
|
|
|
|
}
|
|
|
|
SetSettingsOptionsText(SettingsOptionType.MicDevice, "Current input device: \n " + settings.micDevice);
|
|
|
|
if (saveResult && comms != null)
|
|
|
|
{
|
|
|
|
comms.MicrophoneName = settings.micDevice;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetSettingsOptionsText(SettingsOptionType optionType, string setToText)
|
|
|
|
{
|
|
|
|
SettingsOption[] array = UnityEngine.Object.FindObjectsOfType<SettingsOption>(includeInactive: true);
|
|
|
|
for (int i = 0; i < array.Length; i++)
|
|
|
|
{
|
|
|
|
if (array[i].optionType == optionType && array[i].textElement != null)
|
|
|
|
{
|
|
|
|
array[i].textElement.text = setToText;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SwitchMicrophoneSetting()
|
|
|
|
{
|
|
|
|
if (Microphone.devices.Length == 0)
|
|
|
|
{
|
|
|
|
Debug.Log("No mics found when trying to switch");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Debug.Log("Switching microphone");
|
|
|
|
unsavedSettings.micDeviceIndex = ++unsavedSettings.micDeviceIndex % Microphone.devices.Length;
|
|
|
|
unsavedSettings.micDevice = Microphone.devices[unsavedSettings.micDeviceIndex];
|
|
|
|
SetSettingsOptionsText(SettingsOptionType.MicDevice, "Current input device: \n " + unsavedSettings.micDevice);
|
|
|
|
DisplayPlayerMicVolume displayPlayerMicVolume = UnityEngine.Object.FindObjectOfType<DisplayPlayerMicVolume>();
|
|
|
|
if (displayPlayerMicVolume != null)
|
|
|
|
{
|
|
|
|
displayPlayerMicVolume.SwitchMicrophone();
|
|
|
|
}
|
|
|
|
if (comms != null)
|
|
|
|
{
|
|
|
|
comms.MicrophoneName = unsavedSettings.micDevice;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetMicrophoneEnabled()
|
|
|
|
{
|
|
|
|
unsavedSettings.micEnabled = !unsavedSettings.micEnabled;
|
|
|
|
if (comms != null && StartOfRound.Instance != null)
|
|
|
|
{
|
|
|
|
comms.IsMuted = !settings.micEnabled;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetMicPushToTalk()
|
|
|
|
{
|
|
|
|
unsavedSettings.pushToTalk = !unsavedSettings.pushToTalk;
|
|
|
|
if (unsavedSettings.pushToTalk)
|
|
|
|
{
|
|
|
|
SetSettingsOptionsText(SettingsOptionType.MicPushToTalk, "MODE: Push to talk");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetSettingsOptionsText(SettingsOptionType.MicPushToTalk, "MODE: Voice activation");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void UpdateMicPushToTalkButton()
|
|
|
|
{
|
|
|
|
if (settings.pushToTalk)
|
|
|
|
{
|
|
|
|
SetSettingsOptionsText(SettingsOptionType.MicPushToTalk, "MODE: Push to talk");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetSettingsOptionsText(SettingsOptionType.MicPushToTalk, "MODE: Voice activation");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetPlayerFinishedLaunchOptions()
|
|
|
|
{
|
|
|
|
settings.playerHasFinishedSetup = true;
|
|
|
|
unsavedSettings.playerHasFinishedSetup = true;
|
|
|
|
ES3.Save("PlayerFinishedSetup", value: true, "LCGeneralSaveData");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetLaunchInOnlineMode(bool enable)
|
|
|
|
{
|
|
|
|
settings.startInOnlineMode = enable;
|
|
|
|
unsavedSettings.startInOnlineMode = enable;
|
|
|
|
ES3.Save("StartInOnlineMode", enable, "LCGeneralSaveData");
|
|
|
|
}
|
|
|
|
|
2023-12-23 00:55:14 +00:00
|
|
|
public void RebindKey(InputActionReference rebindableAction, SettingsOption optionUI, int rebindIndex, bool gamepadRebinding = false)
|
2023-12-22 22:51:17 +00:00
|
|
|
{
|
|
|
|
if (rebindingOperation != null)
|
|
|
|
{
|
|
|
|
rebindingOperation.Dispose();
|
|
|
|
if (currentRebindingKeyUI != null)
|
|
|
|
{
|
|
|
|
currentRebindingKeyUI.currentlyUsedKeyText.enabled = true;
|
|
|
|
currentRebindingKeyUI.waitingForInput.SetActive(value: false);
|
|
|
|
}
|
|
|
|
}
|
2023-12-23 00:05:55 +00:00
|
|
|
optionUI.currentlyUsedKeyText.enabled = false;
|
|
|
|
optionUI.waitingForInput.SetActive(value: true);
|
2023-12-22 22:51:17 +00:00
|
|
|
playerInput.DeactivateInput();
|
|
|
|
currentRebindingKeyUI = optionUI;
|
2023-12-23 00:55:14 +00:00
|
|
|
bool getBindingIndexManually = rebindIndex != -1;
|
|
|
|
if (rebindIndex == -1)
|
|
|
|
{
|
|
|
|
rebindIndex = 0;
|
|
|
|
}
|
|
|
|
Debug.Log($"Rebinding starting.. rebindIndex: {rebindIndex}");
|
|
|
|
if (gamepadRebinding)
|
|
|
|
{
|
|
|
|
rebindingOperation = rebindableAction.action.PerformInteractiveRebinding(rebindIndex).OnMatchWaitForAnother(0.1f).WithControlsHavingToMatchPath("<Gamepad>")
|
2023-12-23 02:05:52 +00:00
|
|
|
.WithCancelingThrough(playerInput.actions.FindAction("OpenMenu").controls[2])
|
2023-12-23 00:55:14 +00:00
|
|
|
.OnComplete(delegate
|
|
|
|
{
|
|
|
|
CompleteRebind(optionUI, getBindingIndexManually, rebindIndex);
|
|
|
|
})
|
|
|
|
.Start();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rebindingOperation = rebindableAction.action.PerformInteractiveRebinding(rebindIndex).OnMatchWaitForAnother(0.1f).WithControlsHavingToMatchPath("<Keyboard>")
|
|
|
|
.WithControlsHavingToMatchPath("<Mouse>")
|
2023-12-23 02:05:52 +00:00
|
|
|
.WithControlsExcluding("<Mouse>/scroll/y")
|
|
|
|
.WithCancelingThrough(playerInput.actions.FindAction("OpenMenu").controls[0])
|
2023-12-23 00:55:14 +00:00
|
|
|
.OnComplete(delegate
|
|
|
|
{
|
|
|
|
CompleteRebind(optionUI, getBindingIndexManually, rebindIndex);
|
|
|
|
})
|
|
|
|
.Start();
|
|
|
|
}
|
|
|
|
Debug.Log("Rebinding starting.. B");
|
2023-12-22 22:51:17 +00:00
|
|
|
}
|
|
|
|
|
2023-12-23 00:55:14 +00:00
|
|
|
public void CompleteRebind(SettingsOption optionUI, bool getBindingIndexManually, int setBindingIndex = 0)
|
2023-12-22 22:51:17 +00:00
|
|
|
{
|
|
|
|
InputAction action = rebindingOperation.action;
|
|
|
|
if (rebindingOperation != null)
|
|
|
|
{
|
|
|
|
rebindingOperation.Dispose();
|
|
|
|
}
|
|
|
|
playerInput.ActivateInput();
|
2023-12-23 00:55:14 +00:00
|
|
|
int num;
|
|
|
|
if (!getBindingIndexManually)
|
|
|
|
{
|
|
|
|
num = action.GetBindingIndexForControl(action.controls[0]);
|
|
|
|
Debug.Log($"Setting binding index to default which is {num}");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Debug.Log($"Setting binding index to manual which is {setBindingIndex}");
|
|
|
|
num = setBindingIndex;
|
|
|
|
}
|
|
|
|
optionUI.currentlyUsedKeyText.text = InputControlPath.ToHumanReadableString(action.bindings[num].effectivePath, InputControlPath.HumanReadableStringOptions.OmitDevice);
|
2023-12-22 22:51:17 +00:00
|
|
|
optionUI.currentlyUsedKeyText.enabled = true;
|
|
|
|
optionUI.waitingForInput.SetActive(value: false);
|
2023-12-23 00:55:14 +00:00
|
|
|
Debug.Log("Rebinding finishing.. A");
|
2023-12-22 22:51:17 +00:00
|
|
|
unsavedSettings.keyBindings = playerInput.actions.SaveBindingOverridesAsJson();
|
|
|
|
SetChangesNotAppliedTextVisible();
|
2023-12-23 00:55:14 +00:00
|
|
|
Debug.Log("Rebinding finishing.. B");
|
2023-12-22 22:51:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void CancelRebind(SettingsOption optionUI = null)
|
|
|
|
{
|
|
|
|
if (rebindingOperation != null)
|
|
|
|
{
|
|
|
|
rebindingOperation.Dispose();
|
|
|
|
}
|
2023-12-23 00:55:14 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
playerInput.ActivateInput();
|
|
|
|
}
|
|
|
|
catch (Exception arg)
|
|
|
|
{
|
|
|
|
Debug.Log($"Unable to activate input!: {arg}");
|
|
|
|
}
|
2023-12-22 22:51:17 +00:00
|
|
|
if (!(optionUI == null))
|
|
|
|
{
|
|
|
|
optionUI.currentlyUsedKeyText.enabled = true;
|
|
|
|
optionUI.waitingForInput.SetActive(value: false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ResetSettingsToDefault()
|
|
|
|
{
|
|
|
|
SetChangesNotAppliedTextVisible(visible: false);
|
|
|
|
Settings copyFrom = new Settings(settings.playerHasFinishedSetup, settings.startInOnlineMode);
|
|
|
|
settings.CopySettings(copyFrom);
|
|
|
|
unsavedSettings.CopySettings(copyFrom);
|
|
|
|
SaveSettingsToPrefs();
|
|
|
|
UpdateGameToMatchSettings();
|
|
|
|
}
|
|
|
|
|
2023-12-23 02:05:52 +00:00
|
|
|
public void ResetAllKeybinds()
|
|
|
|
{
|
|
|
|
CancelRebind();
|
|
|
|
playerInput.actions.RemoveAllBindingOverrides();
|
|
|
|
unsavedSettings.keyBindings = string.Empty;
|
|
|
|
SetChangesNotAppliedTextVisible();
|
|
|
|
UpdateAllKeybindOptions();
|
|
|
|
}
|
|
|
|
|
2023-12-22 22:51:17 +00:00
|
|
|
public void SaveChangedSettings()
|
|
|
|
{
|
|
|
|
SetChangesNotAppliedTextVisible(visible: false);
|
|
|
|
Debug.Log("Saving changed settings");
|
|
|
|
settings.CopySettings(unsavedSettings);
|
|
|
|
SaveSettingsToPrefs();
|
|
|
|
UpdateGameToMatchSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void DisplayConfirmChangesScreen(bool visible)
|
|
|
|
{
|
|
|
|
MenuManager menuManager = UnityEngine.Object.FindObjectOfType<MenuManager>();
|
|
|
|
if (menuManager != null)
|
|
|
|
{
|
|
|
|
menuManager.PleaseConfirmChangesSettingsPanel.SetActive(visible);
|
2023-12-23 00:55:14 +00:00
|
|
|
menuManager.KeybindsPanel.SetActive(!visible);
|
2023-12-22 22:51:17 +00:00
|
|
|
menuManager.PleaseConfirmChangesSettingsPanelBackButton.Select();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QuickMenuManager quickMenuManager = UnityEngine.Object.FindObjectOfType<QuickMenuManager>();
|
|
|
|
if (quickMenuManager != null)
|
|
|
|
{
|
|
|
|
quickMenuManager.PleaseConfirmChangesSettingsPanel.SetActive(visible);
|
2023-12-23 00:55:14 +00:00
|
|
|
quickMenuManager.KeybindsPanel.SetActive(!visible);
|
2023-12-22 22:51:17 +00:00
|
|
|
quickMenuManager.PleaseConfirmChangesSettingsPanelBackButton.Select();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void DiscardChangedSettings()
|
|
|
|
{
|
|
|
|
SetChangesNotAppliedTextVisible(visible: false);
|
|
|
|
Debug.Log("Discarding changed settings");
|
|
|
|
unsavedSettings.CopySettings(settings);
|
|
|
|
if (!string.IsNullOrEmpty(settings.keyBindings))
|
|
|
|
{
|
|
|
|
playerInput.actions.LoadBindingOverridesFromJson(settings.keyBindings);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
playerInput.actions.RemoveAllBindingOverrides();
|
|
|
|
}
|
|
|
|
UpdateGameToMatchSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnDestroy()
|
|
|
|
{
|
|
|
|
SceneManager.sceneLoaded -= OnSceneLoaded;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnDisable()
|
|
|
|
{
|
|
|
|
SceneManager.sceneLoaded -= OnSceneLoaded;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnEnable()
|
|
|
|
{
|
|
|
|
SceneManager.sceneLoaded += OnSceneLoaded;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnSceneLoaded(Scene scene, LoadSceneMode loadType)
|
|
|
|
{
|
|
|
|
if (loadType == LoadSceneMode.Single)
|
|
|
|
{
|
|
|
|
UpdateGameToMatchSettings();
|
|
|
|
comms = UnityEngine.Object.FindObjectOfType<DissonanceComms>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SetChangesNotAppliedTextVisible(bool visible = true)
|
|
|
|
{
|
|
|
|
changesNotApplied = visible;
|
|
|
|
MenuManager menuManager = UnityEngine.Object.FindObjectOfType<MenuManager>();
|
|
|
|
if (menuManager != null)
|
|
|
|
{
|
|
|
|
menuManager.changesNotAppliedText.enabled = visible;
|
|
|
|
if (visible)
|
|
|
|
{
|
|
|
|
menuManager.settingsBackButton.text = "DISCARD";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
menuManager.settingsBackButton.text = "BACK";
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QuickMenuManager quickMenuManager = UnityEngine.Object.FindObjectOfType<QuickMenuManager>();
|
|
|
|
if (quickMenuManager != null)
|
|
|
|
{
|
|
|
|
quickMenuManager.changesNotAppliedText.enabled = visible;
|
|
|
|
if (visible)
|
|
|
|
{
|
|
|
|
quickMenuManager.settingsBackButton.text = "Discard changes";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
quickMenuManager.settingsBackButton.text = "Back";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|