From 16b00b622bf0844b1f65f93dc6d3a2dec46b9338 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 2 Jan 2019 02:13:04 +0100 Subject: [PATCH] Settings are now saved Tutorial is only displayed on first start (when no settings file is found) --- Assets/Resources/UI/SettingsView.prefab | 4 +- .../Scripts/AppInitializerBehaviour.cs | 5 +- .../RothenburgAR/Scripts/Common/PathHelper.cs | 5 ++ .../Scripts/Common/SettingsManager.cs | 51 +++++++++++++++++++ .../Scripts/Common/SettingsManager.cs.meta | 13 +++++ .../Scripts/UI/ColorSelectViewBehaviour.cs | 18 ++----- .../Scripts/UI/FontsizeSelectViewBehaviour.cs | 4 +- .../Scripts/UI/LanguageSelectViewBehaviour.cs | 14 ++--- .../Scripts/UI/TutorialViewBehaviour.cs | 4 +- .../Scripts/UI/UIColorSchemeManager.cs | 3 ++ Assets/RothenburgAR/Scripts/UI/UIManager.cs | 18 +++++-- .../Scripts/UI/UpdaterViewBehaviour.cs | 8 +-- .../{UpdaterBehaviour.cs => UpdateManager.cs} | 25 +-------- ...ehaviour.cs.meta => UpdateManager.cs.meta} | 0 14 files changed, 110 insertions(+), 62 deletions(-) create mode 100644 Assets/RothenburgAR/Scripts/Common/SettingsManager.cs create mode 100644 Assets/RothenburgAR/Scripts/Common/SettingsManager.cs.meta rename Assets/RothenburgAR/Scripts/Updater/{UpdaterBehaviour.cs => UpdateManager.cs} (93%) rename Assets/RothenburgAR/Scripts/Updater/{UpdaterBehaviour.cs.meta => UpdateManager.cs.meta} (100%) diff --git a/Assets/Resources/UI/SettingsView.prefab b/Assets/Resources/UI/SettingsView.prefab index df95133..6b63771 100644 --- a/Assets/Resources/UI/SettingsView.prefab +++ b/Assets/Resources/UI/SettingsView.prefab @@ -1819,7 +1819,7 @@ MonoBehaviour: m_Top: 0 m_Bottom: 0 m_ChildAlignment: 0 - m_Spacing: 16 + m_Spacing: 12 m_ChildForceExpandWidth: 1 m_ChildForceExpandHeight: 1 m_ChildControlWidth: 1 @@ -2977,7 +2977,7 @@ RectTransform: m_AnchorMin: {x: 0.5, y: 0} m_AnchorMax: {x: 0.5, y: 0} m_AnchoredPosition: {x: 0, y: 300} - m_SizeDelta: {x: 400, y: 350} + m_SizeDelta: {x: 400, y: 420} m_Pivot: {x: 0.5, y: 0.5} --- !u!224 &224877065014001232 RectTransform: diff --git a/Assets/RothenburgAR/Scripts/AppInitializerBehaviour.cs b/Assets/RothenburgAR/Scripts/AppInitializerBehaviour.cs index a7d5078..070fdde 100644 --- a/Assets/RothenburgAR/Scripts/AppInitializerBehaviour.cs +++ b/Assets/RothenburgAR/Scripts/AppInitializerBehaviour.cs @@ -33,11 +33,12 @@ namespace RothenburgAR UIManager.Instance.Initialize(); UIManager.Instance.UICamera = UICamera; UIManager.Instance.UIObjectCamera = UIObjectCamera; - UIManager.Instance.InitStartView(); + + StartCoroutine(UIManager.Instance.InitStartView()); InputManager.Instance.Initialize(); var initDisplayManagerSingleton = DisplayManager.Instance; - var initUpdaterSingleton = UpdaterBehaviour.Instance; + var initUpdaterSingleton = UpdateManager.Instance; } void InitializeData() diff --git a/Assets/RothenburgAR/Scripts/Common/PathHelper.cs b/Assets/RothenburgAR/Scripts/Common/PathHelper.cs index 1f02c17..8f27c5c 100644 --- a/Assets/RothenburgAR/Scripts/Common/PathHelper.cs +++ b/Assets/RothenburgAR/Scripts/Common/PathHelper.cs @@ -40,6 +40,11 @@ namespace RothenburgAR.Common get { return Directory.Exists(ExhibitionPath); } } + public static string SettingsFilePath + { + get { return Path.Combine(DataPath, "settings.json"); } + } + public static string GetXmlPathFromDirectoryPath(string poiDirectory) { string directoryName = new DirectoryInfo(poiDirectory).Name; diff --git a/Assets/RothenburgAR/Scripts/Common/SettingsManager.cs b/Assets/RothenburgAR/Scripts/Common/SettingsManager.cs new file mode 100644 index 0000000..8e97707 --- /dev/null +++ b/Assets/RothenburgAR/Scripts/Common/SettingsManager.cs @@ -0,0 +1,51 @@ +using System.IO; +using Newtonsoft.Json; +using RothenburgAR.UI; + +namespace RothenburgAR.Common +{ + class SettingsManager : Singleton + { + public bool? IsInitialized { get; private set; } + + internal class Settings + { + public string Language { get; set; } + public FontsizeSetting Fontsize { get; set; } + public int ColorschemeID { get; set; } + } + + private Settings settings; + + public void Start() + { + if (File.Exists(PathHelper.SettingsFilePath)) + { + //load settings file into settings object if existent + var json = File.ReadAllText(PathHelper.SettingsFilePath); + settings = JsonConvert.DeserializeObject(json); + + LanguageManager.Instance.CurrentLanguageKey = settings.Language; + UIColorSchemeManager.Instance.SetUiColorScheme(settings.ColorschemeID); + FontsizeManager.Instance.CurrentFontsizeSetting = settings.Fontsize; + + IsInitialized = true; + } + else + { + settings = new Settings(); + IsInitialized = false; + } + } + + public void PersistSettings() + { + settings.Language = LanguageManager.Instance.CurrentLanguageKey; + settings.ColorschemeID = UIColorSchemeManager.Instance.CurrentColorSchemeID; + settings.Fontsize = FontsizeManager.Instance.CurrentFontsizeSetting; + + var json = JsonConvert.SerializeObject(settings); + File.WriteAllText(PathHelper.SettingsFilePath, json); + } + } +} \ No newline at end of file diff --git a/Assets/RothenburgAR/Scripts/Common/SettingsManager.cs.meta b/Assets/RothenburgAR/Scripts/Common/SettingsManager.cs.meta new file mode 100644 index 0000000..3a0f8ed --- /dev/null +++ b/Assets/RothenburgAR/Scripts/Common/SettingsManager.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: d50764101604fa14d92f7523c16bdabc +timeCreated: 1546388554 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/RothenburgAR/Scripts/UI/ColorSelectViewBehaviour.cs b/Assets/RothenburgAR/Scripts/UI/ColorSelectViewBehaviour.cs index 535bdd0..e6e0752 100644 --- a/Assets/RothenburgAR/Scripts/UI/ColorSelectViewBehaviour.cs +++ b/Assets/RothenburgAR/Scripts/UI/ColorSelectViewBehaviour.cs @@ -2,6 +2,7 @@ using UnityEngine; using UnityEngine.UI; using System.Collections.Generic; +using RothenburgAR.Common; namespace RothenburgAR.UI { @@ -26,6 +27,8 @@ namespace RothenburgAR.UI selectionCircle.GetComponentInChildren