76 lines
3.2 KiB
C#
76 lines
3.2 KiB
C#
using System.Globalization;
|
|
using Base;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace UI
|
|
{
|
|
public class SettingUI : FullScreenUI
|
|
{
|
|
[SerializeField] private Scrollbar globalVolume;
|
|
[SerializeField] private Toggle developerMode;
|
|
[SerializeField] private Toggle friendlyFire;
|
|
[SerializeField] private Toggle showMiniMap;
|
|
[SerializeField] private TMP_Dropdown windowMode;
|
|
[SerializeField] private TMP_Dropdown windowResolution;
|
|
[SerializeField] private TMP_InputField progressStepDuration;
|
|
[SerializeField] private TMP_InputField exitAnimationDuration;
|
|
|
|
Base.Setting.GameSettings currentSettings;
|
|
|
|
public override void Show()
|
|
{
|
|
base.Show();
|
|
currentSettings = Base.Setting.Instance.CurrentSettings;
|
|
globalVolume.value = currentSettings.globalVolume;
|
|
developerMode.isOn = currentSettings.developerMode;
|
|
friendlyFire.isOn = currentSettings.friendlyFire;
|
|
showMiniMap.isOn = currentSettings.showMiniMap;
|
|
|
|
progressStepDuration.text = currentSettings.progressStepDuration.ToString(CultureInfo.InvariantCulture);
|
|
exitAnimationDuration.text = currentSettings.exitAnimationDuration.ToString(CultureInfo.InvariantCulture);
|
|
|
|
windowResolution.ClearOptions();
|
|
var options = new System.Collections.Generic.List<TMP_Dropdown.OptionData>();
|
|
foreach (var resolution in Base.Setting.CommonResolutions)
|
|
{
|
|
options.Add(new TMP_Dropdown.OptionData(resolution.ToString()));
|
|
}
|
|
windowResolution.AddOptions(options);
|
|
if (currentSettings.windowResolution != null)
|
|
{
|
|
var resolutionIndex = System.Array.FindIndex(Base.Setting.CommonResolutions, r => r == currentSettings.windowResolution);
|
|
windowResolution.value = resolutionIndex >= 0 ? resolutionIndex : 0;
|
|
}
|
|
else
|
|
{
|
|
windowResolution.value = 0;
|
|
}
|
|
windowMode.value = (int)currentSettings.currentWindowMode;
|
|
}
|
|
public void CancelSettings()
|
|
{
|
|
UIInputControl.Instance.Hide(this);
|
|
}
|
|
public void ApplySettings()
|
|
{
|
|
currentSettings.globalVolume = globalVolume.value;
|
|
currentSettings.developerMode = developerMode.isOn;
|
|
currentSettings.friendlyFire = friendlyFire.isOn;
|
|
currentSettings.currentWindowMode = (Base.Setting.WindowMode)windowMode.value;
|
|
currentSettings.windowResolution = Base.Setting.CommonResolutions[windowResolution.value];
|
|
currentSettings.progressStepDuration = float.Parse(progressStepDuration.text, CultureInfo.InvariantCulture);
|
|
currentSettings.exitAnimationDuration = float.Parse(exitAnimationDuration.text, CultureInfo.InvariantCulture);
|
|
currentSettings.showMiniMap = showMiniMap.isOn;
|
|
Base.Setting.Instance.CurrentSettings = currentSettings;
|
|
Base.Setting.Instance.Apply();
|
|
}
|
|
public void EnterSetting()
|
|
{
|
|
ApplySettings();
|
|
UIInputControl.Instance.Hide(this);
|
|
Base.Setting.Instance.SaveSettings();
|
|
}
|
|
}
|
|
} |