| using System; |
| using System; |
| using System.Collections.Generic; |
| using System.Collections.Generic; |
| using UnityEngine; |
| using UnityEngine; |
| using UnityEngine.UI; |
| using UnityEngine.UI; |
| using Valheim.SettingsGui; |
| using Valheim.SettingsGui; |
| |
| |
| public class Settings : MonoBehaviour |
| public class Settings : MonoBehaviour |
| { |
| { |
| public static Settings instance |
| public static Settings instance |
| { |
| { |
| get |
| get |
| { |
| { |
| return Settings.m_instance; |
| return Settings.m_instance; |
| } |
| } |
| } |
| } |
| |
| |
| private void Awake() |
| private void Awake() |
| { |
| { |
| Settings.m_instance = this; |
| Settings.m_instance = this; |
| this.m_tabHandler = base.GetComponentInChildren<TabHandler>(); |
| this.m_tabHandler = base.GetComponentInChildren<TabHandler>(); |
| this.SetAvailableTabs(); |
| this.SetAvailableTabs(); |
| ZInput.OnInputLayoutChanged += this.OnInputLayoutChanged; |
| ZInput.OnInputLayoutChanged += this.OnInputLayoutChanged; |
| this.OnInputLayoutChanged(); |
| this.OnInputLayoutChanged(); |
| } |
| } |
| |
| |
| private void Update() |
| private void Update() |
| { |
| { |
| if (!this.m_navigationBlocked && ZInput.GetKeyDown(KeyCode.Escape, true)) |
| if (!this.m_navigationBlocked && ZInput.GetKeyDown(KeyCode.Escape, true)) |
| { |
| { |
| this.OnBack(); |
| this.OnBack(); |
| } |
| } |
| } |
| } |
| |
| |
| private void SetAvailableTabs() |
| private void SetAvailableTabs() |
| { |
| { |
| this.SettingsTabs = new List<SettingsBase>(); |
| this.SettingsTabs = new List<SettingsBase>(); |
| foreach (TabHandler.Tab tab in this.m_tabHandler.m_tabs) |
| foreach (TabHandler.Tab tab in this.m_tabHandler.m_tabs) |
| { |
| { |
| this.SettingsTabs.Add(tab.m_page.gameObject.GetComponent<SettingsBase>()); |
| this.SettingsTabs.Add(tab.m_page.gameObject.GetComponent<SettingsBase>()); |
| } |
| } |
| this.LoadTabSettings(); |
| this.LoadTabSettings(); |
| this.m_tabHandler.ActiveTabChanged -= this.ActiveTabChanged; |
| this.m_tabHandler.ActiveTabChanged -= this.ActiveTabChanged; |
| this.m_tabHandler.ActiveTabChanged += this.ActiveTabChanged; |
| this.m_tabHandler.ActiveTabChanged += this.ActiveTabChanged; |
| } |
| } |
| |
| |
| private void OnInputLayoutChanged() |
| private void OnInputLayoutChanged() |
| { |
| { |
| GameObject[] tabKeyHints = this.m_tabKeyHints; |
| GameObject[] tabKeyHints = this.m_tabKeyHints; |
| for (int i = 0; i < tabKeyHints.Length; i++) |
| for (int i = 0; i < tabKeyHints.Length; i++) |
| { |
| { |
| tabKeyHints[i].SetActive(ZInput.GamepadActive); |
| tabKeyHints[i].SetActive(ZInput.GamepadActive); |
| } |
| } |
| } |
| } |
| |
| |
| private void ActiveTabChanged(int index) |
| private void ActiveTabChanged(int index) |
| { |
| { |
| this.SettingsTabs[index].FixBackButtonNavigation(this.m_backButton); |
| this.SettingsTabs[index].FixBackButtonNavigation(this.m_backButton); |
| this.SettingsTabs[index].FixOkButtonNavigation(this.m_okButton); |
| this.SettingsTabs[index].FixOkButtonNavigation(this.m_okButton); |
| } |
| } |
| |
| |
| private void LoadTabSettings() |
| private void LoadTabSettings() |
| { |
| { |
| foreach (SettingsBase settingsBase in this.SettingsTabs) |
| foreach (SettingsBase settingsBase in this.SettingsTabs) |
| { |
| { |
| settingsBase.LoadSettings(); |
| settingsBase.LoadSettings(); |
| } |
| } |
| } |
| } |
| |
| |
| private void ResetTabSettings() |
| private void ResetTabSettings() |
| { |
| { |
| foreach (SettingsBase settingsBase in this.SettingsTabs) |
| foreach (SettingsBase settingsBase in this.SettingsTabs) |
| { |
| { |
| settingsBase.ResetSettings(); |
| settingsBase.ResetSettings(); |
| } |
| } |
| ZInput.instance.Save(); |
| ZInput.instance.Save(); |
| } |
| } |
| |
| |
| private void SaveTabSettings() |
| private void SaveTabSettings() |
| { |
| { |
| this.m_tabsToSave = 0; |
| this.m_tabsToSave = 0; |
| foreach (SettingsBase settingsBase in this.SettingsTabs) |
| foreach (SettingsBase settingsBase in this.SettingsTabs) |
| { |
| { |
| settingsBase.Saved = (Action)Delegate.Remove(settingsBase.Saved, new Action(this.TabSaved)); |
| settingsBase.Saved = (Action)Delegate.Remove(settingsBase.Saved, new Action(this.TabSaved)); |
| settingsBase.Saved = (Action)Delegate.Combine(settingsBase.Saved, new Action(this.TabSaved)); |
| settingsBase.Saved = (Action)Delegate.Combine(settingsBase.Saved, new Action(this.TabSaved)); |
| this.m_tabsToSave++; |
| this.m_tabsToSave++; |
| } |
| } |
| foreach (SettingsBase settingsBase2 in this.SettingsTabs) |
| foreach (SettingsBase settingsBase2 in this.SettingsTabs) |
| { |
| { |
| settingsBase2.SaveSettings(); |
| settingsBase2.SaveSettings(); |
| } |
| } |
| } |
| } |
| |
| |
| private void ApplyAndClose() |
| private void ApplyAndClose() |
| { |
| { |
| ZInput.instance.Save(); |
| ZInput.instance.Save(); |
| if (GameCamera.instance) |
| if (GameCamera.instance) |
| { |
| { |
| GameCamera.instance.ApplySettings(); |
| GameCamera.instance.ApplySettings(); |
| } |
| } |
| if (CameraEffects.instance) |
| if (CameraEffects.instance) |
| { |
| { |
| CameraEffects.instance.ApplySettings(); |
| CameraEffects.instance.ApplySettings(); |
| } |
| } |
| if (ClutterSystem.instance) |
| if (ClutterSystem.instance) |
| { |
| { |
| ClutterSystem.instance.ApplySettings(); |
| ClutterSystem.instance.ApplySettings(); |
| } |
| } |
| if (MusicMan.instance) |
| if (MusicMan.instance) |
| { |
| { |
| MusicMan.instance.ApplySettings(); |
| MusicMan.instance.ApplySettings(); |
| } |
| } |
| if (GameCamera.instance) |
| if (GameCamera.instance) |
| { |
| { |
| GameCamera.instance.ApplySettings(); |
| GameCamera.instance.ApplySettings(); |
| } |
| } |
| if (KeyHints.instance) |
| if (KeyHints.instance) |
| { |
| { |
| KeyHints.instance.ApplySettings(); |
| KeyHints.instance.ApplySettings(); |
| } |
| } |
| . | |
| DynamicParticleReduction[] array = UnityEngine.Object.FindObjectsOfType<DynamicParticleReduction>(); |
| |
| for (int i = 0; i < array.Length; i++) |
| |
| { |
| |
| array[i].ApplySettings(); |
| |
| } |
| PlayerPrefs.Save(); |
| PlayerPrefs.Save(); |
| UnityEngine.Object.Destroy(base.gameObject); |
| UnityEngine.Object.Destroy(base.gameObject); |
| } |
| } |
| |
| |
| private void TabSaved() |
| private void TabSaved() |
| { |
| { |
| int num = this.m_tabsToSave - 1; |
| int num = this.m_tabsToSave - 1; |
| this.m_tabsToSave = num; |
| this.m_tabsToSave = num; |
| if (num > 0) |
| if (num > 0) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| this.ApplyAndClose(); |
| this.ApplyAndClose(); |
| } |
| } |
| |
| |
| private void OnDestroy() |
| private void OnDestroy() |
| { |
| { |
| ZInput.OnInputLayoutChanged -= this.OnInputLayoutChanged; |
| ZInput.OnInputLayoutChanged -= this.OnInputLayoutChanged; |
| this.m_tabHandler.ActiveTabChanged -= this.ActiveTabChanged; |
| this.m_tabHandler.ActiveTabChanged -= this.ActiveTabChanged; |
| Action settingsPopupDestroyed = this.SettingsPopupDestroyed; |
| Action settingsPopupDestroyed = this.SettingsPopupDestroyed; |
| if (settingsPopupDestroyed != null) |
| if (settingsPopupDestroyed != null) |
| { |
| { |
| settingsPopupDestroyed(); |
| settingsPopupDestroyed(); |
| } |
| } |
| Settings.m_instance = null; |
| Settings.m_instance = null; |
| } |
| } |
| |
| |
| public void OnBack() |
| public void OnBack() |
| { |
| { |
| this.ResetTabSettings(); |
| this.ResetTabSettings(); |
| UnityEngine.Object.Destroy(base.gameObject); |
| UnityEngine.Object.Destroy(base.gameObject); |
| } |
| } |
| |
| |
| public void OnOk() |
| public void OnOk() |
| { |
| { |
| this.SaveTabSettings(); |
| this.SaveTabSettings(); |
| } |
| } |
| |
| |
| public void BlockNavigation(bool block) |
| public void BlockNavigation(bool block) |
| { |
| { |
| this.m_navigationBlocked = block; |
| this.m_navigationBlocked = block; |
| this.m_okButton.gameObject.SetActive(!block); |
| this.m_okButton.gameObject.SetActive(!block); |
| this.m_backButton.gameObject.SetActive(!block); |
| this.m_backButton.gameObject.SetActive(!block); |
| this.m_tabHandler.m_gamepadInput = !block; |
| this.m_tabHandler.m_gamepadInput = !block; |
| this.m_tabHandler.m_keybaordInput = !block; |
| this.m_tabHandler.m_keybaordInput = !block; |
| this.m_tabHandler.m_tabKeyInput = !block; |
| this.m_tabHandler.m_tabKeyInput = !block; |
| } |
| } |
| |
| |
| public static void SetPlatformDefaultPrefs() |
| public static void SetPlatformDefaultPrefs() |
| { |
| { |
| if (Settings.IsSteamRunningOnSteamDeck()) |
| if (Settings.IsSteamRunningOnSteamDeck()) |
| { |
| { |
| ZLog.Log("Running on Steam Deck!"); |
| ZLog.Log("Running on Steam Deck!"); |
| } |
| } |
| else |
| else |
| { |
| { |
| ZLog.Log("Using default prefs"); |
| ZLog.Log("Using default prefs"); |
| } |
| } |
| PlatformPrefs.PlatformDefaults[] array = new PlatformPrefs.PlatformDefaults[1]; |
| PlatformPrefs.PlatformDefaults[] array = new PlatformPrefs.PlatformDefaults[1]; |
| array[0] = new PlatformPrefs.PlatformDefaults("deck_", () => Settings.IsSteamRunningOnSteamDeck(), new Dictionary<string, PlatformPrefs> |
| array[0] = new PlatformPrefs.PlatformDefaults("deck_", () => Settings.IsSteamRunningOnSteamDeck(), new Dictionary<string, PlatformPrefs> |
| { |
| { |
| { "GuiScale", 1.15f }, |
| { "GuiScale", 1.15f }, |
| { "DOF", 0 }, |
| { "DOF", 0 }, |
| { "VSync", 0 }, |
| { "VSync", 0 }, |
| { "Bloom", 1 }, |
| { "Bloom", 1 }, |
| { "SSAO", 1 }, |
| { "SSAO", 1 }, |
| { "SunShafts", 1 }, |
| { "SunShafts", 1 }, |
| { "AntiAliasing", 0 }, |
| { "AntiAliasing", 0 }, |
| { "ChromaticAberration", 1 }, |
| { "ChromaticAberration", 1 }, |
| { "MotionBlur", 0 }, |
| { "MotionBlur", 0 }, |
| { "SoftPart", 1 }, |
| { "SoftPart", 1 }, |
| { "Tesselation", 0 }, |
| { "Tesselation", 0 }, |
| { "DistantShadows", 1 }, |
| { "DistantShadows", 1 }, |
| { "ShadowQuality", 0 }, |
| { "ShadowQuality", 0 }, |
| { "LodBias", 1 }, |
| { "LodBias", 1 }, |
| { "Lights", 1 }, |
| { "Lights", 1 }, |
| { "ClutterQuality", 1 }, |
| { "ClutterQuality", 1 }, |
| { "PointLights", 1 }, |
| { "PointLights", 1 }, |
| { "PointLightShadows", 1 }, |
| { "PointLightShadows", 1 }, |
| { "FPSLimit", 60 } |
| { "FPSLimit", 60 } |
| }); |
| }); |
| PlatformPrefs.SetDefaults(array); |
| PlatformPrefs.SetDefaults(array); |
| } |
| } |
| |
| |
| public static bool IsSteamRunningOnSteamDeck() |
| public static bool IsSteamRunningOnSteamDeck() |
| { |
| { |
| string environmentVariable = Environment.GetEnvironmentVariable("SteamDeck"); |
| string environmentVariable = Environment.GetEnvironmentVariable("SteamDeck"); |
| return !string.IsNullOrEmpty(environmentVariable) && environmentVariable != "0"; |
| return !string.IsNullOrEmpty(environmentVariable) && environmentVariable != "0"; |
| } |
| } |
| |
| |
| public static void ApplyStartupSettings() |
| public static void ApplyStartupSettings() |
| { |
| { |
| Settings.ReduceBackgroundUsage = PlatformPrefs.GetInt("ReduceBackgroundUsage", 0) == 1; |
| Settings.ReduceBackgroundUsage = PlatformPrefs.GetInt("ReduceBackgroundUsage", 0) == 1; |
| Settings.ContinousMusic = PlatformPrefs.GetInt("ContinousMusic", 1) == 1; |
| Settings.ContinousMusic = PlatformPrefs.GetInt("ContinousMusic", 1) == 1; |
| Settings.ReduceFlashingLights = PlatformPrefs.GetInt("ReduceFlashingLights", 0) == 1; |
| Settings.ReduceFlashingLights = PlatformPrefs.GetInt("ReduceFlashingLights", 0) == 1; |
| Raven.m_tutorialsEnabled = PlatformPrefs.GetInt("TutorialsEnabled", 1) == 1; |
| Raven.m_tutorialsEnabled = PlatformPrefs.GetInt("TutorialsEnabled", 1) == 1; |
| GraphicsModeManager.Initialize(); |
| GraphicsModeManager.Initialize(); |
| } |
| } |
| |
| |
| public static void ApplyQualitySettings() |
| public static void ApplyQualitySettings() |
| { |
| { |
| bool startUp = Settings.m_startUp; |
| bool startUp = Settings.m_startUp; |
| QualitySettings.vSyncCount = ((PlatformPrefs.GetInt("VSync", 0) == 1) ? 1 : 0); |
| QualitySettings.vSyncCount = ((PlatformPrefs.GetInt("VSync", 0) == 1) ? 1 : 0); |
| QualitySettings.softParticles = PlatformPrefs.GetInt("SoftPart", 1) == 1; |
| QualitySettings.softParticles = PlatformPrefs.GetInt("SoftPart", 1) == 1; |
| if (PlatformPrefs.GetInt("Tesselation", 1) == 1) |
| if (PlatformPrefs.GetInt("Tesselation", 1) == 1) |
| { |
| { |
| Shader.EnableKeyword("TESSELATION_ON"); |
| Shader.EnableKeyword("TESSELATION_ON"); |
| } |
| } |
| else |
| else |
| { |
| { |
| Shader.DisableKeyword("TESSELATION_ON"); |
| Shader.DisableKeyword("TESSELATION_ON"); |
| } |
| } |
| switch (PlatformPrefs.GetInt("LodBias", 2)) |
| switch (PlatformPrefs.GetInt("LodBias", 2)) |
| { |
| { |
| case 0: |
| case 0: |
| QualitySettings.lodBias = 1f; |
| QualitySettings.lodBias = 1f; |
| break; |
| break; |
| case 1: |
| case 1: |
| QualitySettings.lodBias = 1.5f; |
| QualitySettings.lodBias = 1.5f; |
| break; |
| break; |
| case 2: |
| case 2: |
| QualitySettings.lodBias = 2f; |
| QualitySettings.lodBias = 2f; |
| break; |
| break; |
| case 3: |
| case 3: |
| QualitySettings.lodBias = 5f; |
| QualitySettings.lodBias = 5f; |
| break; |
| break; |
| } |
| } |
| switch (PlatformPrefs.GetInt("Lights", 2)) |
| switch (PlatformPrefs.GetInt("Lights", 2)) |
| { |
| { |
| case 0: |
| case 0: |
| QualitySettings.pixelLightCount = 2; |
| QualitySettings.pixelLightCount = 2; |
| break; |
| break; |
| case 1: |
| case 1: |
| QualitySettings.pixelLightCount = 4; |
| QualitySettings.pixelLightCount = 4; |
| break; |
| break; |
| case 2: |
| case 2: |
| QualitySettings.pixelLightCount = 8; |
| QualitySettings.pixelLightCount = 8; |
| break; |
| break; |
| } |
| } |
| LightLod.m_lightLimit = Settings.GetPointLightLimit(PlatformPrefs.GetInt("PointLights", 3)); |
| LightLod.m_lightLimit = Settings.GetPointLightLimit(PlatformPrefs.GetInt("PointLights", 3)); |
| LightLod.m_shadowLimit = Settings.GetPointLightShadowLimit(PlatformPrefs.GetInt("PointLightShadows", 2)); |
| LightLod.m_shadowLimit = Settings.GetPointLightShadowLimit(PlatformPrefs.GetInt("PointLightShadows", 2)); |
| Settings.FPSLimit = PlatformPrefs.GetInt("FPSLimit", -1); |
| Settings.FPSLimit = PlatformPrefs.GetInt("FPSLimit", -1); |
| float @float = PlatformPrefs.GetFloat("RenderScale", 1f); |
| float @float = PlatformPrefs.GetFloat("RenderScale", 1f); |
| if (@float <= 0f) |
| if (@float <= 0f) |
| { |
| { |
| VirtualFrameBuffer.m_autoRenderScale = true; |
| VirtualFrameBuffer.m_autoRenderScale = true; |
| } |
| } |
| else |
| else |
| { |
| { |
| VirtualFrameBuffer.m_autoRenderScale = false; |
| VirtualFrameBuffer.m_autoRenderScale = false; |
| VirtualFrameBuffer.m_global3DRenderScale = Mathf.Clamp01(@float); |
| VirtualFrameBuffer.m_global3DRenderScale = Mathf.Clamp01(@float); |
| } |
| } |
| Settings.ApplyShadowQuality(); |
| Settings.ApplyShadowQuality(); |
| Settings.m_startUp = false; |
| Settings.m_startUp = false; |
| } |
| } |
| |
| |
| public static int GetPointLightLimit(int level) |
| public static int GetPointLightLimit(int level) |
| { |
| { |
| switch (level) |
| switch (level) |
| { |
| { |
| case 0: |
| case 0: |
| return 4; |
| return 4; |
| case 1: |
| case 1: |
| return 15; |
| return 15; |
| case 3: |
| case 3: |
| return -1; |
| return -1; |
| } |
| } |
| return 40; |
| return 40; |
| } |
| } |
| |
| |
| public static int GetPointLightShadowLimit(int level) |
| public static int GetPointLightShadowLimit(int level) |
| { |
| { |
| switch (level) |
| switch (level) |
| { |
| { |
| case 0: |
| case 0: |
| return 0; |
| return 0; |
| case 1: |
| case 1: |
| return 1; |
| return 1; |
| case 3: |
| case 3: |
| return -1; |
| return -1; |
| } |
| } |
| return 3; |
| return 3; |
| } |
| } |
| |
| |
| public static void ApplyShadowQuality() |
| public static void ApplyShadowQuality() |
| { |
| { |
| int @int = PlatformPrefs.GetInt("ShadowQuality", 2); |
| int @int = PlatformPrefs.GetInt("ShadowQuality", 2); |
| int int2 = PlatformPrefs.GetInt("DistantShadows", 1); |
| int int2 = PlatformPrefs.GetInt("DistantShadows", 1); |
| switch (@int) |
| switch (@int) |
| { |
| { |
| case 0: |
| case 0: |
| QualitySettings.shadowCascades = 2; |
| QualitySettings.shadowCascades = 2; |
| QualitySettings.shadowDistance = 80f; |
| QualitySettings.shadowDistance = 80f; |
| QualitySettings.shadowResolution = ShadowResolution.Low; |
| QualitySettings.shadowResolution = ShadowResolution.Low; |
| break; |
| break; |
| case 1: |
| case 1: |
| QualitySettings.shadowCascades = 3; |
| QualitySettings.shadowCascades = 3; |
| QualitySettings.shadowDistance = 120f; |
| QualitySettings.shadowDistance = 120f; |
| QualitySettings.shadowResolution = ShadowResolution.Medium; |
| QualitySettings.shadowResolution = ShadowResolution.Medium; |
| break; |
| break; |
| case 2: |
| case 2: |
| QualitySettings.shadowCascades = 4; |
| QualitySettings.shadowCascades = 4; |
| QualitySettings.shadowDistance = 150f; |
| QualitySettings.shadowDistance = 150f; |
| QualitySettings.shadowResolution = ShadowResolution.High; |
| QualitySettings.shadowResolution = ShadowResolution.High; |
| break; |
| break; |
| } |
| } |
| Heightmap.EnableDistantTerrainShadows = int2 == 1; |
| Heightmap.EnableDistantTerrainShadows = int2 == 1; |
| } |
| } |
| |
| |
| public event Action SettingsPopupDestroyed; |
| public event Action SettingsPopupDestroyed; |
| |
| |
| private static Settings m_instance; |
| private static Settings m_instance; |
| |
| |
| private static bool m_startUp = true; |
| private static bool m_startUp = true; |
| |
| |
| public const bool c_vsyncRequiresRestart = false; |
| public const bool c_vsyncRequiresRestart = false; |
| |
| |
| public const float c_renderScaleDefault = 1f; |
| public const float c_renderScaleDefault = 1f; |
| |
| |
| public static int FPSLimit = -1; |
| public static int FPSLimit = -1; |
| |
| |
| public static bool ReduceBackgroundUsage = false; |
| public static bool ReduceBackgroundUsage = false; |
| |
| |
| public static bool ContinousMusic = true; |
| public static bool ContinousMusic = true; |
| |
| |
| public static bool ReduceFlashingLights = false; |
| public static bool ReduceFlashingLights = false; |
| |
| |
| public static AssetMemoryUsagePolicy AssetMemoryUsagePolicy = AssetMemoryUsagePolicy.KeepSynchronousOnlyLoaded; |
| public static AssetMemoryUsagePolicy AssetMemoryUsagePolicy = AssetMemoryUsagePolicy.KeepSynchronousOnlyLoaded; |
| |
| |
| [SerializeField] |
| [SerializeField] |
| private GameObject[] m_tabKeyHints; |
| private GameObject[] m_tabKeyHints; |
| |
| |
| [SerializeField] |
| [SerializeField] |
| private GameObject m_settingsPanel; |
| private GameObject m_settingsPanel; |
| |
| |
| [SerializeField] |
| [SerializeField] |
| private TabHandler m_tabHandler; |
| private TabHandler m_tabHandler; |
| |
| |
| [SerializeField] |
| [SerializeField] |
| private Button m_backButton; |
| private Button m_backButton; |
| |
| |
| [SerializeField] |
| [SerializeField] |
| private Button m_okButton; |
| private Button m_okButton; |
| |
| |
| private bool m_navigationBlocked; |
| private bool m_navigationBlocked; |
| |
| |
| private List<SettingsBase> SettingsTabs; |
| private List<SettingsBase> SettingsTabs; |
| |
| |
| private int m_tabsToSave; |
| private int m_tabsToSave; |
| |
| |
| public Action<string, int> SharedSettingsChanged; |
| public Action<string, int> SharedSettingsChanged; |
| } |
| } |
| |
| |