Pārlūkot izejas kodu

Separate base game poses from custom poses

habeebweeb 4 gadi atpakaļ
vecāks
revīzija
f7f6652fbd

+ 12 - 21
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Constants.cs

@@ -32,8 +32,10 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         }
         public static readonly List<string> PoseGroupList = new List<string>();
         public static readonly Dictionary<string, List<string>> PoseDict = new Dictionary<string, List<string>>();
-        public static readonly Dictionary<string, List<KeyValuePair<string, string>>> CustomPoseDict
-            = new Dictionary<string, List<KeyValuePair<string, string>>>();
+        public static readonly List<string> CustomPoseGroupList = new List<string>();
+        public static readonly Dictionary<string, List<string>> CustomPoseDict = new Dictionary<string, List<string>>();
+        // public static readonly Dictionary<string, List<KeyValuePair<string, string>>> CustomPoseDict
+        //     = new Dictionary<string, List<KeyValuePair<string, string>>>();
         public static readonly List<string> FaceBlendList = new List<string>();
         public static readonly List<string> BGList = new List<string>();
         public static readonly List<KeyValuePair<string, string>> MyRoomCustomBGList
@@ -108,12 +110,9 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             if (com3d2MotionList != null && com3d2MotionList.Length > 0)
             {
                 HashSet<string> poseSet = new HashSet<string>();
-                foreach (KeyValuePair<string, List<string>> poses in PoseDict)
+                foreach (List<string> poses in PoseDict.Values)
                 {
-                    foreach (string pose in poses.Value)
-                    {
-                        poseSet.Add(pose);
-                    }
+                    poseSet.UnionWith(poses);
                 }
 
                 List<string> editPoseList = new List<string>();
@@ -140,8 +139,8 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                                 && !file.Contains("_man_")
                             )
                             {
-                                if (!path.Contains(@"\sex\")) otherPoseList.Add(file);
-                                else eroPoseList.Add(file);
+                                if (path.Contains(@"\sex\")) eroPoseList.Add(file);
+                                else otherPoseList.Add(file);
                             }
                         }
                     }
@@ -153,23 +152,15 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 PoseGroupList.AddRange(new[] { "normal2", "ero2" });
             }
 
-            CustomPoseGroupsIndex = PoseGroupList.Count;
-
             Action<string> GetPoses = directory =>
             {
-                List<KeyValuePair<string, string>> poseList = new List<KeyValuePair<string, string>>();
-                foreach (string file in Directory.GetFiles(directory))
-                {
-                    if (Path.GetExtension(file) == ".anm")
-                    {
-                        string fileName = Path.GetFileNameWithoutExtension(file);
-                        poseList.Add(new KeyValuePair<string, string>(fileName, file));
-                    }
-                }
+                List<string> poseList = Directory.GetFiles(directory)
+                    .Where(file => Path.GetExtension(file) == ".anm").ToList();
+
                 if (poseList.Count > 0)
                 {
                     string poseGroupName = new DirectoryInfo(directory).Name;
-                    PoseGroupList.Add(poseGroupName);
+                    CustomPoseGroupList.Add(poseGroupName);
                     CustomPoseDict[poseGroupName] = poseList;
                 }
             };

+ 105 - 92
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/PoseWindowPanes/MaidPoseSelectorPane.cs

@@ -1,4 +1,5 @@
 using System;
+using System.IO;
 using System.Collections.Generic;
 using System.Linq;
 using UnityEngine;
@@ -14,29 +15,35 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private Button poseGroupRightButton;
         private Dropdown poseGroupDropdown;
         private Dropdown poseDropdown;
-        private string selectedPoseGroup;
-        private int selectedPose;
+        private SelectionGrid poseModeGrid;
+        private bool customPoseMode = false;
+        private Dictionary<string, List<string>> CurrentPoseDict
+        {
+            get => customPoseMode ? Constants.CustomPoseDict : Constants.PoseDict;
+        }
+        private List<string> CurrentPoseGroupList
+        {
+            get => customPoseMode ? Constants.CustomPoseGroupList : Constants.PoseGroupList;
+        }
+        private string SelectedPoseGroup => CurrentPoseGroupList[poseGroupDropdown.SelectedItemIndex];
+        private List<string> CurrentPoseList => CurrentPoseDict[SelectedPoseGroup];
+        private int SelectedPoseIndex => poseDropdown.SelectedItemIndex;
+        private string SelectedPose => CurrentPoseList[SelectedPoseIndex];
+        private PoseInfo CurrentPoseInfo => new PoseInfo(SelectedPoseGroup, SelectedPose, customPoseMode);
+        private string previousPoseGroup;
 
         public MaidPoseSelectorPane(MeidoManager meidoManager)
         {
             this.meidoManager = meidoManager;
 
-            List<string> poseGroups = new List<string>(Constants.PoseGroupList.Count);
+            this.poseModeGrid = new SelectionGrid(new[] { "Base", "Custom" });
+            this.poseModeGrid.ControlEvent += (s, a) => SetPoseMode();
 
-            for (int i = 0; i < Constants.PoseGroupList.Count; i++)
-            {
-                string poseGroup = Constants.PoseGroupList[i];
-                poseGroups.Add(i < Constants.CustomPoseGroupsIndex
-                    ? Translation.Get("poseGroupDropdown", poseGroup)
-                    : poseGroup
-                );
-            }
-
-            this.poseGroupDropdown = new Dropdown(poseGroups.ToArray());
-            this.poseGroupDropdown.SelectionChange += ChangePoseGroup;
+            this.poseGroupDropdown = new Dropdown(Translation.GetArray("poseGroupDropdown", Constants.PoseGroupList));
+            this.poseGroupDropdown.SelectionChange += (s, a) => ChangePoseGroup();
 
-            this.poseDropdown = new Dropdown(MakePoseList(Constants.PoseDict[Constants.PoseGroupList[0]]));
-            this.poseDropdown.SelectionChange += ChangePose;
+            this.poseDropdown = new Dropdown(UIPoseList(Constants.PoseDict[Constants.PoseGroupList[0]]));
+            this.poseDropdown.SelectionChange += (s, a) => ChangePose();
 
             this.poseGroupLeftButton = new Button("<");
             this.poseGroupLeftButton.ControlEvent += (s, a) => poseGroupDropdown.Step(-1);
@@ -50,93 +57,22 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             this.poseRightButton = new Button(">");
             this.poseRightButton.ControlEvent += (s, a) => poseDropdown.Step(1);
 
-            selectedPoseGroup = Constants.PoseGroupList[this.poseGroupDropdown.SelectedItemIndex];
+            previousPoseGroup = SelectedPoseGroup;
         }
 
         protected override void ReloadTranslation()
         {
-            List<string> poseGroups = new List<string>(Constants.PoseGroupList.Count);
-
-            for (int i = 0; i < Constants.PoseGroupList.Count; i++)
+            if (!customPoseMode)
             {
-                string poseGroup = Constants.PoseGroupList[i];
-                poseGroups.Add(i < Constants.CustomPoseGroupsIndex
-                    ? Translation.Get("poseGroupDropdown", poseGroup)
-                    : poseGroup
+                this.poseGroupDropdown.SetDropdownItems(
+                    Translation.GetArray("poseGroupDropdown", Constants.PoseGroupList)
                 );
             }
-
-            updating = true;
-            this.poseGroupDropdown.SetDropdownItems(poseGroups.ToArray());
-            updating = false;
-        }
-
-        private void ChangePoseGroup(object sender, EventArgs args)
-        {
-            string newPoseGroup = Constants.PoseGroupList[this.poseGroupDropdown.SelectedItemIndex];
-            if (selectedPoseGroup == newPoseGroup)
-            {
-                this.poseDropdown.SelectedItemIndex = 0;
-            }
-            else
-            {
-                selectedPoseGroup = newPoseGroup;
-                if (this.poseGroupDropdown.SelectedItemIndex >= Constants.CustomPoseGroupsIndex)
-                {
-                    this.poseDropdown.SetDropdownItems(MakePoseList(Constants.CustomPoseDict[selectedPoseGroup]), 0);
-                }
-                else
-                {
-                    this.poseDropdown.SetDropdownItems(MakePoseList(Constants.PoseDict[selectedPoseGroup]), 0);
-                }
-            }
-        }
-
-        private void ChangePose(object sender, EventArgs args)
-        {
-            selectedPose = poseDropdown.SelectedItemIndex;
-
-            if (updating) return;
-            PoseInfo poseInfo = MakePoseInfo();
-            meidoManager.ActiveMeido.SetPose(poseInfo);
-        }
-
-        private PoseInfo MakePoseInfo()
-        {
-            int poseGroup = this.poseGroupDropdown.SelectedItemIndex;
-            int pose = this.poseDropdown.SelectedItemIndex;
-
-            string poseName;
-            if (this.poseGroupDropdown.SelectedItemIndex >= Constants.CustomPoseGroupsIndex)
-                poseName = Constants.CustomPoseDict[selectedPoseGroup][selectedPose].Value;
-            else
-                poseName = Constants.PoseDict[selectedPoseGroup][selectedPose];
-
-            return new PoseInfo(poseGroup, pose, poseName);
-        }
-
-        private string[] MakePoseList(IEnumerable<string> poseList)
-        {
-            return poseList.Select((pose, i) => $"{i + 1}:{pose}").ToArray();
-        }
-
-        private string[] MakePoseList(List<KeyValuePair<string, string>> poseList)
-        {
-            return poseList.Select((kvp, i) => $"{i + 1}:{kvp.Key}").ToArray();
-        }
-
-        public override void UpdatePane()
-        {
-            this.updating = true;
-            PoseInfo poseInfo = this.meidoManager.ActiveMeido.CachedPose;
-            this.poseGroupDropdown.SelectedItemIndex = poseInfo.PoseGroupIndex;
-            this.poseDropdown.SelectedItemIndex = poseInfo.PoseIndex;
-            this.updating = false;
         }
 
         public override void Draw()
         {
-            float arrowButtonSize = 30;
+            float arrowButtonSize = 30f;
             GUILayoutOption[] arrowLayoutOptions = {
                 GUILayout.Width(arrowButtonSize),
                 GUILayout.Height(arrowButtonSize)
@@ -151,6 +87,9 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
             GUI.enabled = meidoManager.HasActiveMeido && !meidoManager.ActiveMeido.IsStop;
 
+            this.poseModeGrid.Draw();
+            MiscGUI.WhiteLine();
+
             GUILayout.BeginHorizontal();
             this.poseGroupLeftButton.Draw(arrowLayoutOptions);
             this.poseGroupDropdown.Draw(dropdownLayoutOptions);
@@ -162,6 +101,80 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             this.poseDropdown.Draw(dropdownLayoutOptions);
             this.poseRightButton.Draw(arrowLayoutOptions);
             GUILayout.EndHorizontal();
+
+            GUI.enabled = true;
+        }
+
+        public override void UpdatePane()
+        {
+            this.updating = true;
+
+            PoseInfo poseInfo = this.meidoManager.ActiveMeido.CachedPose;
+
+            bool oldPoseMode = customPoseMode;
+
+            poseModeGrid.SelectedItemIndex = poseInfo.CustomPose ? 1 : 0;
+
+            int poseGroupIndex = CurrentPoseGroupList.IndexOf(poseInfo.PoseGroup);
+
+            if (poseGroupIndex < 0) poseGroupIndex = 0;
+
+            int poseIndex = CurrentPoseDict[poseInfo.PoseGroup].IndexOf(poseInfo.Pose);
+
+            if (poseIndex < 0) poseIndex = 0;
+
+            if (oldPoseMode != customPoseMode)
+            {
+                string[] list = customPoseMode
+                    ? CurrentPoseGroupList.ToArray()
+                    : Translation.GetArray("poseGroupDropdown", CurrentPoseGroupList);
+
+                this.poseGroupDropdown.SetDropdownItems(list);
+            }
+
+            this.poseGroupDropdown.SelectedItemIndex = poseGroupIndex;
+            this.poseDropdown.SelectedItemIndex = poseIndex;
+
+            this.updating = false;
+        }
+
+        private void SetPoseMode()
+        {
+            customPoseMode = poseModeGrid.SelectedItemIndex == 1;
+
+            if (this.updating) return;
+
+            string[] list = customPoseMode
+                ? CurrentPoseGroupList.ToArray()
+                : Translation.GetArray("poseGroupDropdown", CurrentPoseGroupList);
+            this.poseGroupDropdown.SetDropdownItems(list, 0);
+        }
+
+        private void ChangePoseGroup()
+        {
+            if (previousPoseGroup == SelectedPoseGroup)
+            {
+                this.poseDropdown.SelectedItemIndex = 0;
+            }
+            else
+            {
+                previousPoseGroup = SelectedPoseGroup;
+                this.poseDropdown.SetDropdownItems(UIPoseList(CurrentPoseList), 0);
+            }
+        }
+
+        private void ChangePose()
+        {
+            if (updating) return;
+            meidoManager.ActiveMeido.SetPose(CurrentPoseInfo);
+        }
+
+        private string[] UIPoseList(IEnumerable<string> poseList)
+        {
+            return poseList.Select((pose, i) =>
+            {
+                return $"{i + 1}:{(customPoseMode ? Path.GetFileNameWithoutExtension(pose) : pose)}";
+            }).ToArray();
         }
     }
 }

+ 12 - 14
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Meido/Meido.cs

@@ -11,7 +11,8 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private const int MAX_MAIDS = 12;
         private static CharacterMgr characterMgr = GameMain.Instance.CharacterMgr;
         public readonly int stockNo;
-        public static readonly PoseInfo defaultPose = new PoseInfo(0, 0, "pose_taiki_f");
+        public static readonly PoseInfo defaultPose
+            = new PoseInfo(Constants.PoseGroupList[0], Constants.PoseDict[Constants.PoseGroupList[0]][0]);
         public static readonly string defaultFaceBlendSet = "通常";
         public Maid Maid { get; private set; }
         public Texture2D Image { get; private set; }
@@ -46,7 +47,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 else
                 {
                     if (value) Maid.GetAnimation().Stop();
-                    else this.SetPose(this.CachedPose.PoseName);
+                    else this.SetPose(this.CachedPose.Pose);
                     OnUpdateMeido();
                 }
             }
@@ -178,7 +179,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         public void SetPose(PoseInfo poseInfo)
         {
             this.CachedPose = poseInfo;
-            SetPose(poseInfo.PoseName);
+            SetPose(poseInfo.Pose);
         }
 
         public void SetPose(string pose)
@@ -218,7 +219,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
         public void SetMune(bool drag = false)
         {
-            bool isMomiOrPaizuri = CachedPose.PoseName.Contains("_momi") || CachedPose.PoseName.Contains("paizuri_");
+            bool isMomiOrPaizuri = CachedPose.Pose.Contains("_momi") || CachedPose.Pose.Contains("paizuri_");
             float onL = (drag || isMomiOrPaizuri) ? 0f : 1f;
             Maid.body0.MuneYureL(onL);
             Maid.body0.MuneYureR(onL);
@@ -310,17 +311,14 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
     public struct PoseInfo
     {
-        public int PoseGroupIndex { get; }
-        public int PoseIndex { get; }
-        public string PoseName { get; }
-        public bool IsCustomPose { get; }
-        public PoseInfo(int poseGroup, int pose, string poseName, bool isCustomPose = false)
+        public string PoseGroup { get; }
+        public string Pose { get; }
+        public bool CustomPose { get; }
+        public PoseInfo(string poseGroup, string pose, bool customPose = false)
         {
-            this.PoseGroupIndex = poseGroup;
-            this.PoseIndex = pose;
-            this.PoseName = poseName;
-            this.IsCustomPose = isCustomPose;
+            this.PoseGroup = poseGroup;
+            this.Pose = pose;
+            this.CustomPose = customPose;
         }
-        public override string ToString() => $"pose group: {PoseGroupIndex}, pose index: {PoseIndex}, pose name: {PoseName}, is custom: {IsCustomPose}";
     }
 }