Kaynağa Gözat

Add configuration serialization/deserialization

habeebweeb 4 yıl önce
ebeveyn
işleme
d2e3490228

+ 9 - 2
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Configuration.cs

@@ -1,8 +1,15 @@
+using BepInEx.Configuration;
+
 namespace COM3D2.MeidoPhotoStudio.Plugin
 {
     internal static class Configuration
     {
-        public static bool ModItemsOnly { get; private set; } = false;
-        public static string CurrentLanguage { get; private set; } = "en";
+        public static ConfigFile Config { get; private set; }
+
+        static Configuration()
+        {
+            string configPath = System.IO.Path.Combine(Constants.configPath, $"{MeidoPhotoStudio.pluginName}.cfg");
+            Config = new ConfigFile(configPath, false);
+        }
     }
 }

+ 2 - 2
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Constants.cs

@@ -667,7 +667,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 ModPropDict[MenuCategories[i]] = new List<ModItem>();
             }
 
-            if (!Configuration.ModItemsOnly)
+            if (!PropManager.ModItemsOnly)
             {
                 MenuDataBase menuDatabase = GameMain.Instance.MenuDataBase;
 
@@ -712,7 +712,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
         public static List<ModItem> GetModPropList(string category)
         {
-            if (!Configuration.ModItemsOnly)
+            if (!PropManager.ModItemsOnly)
             {
                 if (!MenuFileUtility.MenuFilesReady)
                 {

+ 7 - 5
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/BackgroundWindow2Panes/ModPropsPane.cs

@@ -24,7 +24,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private bool modFilter = false;
         private bool baseFilter = false;
         private int currentListCount;
-        private bool isModsOnly = Configuration.ModItemsOnly;
+        private bool isModsOnly = PropManager.ModItemsOnly;
         private enum FilterType
         {
             None, Mod, Base
@@ -34,7 +34,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         {
             this.propManager = propManager;
 
-            this.modItemsReady = MenuFileUtility.MenuFilesReady || Configuration.ModItemsOnly;
+            this.modItemsReady = MenuFileUtility.MenuFilesReady || PropManager.ModItemsOnly;
 
             string[] listItems = Translation.GetArray("clothing", MenuFileUtility.MenuCategories);
 
@@ -77,9 +77,11 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
             this.propCategoryDropdown.SetDropdownItems(listItems);
 
-
-            this.modFilterToggle.Label = Translation.Get("background2Window", "modsToggle");
-            this.baseFilterToggle.Label = Translation.Get("background2Window", "baseToggle");
+            if (!isModsOnly)
+            {
+                this.modFilterToggle.Label = Translation.Get("background2Window", "modsToggle");
+                this.baseFilterToggle.Label = Translation.Get("background2Window", "baseToggle");
+            }
         }
 
         public override void Draw()

+ 3 - 1
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/SceneManagerPanes/SceneManagerTitleBar.cs

@@ -23,7 +23,9 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             refreshButton = new Button(Translation.Get("sceneManager", "refreshButton"));
             refreshButton.ControlEvent += (s, a) => sceneManager.Refresh();
 
-            sortDropdown = new Dropdown(Translation.GetArray("sceneManager", sortModes));
+            sortDropdown = new Dropdown(
+                Translation.GetArray("sceneManager", sortModes), (int)sceneManager.CurrentSortMode
+            );
             sortDropdown.SelectionChange += (s, a) =>
             {
                 SceneManager.SortMode sortMode = (SceneManager.SortMode)sortDropdown.SelectedItemIndex;

+ 1 - 1
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Windows/MainWindow.cs

@@ -52,7 +52,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             ReloadTranslationButton = new Button("Reload Translation");
             ReloadTranslationButton.ControlEvent += (s, a) =>
             {
-                Translation.ReloadTranslation();
+                Translation.ReinitializeTranslation();
             };
             windowRect.width = 240f;
             windowRect.height = Screen.height * 0.9f;

+ 17 - 0
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Managers/PropManager.cs

@@ -4,6 +4,7 @@ using System.Collections.Generic;
 using System.Linq;
 using UnityEngine;
 using UnityEngine.Rendering;
+using BepInEx.Configuration;
 
 namespace COM3D2.MeidoPhotoStudio.Plugin
 {
@@ -11,6 +12,8 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
     internal class PropManager : IManager, ISerializable
     {
         public const string header = "PROP";
+        private static readonly ConfigEntry<bool> modItemsOnly;
+        public static bool ModItemsOnly => modItemsOnly.Value;
         private MeidoManager meidoManager;
         private static bool cubeActive = true;
         public static bool CubeActive
@@ -56,6 +59,15 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         public int CurrentDoguIndex { get; private set; } = 0;
         public DragPointDogu CurrentDogu => DoguCount == 0 ? null : doguList[CurrentDoguIndex];
 
+        static PropManager()
+        {
+            modItemsOnly = Configuration.Config.Bind<bool>(
+                "Prop", "ModItemsOnly",
+                false,
+                "Disable waiting for and loading base game clothing"
+            );
+        }
+
         public PropManager(MeidoManager meidoManager)
         {
             this.meidoManager = meidoManager;
@@ -537,5 +549,10 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         {
             this.DoguListChange?.Invoke(this, EventArgs.Empty);
         }
+
+        public void SaveConfiguration()
+        {
+
+        }
     }
 }

+ 28 - 2
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Managers/SceneManager.cs

@@ -3,6 +3,7 @@ using System.IO;
 using System.Collections.Generic;
 using System.Linq;
 using UnityEngine;
+using BepInEx.Configuration;
 
 namespace COM3D2.MeidoPhotoStudio.Plugin
 {
@@ -15,7 +16,12 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private int SortDirection => SortDescending ? -1 : 1;
         public static Vector2 sceneDimensions = new Vector2(480, 270);
         public bool KankyoMode { get; set; } = false;
-        public bool SortDescending { get; set; } = false;
+        private static readonly ConfigEntry<bool> sortDescending;
+        public bool SortDescending
+        {
+            get => sortDescending.Value;
+            set => sortDescending.Value = value;
+        }
         public List<Scene> SceneList { get; private set; } = new List<Scene>();
         public int CurrentDirectoryIndex { get; private set; } = -1;
         public string CurrentDirectoryName => CurrentDirectoryList[CurrentDirectoryIndex];
@@ -28,7 +34,12 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         {
             get => CurrentDirectoryIndex == 0 ? CurrentBasePath : Path.Combine(CurrentBasePath, CurrentDirectoryName);
         }
-        public SortMode CurrentSortMode { get; private set; } = SortMode.Name;
+        private static readonly ConfigEntry<SortMode> currentSortMode;
+        public SortMode CurrentSortMode
+        {
+            get => currentSortMode.Value;
+            private set => currentSortMode.Value = value;
+        }
         public int CurrentSceneIndex { get; private set; } = -1;
         public Scene CurrentScene
         {
@@ -43,6 +54,21 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             Name, DateCreated, DateModified
         }
 
+        static SceneManager()
+        {
+            sortDescending = Configuration.Config.Bind<bool>(
+                "SceneManager", "SortDescending",
+                false,
+                "Sort scenes descending (Z-A)"
+            );
+
+            currentSortMode = Configuration.Config.Bind<SortMode>(
+                "SceneManager", "SortMode",
+                SortMode.Name,
+                "Scene sorting mode"
+            );
+        }
+
         public SceneManager(MeidoPhotoStudio meidoPhotoStudio)
         {
             this.meidoPhotoStudio = meidoPhotoStudio;

+ 2 - 1
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/MeidoPhotoStudio.cs

@@ -42,7 +42,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private void Start()
         {
             Constants.Initialize();
-            Translation.Initialize(Configuration.CurrentLanguage);
+            Translation.Initialize(Translation.CurrentLanguage);
             UnityEngine.SceneManagement.SceneManager.sceneLoaded += OnSceneLoaded;
         }
 
@@ -402,6 +402,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
                         GameObject dailyPanel = GameObject.Find("UI Root")?.transform.Find("DailyPanel")?.gameObject;
                         dailyPanel?.SetActive(true);
+                        Configuration.Config.Save();
                     },
                     f_dgCancel: () =>
                     {

+ 27 - 14
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Translation.cs

@@ -3,6 +3,7 @@ using System.Linq;
 using System.IO;
 using System.Collections.Generic;
 using Newtonsoft.Json.Linq;
+using BepInEx.Configuration;
 
 namespace COM3D2.MeidoPhotoStudio.Plugin
 {
@@ -10,29 +11,45 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
     {
         private static readonly string[] props = { "ui", "props", "bg", "face" };
         private static Dictionary<string, Dictionary<string, string>> Translations;
-        public static string CurrentLanguage { get; private set; }
+        private static readonly ConfigEntry<string> currentLanguage;
+        public static string CurrentLanguage
+        {
+            get => currentLanguage.Value;
+            private set => currentLanguage.Value = value;
+        }
         public static event EventHandler ReloadTranslationEvent;
 
-        public static void Initialize(string language)
+        static Translation()
         {
-            CurrentLanguage = language;
-
-            Translations = new Dictionary<string, Dictionary<string, string>>(
-                StringComparer.InvariantCultureIgnoreCase
+            currentLanguage = Configuration.Config.Bind<string>(
+                "Translation", "Language",
+                "en",
+                "Directory to pull translations from"
+                + "\nTranslations are found in the 'Translations' folder"
             );
 
-            string rootTranslationPath = Path.Combine(Constants.configPath, Constants.translationDirectory);
+            Configuration.Config.ConfigReloaded += OnSettingChange;
+        }
 
-            string currentTranslationPath = Path.Combine(rootTranslationPath, CurrentLanguage);
+        static void OnSettingChange(object sender, EventArgs args) => ReloadTranslation();
+
+        public static void Initialize(string language)
+        {
+            string rootTranslationPath = Path.Combine(Constants.configPath, Constants.translationDirectory);
+            string currentTranslationPath = Path.Combine(rootTranslationPath, language);
 
             if (!Directory.Exists(currentTranslationPath))
             {
                 Utility.LogWarning(
-                    $"No translations found for '{CurrentLanguage}' in '{currentTranslationPath}'"
+                    $"No translations found for '{language}' in '{currentTranslationPath}'"
                 );
                 return;
             }
 
+            Translations = new Dictionary<string, Dictionary<string, string>>(
+                StringComparer.InvariantCultureIgnoreCase
+            );
+
             foreach (string prop in props)
             {
                 string translationFile = $"translation.{prop}.json";
@@ -59,11 +76,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             }
         }
 
-        public static void SetLanguage(string language)
-        {
-            Initialize(language);
-            OnReloadTranslation();
-        }
+        public static void ReinitializeTranslation() => Configuration.Config.Reload();
 
         public static void ReloadTranslation()
         {