Browse Source

Add pose copying

habeebweeb 4 years ago
parent
commit
22572a18e1

+ 2 - 3
COM3D2.MeidoPhotoStudio.Plugin/Config/MeidoPhotoStudio/Translations/en/translation.ui.json

@@ -115,9 +115,8 @@
         "rightHand": "R Hand",
         "leftHand": "L Hand"
     },
-    "copyIK": {
-        "copyLabel": "copy",
-        "copyButton": "OK"
+    "copyPosePane": {
+        "copyButton": "Copy"
     },
     "voiceLines": {
         "speak": "Speak",

+ 10 - 4
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/MainWindowPanes/PoseWindowPane.cs

@@ -14,6 +14,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private MaidSwitcherPane maidSwitcherPane;
         private MaidFaceLookPane maidFaceLookPane;
         private MaidDressingPane maidDressingPane;
+        private CopyPosePane copyPosePane;
         private MaidIKPane maidIKPane;
         private Toggle freeLookToggle;
         private Toggle savePoseToggle;
@@ -30,15 +31,17 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             this.maidFaceLookPane = new MaidFaceLookPane(meidoManager);
             this.maidFaceLookPane.Enabled = false;
 
-            this.maidDressingPane = new MaidDressingPane(meidoManager);
-
-            this.maidIKPane = new MaidIKPane(meidoManager);
-
             this.freeLookToggle = new Toggle(Translation.Get("freeLook", "freeLookToggle"), false);
             this.freeLookToggle.ControlEvent += (s, a) => SetMaidFreeLook();
 
             this.savePoseToggle = new Toggle(Translation.Get("posePane", "saveToggle"));
             this.savePoseToggle.ControlEvent += (s, a) => savePoseMode = !savePoseMode;
+
+            this.maidDressingPane = new MaidDressingPane(meidoManager);
+
+            this.maidIKPane = new MaidIKPane(meidoManager);
+
+            this.copyPosePane = new CopyPosePane(meidoManager);
         }
 
         protected override void ReloadTranslation()
@@ -69,6 +72,8 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
             maidIKPane.Draw();
 
+            copyPosePane.Draw();
+
             GUILayout.EndScrollView();
         }
 
@@ -91,6 +96,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 maidFaceLookPane.UpdatePane();
                 maidDressingPane.UpdatePane();
                 maidIKPane.UpdatePane();
+                copyPosePane.UpdatePane();
             }
         }
 

+ 81 - 0
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/PoseWindowPanes/CopyPosePane.cs

@@ -0,0 +1,81 @@
+using System;
+using System.Linq;
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace COM3D2.MeidoPhotoStudio.Plugin
+{
+    internal class CopyPosePane : BasePane
+    {
+        private MeidoManager meidoManager;
+        private Button copyButton;
+        private Dropdown meidoDropdown;
+        private int[] copyMeidoSlot;
+        private bool PlentyOfMaids => this.meidoManager.ActiveMeidoList.Count >= 2;
+        private Meido FromMeido
+        {
+            get => this.meidoManager.HasActiveMeido
+                ? this.meidoManager.ActiveMeidoList[this.copyMeidoSlot[this.meidoDropdown.SelectedItemIndex]]
+                : null;
+        }
+
+        public CopyPosePane(MeidoManager meidoManager)
+        {
+            this.meidoManager = meidoManager;
+
+            this.meidoDropdown = new Dropdown(new[] { Translation.Get("systemMessage", "noMaids") });
+
+            this.copyButton = new Button(Translation.Get("copyPosePane", "copyButton"));
+            this.copyButton.ControlEvent += (s, a) => CopyPose();
+        }
+
+        protected override void ReloadTranslation()
+        {
+            if (!PlentyOfMaids)
+            {
+                this.meidoDropdown.SetDropdownItem(0, Translation.Get("systemMessage", "noMaids"));
+            }
+            this.copyButton.Label = Translation.Get("copyPosePane", "copyButton");
+        }
+
+        public override void Draw()
+        {
+            GUI.enabled = PlentyOfMaids;
+            GUILayout.BeginHorizontal();
+            this.meidoDropdown.Draw(GUILayout.Width(160f));
+            this.copyButton.Draw(GUILayout.ExpandWidth(false));
+            GUILayout.EndHorizontal();
+            GUI.enabled = false;
+        }
+
+        public override void UpdatePane()
+        {
+            SetMeidoDropdown();
+        }
+
+        private void CopyPose()
+        {
+            if (this.meidoManager.ActiveMeidoList.Count >= 2)
+            {
+                this.meidoManager.ActiveMeido.CopyPose(FromMeido);
+            }
+        }
+
+        private void SetMeidoDropdown()
+        {
+            if (this.meidoManager.ActiveMeidoList.Count >= 2)
+            {
+                IEnumerable<Meido> copyMeidoList = this.meidoManager.ActiveMeidoList
+                    .Where(meido => meido.ActiveSlot != this.meidoManager.ActiveMeido.ActiveSlot);
+
+                copyMeidoSlot = copyMeidoList.Select(meido => meido.ActiveSlot).ToArray();
+
+                string[] dropdownList = copyMeidoList
+                    .Select((meido, i) => $"{copyMeidoSlot[i] + 1}: {meido.LastName} {meido.FirstName}").ToArray();
+
+                this.meidoDropdown.SetDropdownItems(dropdownList, 0);
+            }
+            else this.meidoDropdown.SetDropdownItems(new[] { Translation.Get("systemMessage", "noMaids") });
+        }
+    }
+}

+ 2 - 2
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/PoseWindowPanes/SavePosePane.cs

@@ -45,11 +45,11 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         public override void Draw()
         {
             MiscGUI.Header(categoryHeader);
-            this.categoryComboBox.Draw();
+            this.categoryComboBox.Draw(GUILayout.Width(160f));
 
             MiscGUI.Header(nameHeader);
             GUILayout.BeginHorizontal();
-            this.poseNameTextField.Draw();
+            this.poseNameTextField.Draw(GUILayout.Width(160f));
             this.savePoseButton.Draw(GUILayout.ExpandWidth(false));
             GUILayout.EndHorizontal();
         }

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

@@ -109,7 +109,6 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             GUI.DragWindow();
         }
 
-
         private void UpdateMeido(object sender, MeidoUpdateEventArgs args)
         {
             if (args.FromMeido)

+ 15 - 5
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Meido/Meido.cs

@@ -114,24 +114,24 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             return cache.GetAnmBinary(true, true);
         }
 
-        public Maid Load(int slot, int activeSlot)
+        public Maid Load(int activeSlot, int maidSlot)
         {
             isLoading = true;
-            this.ActiveSlot = slot;
+            this.ActiveSlot = activeSlot;
 
             Maid.Visible = true;
 
             if (!Maid.body0.isLoadedBody)
             {
-                if (activeSlot >= MAX_MAIDS)
+                if (maidSlot >= MAX_MAIDS)
                 {
                     Maid.DutPropAll();
                     Maid.AllProcPropSeqStart();
                 }
                 else
                 {
-                    GameMain.Instance.CharacterMgr.Activate(activeSlot, activeSlot, false, false);
-                    GameMain.Instance.CharacterMgr.CharaVisible(activeSlot, true, false);
+                    GameMain.Instance.CharacterMgr.Activate(maidSlot, maidSlot, false, false);
+                    GameMain.Instance.CharacterMgr.CharaVisible(maidSlot, true, false);
                 }
             }
             else
@@ -219,6 +219,16 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             SetMune();
         }
 
+        public void CopyPose(Meido fromMeido)
+        {
+            byte[] poseBinary = fromMeido.SerializePose();
+            string tag = $"copy_{fromMeido.Maid.status.guid}";
+            Maid.body0.CrossFade(tag, poseBinary, false, true, false, 0f);
+            Maid.SetAutoTwistAll(true);
+            Maid.transform.rotation = fromMeido.Maid.transform.rotation;
+            SetMune();
+        }
+
         public void SetPoseCustom(string path)
         {
             if (!Maid.body0.isLoadedBody) return;