Kaynağa Gözat

Add pose/hand/face preset reinitialization

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

+ 38 - 22
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Constants.cs

@@ -1,4 +1,4 @@
-using System;
+using System;
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
@@ -69,9 +69,9 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         public static bool MpnAttachInitialized { get; private set; }
         public static bool MenuFilesInitialized { get; private set; }
         public static event EventHandler<MenuFilesEventArgs> MenuFilesChange;
-        public static event EventHandler<CustomPoseEventArgs> CustomPoseChange;
-        public static event EventHandler<CustomPoseEventArgs> CustomHandChange;
-        public static event EventHandler<CustomPoseEventArgs> CustomFaceChange;
+        public static event EventHandler<PresetChangeEventArgs> CustomPoseChange;
+        public static event EventHandler<PresetChangeEventArgs> CustomHandChange;
+        public static event EventHandler<PresetChangeEventArgs> CustomFaceChange;
         public enum DoguCategory
         {
             Other, Mob, Desk, HandItem, BGSmall
@@ -178,7 +178,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             CustomFaceDict[category].Add(fullPath);
             CustomFaceDict[category].Sort();
 
-            CustomFaceChange?.Invoke(null, new CustomPoseEventArgs(fullPath, category));
+            CustomFaceChange?.Invoke(null, new PresetChangeEventArgs(fullPath, category));
         }
 
         public static void AddPose(byte[] anmBinary, string filename, string directory)
@@ -227,7 +227,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             CustomPoseDict[category].Add(fullPath);
             CustomPoseDict[category].Sort();
 
-            CustomPoseChange?.Invoke(null, new CustomPoseEventArgs(fullPath, category));
+            CustomPoseChange?.Invoke(null, new PresetChangeEventArgs(fullPath, category));
         }
 
         public static void AddHand(byte[] handBinary, bool right, string filename, string directory)
@@ -255,10 +255,12 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 return;
             }
 
+            int gameVersion = Misc.GAME_VERSION; // get game version from user's Assembly-CSharp
+
             XDocument finalXml = new XDocument(new XDeclaration("1.0", "utf-8", "true"),
                 new XComment("CM3D2 FingerData"),
                 new XElement("FingerData",
-                    new XElement("GameVersion", Misc.GAME_VERSION),
+                    new XElement("GameVersion", gameVersion),
                     new XElement("RightData", right),
                     new XElement("BinaryData", Convert.ToBase64String(handBinary))
                 )
@@ -283,7 +285,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             CustomHandDict[category].Add(fullPath);
             CustomHandDict[category].Sort();
 
-            CustomHandChange?.Invoke(null, new CustomPoseEventArgs(fullPath, category));
+            CustomHandChange?.Invoke(null, new PresetChangeEventArgs(fullPath, category));
         }
 
         public static void InitializeScenes()
@@ -362,6 +364,11 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 PoseGroupList.AddRange(new[] { "normal2", "ero2" });
             }
 
+            InitializeCustomPoses();
+        }
+
+        public static void InitializeCustomPoses()
+        {
             void GetPoses(string directory)
             {
                 List<string> poseList = Directory.GetFiles(directory)
@@ -375,15 +382,16 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 }
             }
 
+            CustomPoseGroupList.Clear();
+            CustomPoseDict.Clear();
+
             CustomPoseGroupList.Add(customPoseDirectory);
             CustomPoseDict[customPoseDirectory] = new List<string>();
 
             GetPoses(customPosePath);
+            foreach (string directory in Directory.GetDirectories(customPosePath)) GetPoses(directory);
 
-            foreach (string directory in Directory.GetDirectories(customPosePath))
-            {
-                GetPoses(directory);
-            }
+            CustomPoseChange?.Invoke(null, PresetChangeEventArgs.Empty);
         }
 
         public static void InitializeHandPresets()
@@ -401,15 +409,16 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 }
             }
 
+            CustomHandGroupList.Clear();
+            CustomHandDict.Clear();
+
             CustomHandGroupList.Add(customHandDirectory);
             CustomHandDict[customHandDirectory] = new List<string>();
 
             GetPresets(customHandPath);
+            foreach (string directory in Directory.GetDirectories(customHandPath)) GetPresets(directory);
 
-            foreach (string directory in Directory.GetDirectories(customHandPath))
-            {
-                GetPresets(directory);
-            }
+            CustomHandChange?.Invoke(null, PresetChangeEventArgs.Empty);
         }
 
         public static void InitializeFaceBlends()
@@ -423,6 +432,11 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 FaceDict[kvp.Key] = kvp.Value.Select(data => data.setting_name).ToList();
             }
 
+            InitializeCustomFaceBlends();
+        }
+
+        public static void InitializeCustomFaceBlends()
+        {
             void GetFacePresets(string directory)
             {
                 List<string> presetList = Directory.GetFiles(directory)
@@ -436,15 +450,16 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 }
             }
 
+            CustomFaceGroupList.Clear();
+            CustomFaceDict.Clear();
+
             CustomFaceGroupList.Add(customFaceDirectory);
             CustomFaceDict[customFaceDirectory] = new List<string>();
 
             GetFacePresets(customFacePath);
+            foreach (string directory in Directory.GetDirectories(customFacePath)) GetFacePresets(directory);
 
-            foreach (string directory in Directory.GetDirectories(customFacePath))
-            {
-                GetFacePresets(directory);
-            }
+            CustomFaceChange?.Invoke(null, PresetChangeEventArgs.Empty);
         }
 
         public static void InitializeBGs()
@@ -933,11 +948,12 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         public MenuFilesEventArgs(EventType type) => Type = type;
     }
 
-    public class CustomPoseEventArgs : EventArgs
+    public class PresetChangeEventArgs : EventArgs
     {
         public string Category { get; }
         public string Path { get; }
-        public CustomPoseEventArgs(string path, string category)
+        public static new PresetChangeEventArgs Empty { get; } = new PresetChangeEventArgs(string.Empty, string.Empty);
+        public PresetChangeEventArgs(string path, string category)
         {
             Path = path;
             Category = category;

+ 15 - 2
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/FaceWindowPanes/MaidFaceBlendPane.cs

@@ -29,7 +29,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
         public MaidFaceBlendPane(MeidoManager meidoManager)
         {
-            Constants.CustomFaceChange += SaveFaceEnd;
+            Constants.CustomFaceChange += OnPresetChange;
             this.meidoManager = meidoManager;
 
             faceBlendSourceGrid = new SelectionGrid(Translation.GetArray("maidFaceWindow", tabTranslations));
@@ -132,8 +132,20 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 ).ToArray();
         }
 
-        private void SaveFaceEnd(object sender, CustomPoseEventArgs args)
+        private void OnPresetChange(object sender, PresetChangeEventArgs args)
         {
+            if (args == PresetChangeEventArgs.Empty)
+            {
+                if (facePresetMode)
+                {
+                    updating = true;
+                    faceBlendCategoryDropdown.SetDropdownItems(CurrentFaceGroupList.ToArray(), 0);
+                    faceBlendDropdown.SetDropdownItems(UIFaceList(), 0);
+                    updating = false;
+                }
+            }
+            else
+            {
                 updating = true;
                 faceBlendSourceGrid.SelectedItemIndex = 1;
                 faceBlendCategoryDropdown.SetDropdownItems(
@@ -141,6 +153,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 );
                 updating = false;
                 faceBlendDropdown.SetDropdownItems(UIFaceList(), CurrentFaceList.IndexOf(args.Path));
+            }
         }
     }
 }

+ 15 - 7
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/PoseWindowPanes/HandPresetPane.cs

@@ -24,7 +24,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
         public HandPresetPane(MeidoManager meidoManager)
         {
-            Constants.CustomHandChange += SaveHandEnd;
+            Constants.CustomHandChange += OnPresetChange;
             this.meidoManager = meidoManager;
 
             presetCategoryDropdown = new Dropdown(Constants.CustomHandGroupList.ToArray());
@@ -108,19 +108,27 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             meidoManager.ActiveMeido.SetHandPreset(CurrentPreset, right);
         }
 
-        private void SaveHandEnd(object sender, CustomPoseEventArgs args)
+        private void OnPresetChange(object sender, PresetChangeEventArgs args)
         {
-            presetCategoryDropdown.SetDropdownItems(
-                Constants.CustomHandGroupList.ToArray(), Constants.CustomHandGroupList.IndexOf(args.Category)
-            );
-            presetDropdown.SetDropdownItems(UIPresetList(), CurrentPresetList.IndexOf(args.Path));
+            if (args == PresetChangeEventArgs.Empty)
+            {
+                presetCategoryDropdown.SetDropdownItems(Constants.CustomHandGroupList.ToArray(), 0);
+                presetDropdown.SetDropdownItems(UIPresetList(), 0);
+            }
+            else
+            {
+                presetCategoryDropdown.SetDropdownItems(
+                    Constants.CustomHandGroupList.ToArray(), Constants.CustomHandGroupList.IndexOf(args.Category)
+                );
+                presetDropdown.SetDropdownItems(UIPresetList(), CurrentPresetList.IndexOf(args.Path));
+            }
         }
 
         private string[] UIPresetList()
         {
             return CurrentPresetList.Count == 0
                 ? new[] { Translation.Get("handPane", "noPresetsMessage") }
-                : CurrentPresetList.Select(file => Path.GetFileNameWithoutExtension(file)).ToArray();
+                : CurrentPresetList.Select(Path.GetFileNameWithoutExtension).ToArray();
         }
     }
 }

+ 23 - 10
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/PoseWindowPanes/MaidPoseSelectorPane.cs

@@ -31,7 +31,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
         public MaidPoseSelectorPane(MeidoManager meidoManager)
         {
-            Constants.CustomPoseChange += SavePoseEnd;
+            Constants.CustomPoseChange += OnPresetChange;
             this.meidoManager = meidoManager;
 
             poseModeGrid = new SelectionGrid(Translation.GetArray("posePane", tabTranslations));
@@ -141,17 +141,30 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             updating = false;
         }
 
-        private void SavePoseEnd(object sender, CustomPoseEventArgs args)
+        private void OnPresetChange(object sender, PresetChangeEventArgs args)
         {
-            updating = true;
-            poseModeGrid.SelectedItemIndex = 1;
-            poseGroupDropdown.SetDropdownItems(
-                CurrentPoseGroupList.ToArray(), CurrentPoseGroupList.IndexOf(args.Category)
-            );
-            updating = false;
+            if (args == PresetChangeEventArgs.Empty)
+            {
+                if (poseModeGrid.SelectedItemIndex == 1)
+                {
+                    updating = true;
+                    poseGroupDropdown.SetDropdownItems(CurrentPoseGroupList.ToArray(), 0);
+                    poseDropdown.SetDropdownItems(UIPoseList(), 0);
+                    updating = false;
+                }
+            }
+            else
+            {
+                updating = true;
+                poseModeGrid.SelectedItemIndex = 1;
+                poseGroupDropdown.SetDropdownItems(
+                    CurrentPoseGroupList.ToArray(), CurrentPoseGroupList.IndexOf(args.Category)
+                );
+                updating = false;
 
-            poseDropdown.SetDropdownItems(UIPoseList(), CurrentPoseDict[args.Category].IndexOf(args.Path));
-            poseListEnabled = true;
+                poseDropdown.SetDropdownItems(UIPoseList(), CurrentPoseList.IndexOf(args.Path));
+                poseListEnabled = true;
+            }
         }
 
         private void SetPoseMode()