using System; using System.Collections.Generic; 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; private Setting.GameSettings currentSettings; public override void Show() { base.Show(); currentSettings = 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 List(); foreach (var resolution in Setting.CommonResolutions) options.Add(new TMP_Dropdown.OptionData(resolution.ToString())); windowResolution.AddOptions(options); if (currentSettings.windowResolution != null) { var resolutionIndex = Array.FindIndex(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 = (Setting.WindowMode)windowMode.value; currentSettings.windowResolution = Setting.CommonResolutions[windowResolution.value]; currentSettings.progressStepDuration = float.Parse(progressStepDuration.text, CultureInfo.InvariantCulture); currentSettings.exitAnimationDuration = float.Parse(exitAnimationDuration.text, CultureInfo.InvariantCulture); currentSettings.showMiniMap = showMiniMap.isOn; Setting.Instance.CurrentSettings = currentSettings; Setting.Instance.Apply(); } public void EnterSetting() { ApplySettings(); UIInputControl.Instance.Hide(this); Setting.Instance.SaveSettings(); } } }