Browse Source

Move mask change to Meido and add clothing mask

habeebweeb 4 years ago
parent
commit
ae254463bb

+ 15 - 12
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Managers/MeidoManager.cs

@@ -1,4 +1,5 @@
 using System;
+using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
@@ -11,7 +12,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         public Meido[] meidos { get; private set; }
         public List<Meido> ActiveMeidoList { get; private set; }
         public Meido ActiveMeido { get; private set; }
-        public bool HasActiveMeido { get => ActiveMeido != null; }
+        public bool HasActiveMeido => ActiveMeido != null;
         public bool IsFade { get; set; } = false;
         public int numberOfMeidos;
         public event EventHandler<MeidoChangeEventArgs> SelectMeido;
@@ -22,12 +23,10 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             get => selectedMeido;
             set
             {
-                int max = Math.Max(ActiveMeidoList.Count, 0);
-                selectedMeido = Mathf.Clamp(value, 0, max);
+                selectedMeido = Mathf.Clamp(value, 0, ActiveMeidoList.Count);
                 ActiveMeido = ActiveMeidoList.Count > 0 ? ActiveMeidoList[selectedMeido] : null;
             }
         }
-
         public bool IsBusy
         {
             get
@@ -80,6 +79,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
         private void UndressAll()
         {
+            if (!HasActiveMeido) return;
             undress = Utility.Wrap(undress + 1, 0, 3);
             TBody.MaskMode maskMode = TBody.MaskMode.None;
             switch (undress)
@@ -91,8 +91,9 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
             foreach (Meido activeMeido in ActiveMeidoList)
             {
-                activeMeido.Maid.body0.SetMaskMode(maskMode);
+                activeMeido.SetMaskMode(maskMode);
             }
+            OnSelectMeido(new MeidoChangeEventArgs(SelectedMeido));
         }
 
         public void UnloadMeidos()
@@ -131,13 +132,15 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 meido.Load(i);
             }
 
-            if (selectedMaids.Count == 0)
-            {
-                EndCallMeidos(this, EventArgs.Empty);
-                return;
-            }
-
             SelectedMeido = 0;
+            OnSelectMeido(new MeidoChangeEventArgs(SelectedMeido));
+
+            if (selectedMaids.Count == 0) EndCallMeidos(this, EventArgs.Empty);
+        }
+
+        private void OnSelectMeido(MeidoChangeEventArgs args)
+        {
+            SelectMeido?.Invoke(this, args);
         }
 
         public void SetMeidoPose(string pose, int meidoIndex = -1)
@@ -149,7 +152,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private void ChangeMeido(object sender, MeidoChangeEventArgs args)
         {
             SelectedMeido = args.selected;
-            SelectMeido?.Invoke(this, args);
+            OnSelectMeido(args);
         }
 
         private void EndCallMeidos(object sender, EventArgs args)

+ 25 - 0
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Meido/Meido.cs

@@ -1,4 +1,5 @@
 using System;
+using System.Collections;
 using System.Collections.Generic;
 using System.IO;
 using UnityEngine;
@@ -193,6 +194,30 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             morph.FixBlendValues_Face();
         }
 
+        public void SetMaskMode(TBody.MaskMode maskMode)
+        {
+            TBody body = Maid.body0;
+            bool invisibleBody = !body.GetMask(TBody.SlotID.body);
+            body.SetMaskMode(maskMode);
+            if (invisibleBody) SetBodyMask(false);
+        }
+
+        public void SetBodyMask(bool enabled)
+        {
+            TBody body = Maid.body0;
+            Hashtable table = Utility.GetFieldValue<TBody, Hashtable>(body, "m_hFoceHide");
+            foreach (TBody.SlotID bodySlot in MaidDressingPane.bodySlots)
+            {
+                table[bodySlot] = enabled;
+            }
+            if (body.goSlot[19].m_strModelFileName.Contains("melala_body"))
+            {
+                table[TBody.SlotID.accHana] = enabled;
+            }
+            body.FixMaskFlag();
+            body.FixVisibleFlag(false);
+        }
+
         private void OnBodyLoad()
         {
             BodyLoad?.Invoke(this, EventArgs.Empty);