LethalCompany/Lethal Company/ExportedProject/Assets/Scripts/Assembly-CSharp/SettingsOption.cs

184 lines
4.5 KiB
C#
Raw Normal View History

2023-12-22 22:51:17 +00:00
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;
public class SettingsOption : MonoBehaviour
{
public SettingsOptionType optionType;
public TextMeshProUGUI textElement;
public Image toggleImage;
public Sprite enabledImage;
public Sprite disabledImage;
private bool askedForConfirmation;
[Header("Key rebinding")]
public InputActionReference rebindableAction;
2023-12-23 00:55:14 +00:00
public int rebindableActionBindingIndex = -1;
public bool gamepadOnlyRebinding;
2023-12-23 02:05:52 +00:00
public bool requireButtonType;
2023-12-22 22:51:17 +00:00
public GameObject waitingForInput;
public TextMeshProUGUI currentlyUsedKeyText;
2023-12-23 00:55:14 +00:00
public void CancelRebinds()
{
IngamePlayerSettings.Instance.CancelRebind();
}
2023-12-23 02:05:52 +00:00
public void SetBindingToCurrentSetting()
{
if (optionType == SettingsOptionType.ChangeBinding)
{
int bindingIndexForControl = rebindableAction.action.GetBindingIndexForControl(rebindableAction.action.controls[0]);
currentlyUsedKeyText.text = InputControlPath.ToHumanReadableString(rebindableAction.action.bindings[bindingIndexForControl].effectivePath, InputControlPath.HumanReadableStringOptions.OmitDevice);
}
}
public void ResetBindingsToDefaultButton()
{
IngamePlayerSettings.Instance.ResetAllKeybinds();
}
2023-12-22 22:51:17 +00:00
public void SetValueToMatchSettings()
{
switch (optionType)
{
case SettingsOptionType.ChangeBinding:
2023-12-23 02:05:52 +00:00
SetBindingToCurrentSetting();
2023-12-22 22:51:17 +00:00
break;
case SettingsOptionType.LookSens:
base.gameObject.GetComponentInChildren<Slider>().SetValueWithoutNotify(IngamePlayerSettings.Instance.settings.lookSensitivity);
break;
case SettingsOptionType.Gamma:
base.gameObject.GetComponentInChildren<Slider>().SetValueWithoutNotify(IngamePlayerSettings.Instance.settings.gammaSetting / 0.05f);
break;
case SettingsOptionType.MicEnabled:
2023-12-23 00:30:32 +00:00
ToggleEnabledImage(4);
2023-12-22 22:51:17 +00:00
break;
case SettingsOptionType.MasterVolume:
base.gameObject.GetComponentInChildren<Slider>().SetValueWithoutNotify(IngamePlayerSettings.Instance.settings.masterVolume * 100f);
break;
case SettingsOptionType.FramerateCap:
base.gameObject.GetComponentInChildren<TMP_Dropdown>().SetValueWithoutNotify(IngamePlayerSettings.Instance.settings.framerateCapIndex);
break;
case SettingsOptionType.FullscreenType:
base.gameObject.GetComponentInChildren<TMP_Dropdown>().SetValueWithoutNotify((int)IngamePlayerSettings.Instance.settings.fullScreenType);
break;
2023-12-23 00:30:32 +00:00
case SettingsOptionType.InvertYAxis:
ToggleEnabledImage(11);
break;
2023-12-23 00:55:14 +00:00
case SettingsOptionType.SpiderSafeMode:
ToggleEnabledImage(12);
break;
2023-12-22 22:51:17 +00:00
case SettingsOptionType.OnlineMode:
case SettingsOptionType.MicPushToTalk:
case SettingsOptionType.MicDevice:
case SettingsOptionType.CancelOrConfirm:
break;
}
}
public void SetMasterVolume()
{
AudioListener.volume = IngamePlayerSettings.Instance.settings.masterVolume;
}
public void StartRebindKey()
{
2023-12-23 00:55:14 +00:00
IngamePlayerSettings.Instance.RebindKey(rebindableAction, this, rebindableActionBindingIndex, gamepadOnlyRebinding);
2023-12-22 22:51:17 +00:00
}
public void OnEnable()
{
if (optionType == SettingsOptionType.MicDevice)
{
IngamePlayerSettings.Instance.RefreshAndDisplayCurrentMicrophone();
}
}
public void OnDisable()
{
if (optionType == SettingsOptionType.ChangeBinding)
{
if (IngamePlayerSettings.Instance.rebindingOperation != null)
{
IngamePlayerSettings.Instance.CancelRebind();
}
currentlyUsedKeyText.enabled = true;
waitingForInput.SetActive(value: false);
}
}
public void SetSettingsOptionInt(int value)
{
IngamePlayerSettings.Instance.SetOption(optionType, value);
}
public void SetSettingsOptionFloat(float value)
{
IngamePlayerSettings.Instance.SetOption(optionType, (int)value);
}
2023-12-23 00:30:32 +00:00
public void ToggleEnabledImage(int optionType)
2023-12-22 22:51:17 +00:00
{
2023-12-23 00:30:32 +00:00
if (toggleImage == null)
{
return;
}
bool flag = false;
switch (optionType)
{
case 4:
flag = IngamePlayerSettings.Instance.unsavedSettings.micEnabled;
break;
case 11:
flag = IngamePlayerSettings.Instance.unsavedSettings.invertYAxis;
break;
2023-12-23 00:55:14 +00:00
case 12:
flag = IngamePlayerSettings.Instance.unsavedSettings.spiderSafeMode;
break;
2023-12-23 00:30:32 +00:00
}
if (flag)
2023-12-22 22:51:17 +00:00
{
2023-12-23 00:30:32 +00:00
toggleImage.sprite = enabledImage;
if (textElement != null)
2023-12-22 22:51:17 +00:00
{
textElement.text = "ENABLED";
}
2023-12-23 00:30:32 +00:00
}
else
{
toggleImage.sprite = disabledImage;
if (textElement != null)
2023-12-22 22:51:17 +00:00
{
textElement.text = "DISABLED";
}
}
}
public void ConfirmSettings()
{
IngamePlayerSettings.Instance.SaveChangedSettings();
}
public void ResetSettingsToDefault()
{
IngamePlayerSettings.Instance.ResetSettingsToDefault();
}
public void CancelSettings()
{
IngamePlayerSettings.Instance.DiscardChangedSettings();
}
}