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

137 lines
3.7 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;
public GameObject waitingForInput;
public TextMeshProUGUI currentlyUsedKeyText;
public void SetValueToMatchSettings()
{
switch (optionType)
{
case SettingsOptionType.ChangeBinding:
{
int bindingIndexForControl = rebindableAction.action.GetBindingIndexForControl(rebindableAction.action.controls[0]);
Debug.Log(InputControlPath.ToHumanReadableString(rebindableAction.action.bindings[bindingIndexForControl].effectivePath, InputControlPath.HumanReadableStringOptions.OmitDevice));
currentlyUsedKeyText.text = InputControlPath.ToHumanReadableString(rebindableAction.action.bindings[bindingIndexForControl].effectivePath, InputControlPath.HumanReadableStringOptions.OmitDevice);
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:
ToggleMicEnabledImage();
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;
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()
{
IngamePlayerSettings.Instance.RebindKey(rebindableAction, this);
}
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);
}
public void ToggleMicEnabledImage()
{
if (!(toggleImage == null))
{
if (IngamePlayerSettings.Instance.unsavedSettings.micEnabled)
{
toggleImage.sprite = enabledImage;
textElement.text = "ENABLED";
}
else
{
toggleImage.sprite = disabledImage;
textElement.text = "DISABLED";
}
}
}
public void ConfirmSettings()
{
IngamePlayerSettings.Instance.SaveChangedSettings();
}
public void ResetSettingsToDefault()
{
IngamePlayerSettings.Instance.ResetSettingsToDefault();
}
public void CancelSettings()
{
IngamePlayerSettings.Instance.DiscardChangedSettings();
}
}