Procházet zdrojové kódy

Fix face window doing nothing for gp01fb faces

Long overdue but it's not like anyone's busy making scenes with
MeidoPhotoStudio anyway.
habeebweeb před 4 roky
rodič
revize
bc23a9efef

+ 70 - 74
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/FaceWindowPanes/MaidFaceSliderPane.cs

@@ -3,10 +3,9 @@ using UnityEngine;
 
 namespace COM3D2.MeidoPhotoStudio.Plugin
 {
+    using static Meido;
     internal class MaidFaceSliderPane : BasePane
     {
-        private MeidoManager meidoManager;
-
         // TODO: Consider placing in external file to be user editable
         private static readonly Dictionary<string, float[]> SliderRange = new Dictionary<string, float[]>()
         {
@@ -59,44 +58,30 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             // Tongue Base
             ["tangopen"] = new[] { 0f, 1f }
         };
-
-        public static readonly string[] faceKeys = new string[24]
-        {
-            "eyeclose", "eyeclose2", "eyeclose3", "eyebig", "eyeclose6", "eyeclose5", "hitomih",
-            "hitomis", "mayuha", "mayuw", "mayuup", "mayuv", "mayuvhalf", "moutha", "mouths",
-            "mouthc", "mouthi", "mouthup", "mouthdw", "mouthhe", "mouthuphalf", "tangout",
-            "tangup", "tangopen"
-        };
-
-        public static readonly string[] faceToggleKeys = new string[12]
-        {
-            // blush, shade, nose up, tears, drool, teeth
-            "hoho2", "shock", "nosefook", "namida", "yodare", "toothoff",
-            // cry 1, cry 2, cry 3, blush 1, blush 2, blush 3
-            "tear1", "tear2", "tear3", "hohos", "hoho", "hohol"
-        };
+        private MeidoManager meidoManager;
+        private Dictionary<string, BaseControl> faceControls;
 
         public MaidFaceSliderPane(MeidoManager meidoManager)
         {
             this.meidoManager = meidoManager;
+            this.faceControls = new Dictionary<string, BaseControl>();
 
-            for (int i = 0; i < faceKeys.Length; i++)
+            foreach (string key in faceKeys)
             {
-                string key = faceKeys[i];
                 string uiName = Translation.Get("faceBlendValues", key);
                 Slider slider = new Slider(uiName, SliderRange[key][0], SliderRange[key][1]);
-                int myIndex = i;
-                slider.ControlEvent += (s, a) => this.SetFaceValue(faceKeys[myIndex], slider.Value);
-                this.Controls.Add(slider);
+                string myKey = key;
+                slider.ControlEvent += (s, a) => this.SetFaceValue(myKey, slider.Value);
+                faceControls[key] = slider;
             }
 
-            for (int i = 0; i < faceToggleKeys.Length; i++)
+            foreach (string key in faceToggleKeys)
             {
-                string uiName = Translation.Get("faceBlendValues", faceToggleKeys[i]);
+                string uiName = Translation.Get("faceBlendValues", key);
                 Toggle toggle = new Toggle(uiName);
-                int myIndex = i;
-                toggle.ControlEvent += (s, a) => this.SetFaceValue(faceToggleKeys[myIndex], toggle.Value);
-                this.Controls.Add(toggle);
+                string myKey = key;
+                toggle.ControlEvent += (s, a) => this.SetFaceValue(myKey, toggle.Value);
+                faceControls[key] = toggle;
             }
         }
 
@@ -104,43 +89,32 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         {
             for (int i = 0; i < faceKeys.Length; i++)
             {
-                Slider slider = (Slider)Controls[i];
+                Slider slider = (Slider)faceControls[faceKeys[i]];
                 slider.Label = Translation.Get("faceBlendValues", faceKeys[i]);
             }
 
-            for (int i = faceKeys.Length; i < faceKeys.Length + faceToggleKeys.Length; i++)
+            for (int i = 0; i < faceToggleKeys.Length; i++)
             {
-                Toggle toggle = (Toggle)Controls[i];
-                toggle.Label = Translation.Get("faceBlendValues", faceToggleKeys[i - faceKeys.Length]);
+                Toggle toggle = (Toggle)faceControls[faceToggleKeys[i]];
+                toggle.Label = Translation.Get("faceBlendValues", faceToggleKeys[i]);
             }
         }
 
-        public void SetFaceValue(string key, float value)
-        {
-            if (updating) return;
-            this.meidoManager.ActiveMeido.SetFaceBlendValue(key, value);
-        }
-
-        public void SetFaceValue(string key, bool value)
-        {
-            float max = (key == "hoho" || key == "hoho2") ? 0.5f : 1f;
-            if (key == "toothoff") value = !value;
-            SetFaceValue(key, value ? max : 0f);
-        }
-
         public override void UpdatePane()
         {
             this.updating = true;
             TMorph morph = this.meidoManager.ActiveMeido.Maid.body0.Face.morph;
-            float[] blendValues = Utility.GetFieldValue<TMorph, float[]>(morph, "BlendValues");
-            float[] blendValuesBackup = Utility.GetFieldValue<TMorph, float[]>(morph, "BlendValuesBackup");
+            bool gp01FBFace = morph.bodyskin.PartsVersion >= 120;
+            float[] blendValues = this.meidoManager.ActiveMeido.BlendValues;
+            float[] blendValuesBackup = this.meidoManager.ActiveMeido.BlendValuesBackup;
             for (int i = 0; i < faceKeys.Length; i++)
             {
                 string hash = faceKeys[i];
-                Slider slider = this.Controls[i] as Slider;
+                Slider slider = (Slider)faceControls[hash];
                 try
                 {
-                    if (hash.StartsWith("eyeclose"))
+                    hash = Utility.GP01FbFaceHash(morph, hash);
+                    if (hash.StartsWith("eyeclose") && !(gp01FBFace && (hash == "eyeclose3")))
                         slider.Value = blendValuesBackup[(int)morph.hash[hash]];
                     else
                         slider.Value = blendValues[(int)morph.hash[hash]];
@@ -151,7 +125,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             for (int i = 0; i < faceToggleKeys.Length; i++)
             {
                 string hash = faceToggleKeys[i];
-                Toggle toggle = this.Controls[24 + i] as Toggle;
+                Toggle toggle = (Toggle)faceControls[hash];
                 if (hash == "nosefook") toggle.Value = morph.boNoseFook;
                 else toggle.Value = blendValues[(int)morph.hash[hash]] > 0f;
                 if (hash == "toothoff") toggle.Value = !toggle.Value;
@@ -162,36 +136,58 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         public override void Draw()
         {
             GUI.enabled = this.meidoManager.HasActiveMeido;
-            GUILayoutOption sliderWidth = MiscGUI.HalfSlider;
-            for (int i = 0; i < faceKeys.Length; i += 2)
-            {
-                GUILayout.BeginHorizontal();
-                for (int j = 0; j < 2; j++)
-                {
-                    Controls[i + j].Draw(sliderWidth);
-                    if (i + j == 12 || i + j == 23)
-                    {
-                        i--;
-                        break;
-                    }
+            DrawSliders("eyeclose", "eyeclose2");
+            DrawSliders("eyeclose3", "eyebig");
+            DrawSliders("eyeclose6", "eyeclose5");
+            DrawSliders("hitomih", "hitomis");
+            DrawSliders("mayuha", "mayuw");
+            DrawSliders("mayuup", "mayuv");
+            DrawSliders("mayuvhalf");
+            DrawSliders("moutha", "mouths");
+            DrawSliders("mouthc", "mouthi");
+            DrawSliders("mouthup", "mouthdw");
+            DrawSliders("mouthhe", "mouthuphalf");
+            DrawSliders("tangout", "tangup");
+            DrawSliders("tangopen");
+            MiscGUI.WhiteLine();
+            DrawToggles("hoho2", "shock", "nosefook");
+            DrawToggles("namida", "yodare", "toothoff");
+            DrawToggles("tear1", "tear2", "tear3");
+            DrawToggles("hohos", "hoho", "hohol");
+            GUI.enabled = true;
+        }
 
-                }
-                GUILayout.EndHorizontal();
+        private void DrawSliders(params string[] keys)
+        {
+            GUILayout.BeginHorizontal();
+            foreach (string key in keys)
+            {
+                ((Slider)faceControls[key]).Draw(MiscGUI.HalfSlider);
             }
+            GUILayout.EndHorizontal();
+        }
 
-            MiscGUI.WhiteLine();
-
-            for (int i = 0; i < faceToggleKeys.Length; i += 3)
+        private void DrawToggles(params string[] keys)
+        {
+            GUILayout.BeginHorizontal();
+            foreach (string key in keys)
             {
-                GUILayout.BeginHorizontal();
-                for (int j = 0; j < 3; j++)
-                {
-                    Controls[24 + i + j].Draw();
-                }
-                GUILayout.EndHorizontal();
+                ((Toggle)faceControls[key]).Draw();
             }
+            GUILayout.EndHorizontal();
+        }
 
-            GUI.enabled = true;
+        private void SetFaceValue(string key, float value)
+        {
+            if (updating) return;
+            this.meidoManager.ActiveMeido.SetFaceBlendValue(key, value);
+        }
+
+        private void SetFaceValue(string key, bool value)
+        {
+            float max = (key == "hoho" || key == "hoho2") ? 0.5f : 1f;
+            if (key == "toothoff") value = !value;
+            SetFaceValue(key, value ? max : 0f);
         }
     }
 }

+ 34 - 4
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Meido/Meido.cs

@@ -11,9 +11,26 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private const int MAX_MAIDS = 12;
         private static CharacterMgr characterMgr = GameMain.Instance.CharacterMgr;
         public readonly int stockNo;
+        public static readonly string[] faceKeys = new string[24]
+        {
+            "eyeclose", "eyeclose2", "eyeclose3", "eyebig", "eyeclose6", "eyeclose5", "hitomih",
+            "hitomis", "mayuha", "mayuw", "mayuup", "mayuv", "mayuvhalf", "moutha", "mouths",
+            "mouthc", "mouthi", "mouthup", "mouthdw", "mouthhe", "mouthuphalf", "tangout",
+            "tangup", "tangopen"
+        };
+
+        public static readonly string[] faceToggleKeys = new string[12]
+        {
+            // blush, shade, nose up, tears, drool, teeth
+            "hoho2", "shock", "nosefook", "namida", "yodare", "toothoff",
+            // cry 1, cry 2, cry 3, blush 1, blush 2, blush 3
+            "tear1", "tear2", "tear3", "hohos", "hoho", "hohol"
+        };
         public static readonly PoseInfo defaultPose
             = new PoseInfo(Constants.PoseGroupList[0], Constants.PoseDict[Constants.PoseGroupList[0]][0]);
         public static readonly string defaultFaceBlendSet = "通常";
+        private MeidoDragPointManager dragPointManager;
+        private bool initialized = false;
         public Maid Maid { get; private set; }
         public Texture2D Image { get; private set; }
         public string FirstName { get; private set; }
@@ -21,10 +38,11 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         public string NameJP => $"{LastName}\n{FirstName}";
         public string NameEN => $"{FirstName}\n{LastName}";
         public int ActiveSlot { get; private set; }
-        private MeidoDragPointManager dragPointManager;
         public event EventHandler<MeidoUpdateEventArgs> UpdateMeido;
         public event EventHandler BodyLoad;
         private bool isLoading = false;
+        public float[] BlendValuesBackup { get; private set; }
+        public float[] BlendValues { get; private set; }
         public bool IsIK
         {
             get => dragPointManager?.Active ?? false;
@@ -302,9 +320,12 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             }
             else
             {
-                float[] blendValues = hash.StartsWith("eyeclose")
-                    ? Utility.GetFieldValue<TMorph, float[]>(morph, "BlendValuesBackup")
-                    : Utility.GetFieldValue<TMorph, float[]>(morph, "BlendValues");
+                bool gp01FBFace = morph.bodyskin.PartsVersion >= 120;
+                float[] blendValues = hash.StartsWith("eyeclose") && !(gp01FBFace && (hash == "eyeclose3"))
+                    ? this.BlendValuesBackup
+                    : this.BlendValues;
+
+                hash = Utility.GP01FbFaceHash(morph, hash);
 
                 try
                 {
@@ -347,6 +368,15 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         {
             BodyLoad?.Invoke(this, EventArgs.Empty);
 
+            if (!initialized)
+            {
+                TMorph morph = Maid.body0.Face.morph;
+                this.BlendValuesBackup = Utility.GetFieldValue<TMorph, float[]>(morph, "BlendValuesBackup");
+                this.BlendValues = Utility.GetFieldValue<TMorph, float[]>(morph, "BlendValues");
+
+                initialized = true;
+            }
+
             this.IsIK = true;
             this.IsStop = false;
             this.IsBone = false;

+ 10 - 0
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Utility.cs

@@ -119,5 +119,15 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             path = string.Join("_", path.Split(invalid)).Replace(".", "").Trim('_');
             return path;
         }
+
+        public static string GP01FbFaceHash(TMorph face, string hash)
+        {
+            if ((face.bodyskin.PartsVersion >= 120) && (hash != "eyeclose3") && hash.StartsWith("eyeclose"))
+            {
+                if (hash == "eyeclose") hash += '1';
+                hash += TMorph.crcFaceTypesStr[(int)face.GetFaceTypeGP01FB()];
+            }
+            return hash;
+        }
     }
 }