Przeglądaj źródła

Add maid placement presets

habeebweeb 4 lat temu
rodzic
commit
c6dede5eba

+ 10 - 7
COM3D2.MeidoPhotoStudio.Plugin/Config/MeidoPhotoStudio/Translations/en/translation.ui.json

@@ -14,14 +14,17 @@
     "placementDropdown": {
         "normal": "Normal",
         "horizontalRow": "Horizontal Row",
-        "diagonal": "Diagonal",
-        "circleOut": "Circle (outer)",
-        "circleIn": "Circle (Inner)",
-        "fan": "Fan",
+        "verticalRow": "Vertical Row",
+        "diagonalRow": "Diagonal",
+        "diagonalRowInverse": "Diagonal (Inverse)",
+        "circleOuter": "Circle (Outer)",
+        "circleInner": "Circle (Inner)",
+        "fanInner": "Fan (Inner)",
+        "fanOuter": "Fan (Outer)",
         "v": "V",
-        "^": "^",
-        "m": "M",
-        "w": "W"
+        "vInverse": "^",
+        "wave": "M",
+        "waveInverse": "W"
     },
     "maidPoseWindow": {
         "ikToggle": "IK",

+ 13 - 7
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/MainWindowPanes/CallWindowPane.cs

@@ -6,18 +6,22 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
     {
         private MeidoManager meidoManager;
         private MaidSelectorPane maidSelectorPane;
-        private Button placementButton;
+        private Dropdown placementDropdown;
         private Button placementOKButton;
 
         public CallWindowPane(MeidoManager meidoManager)
         {
             this.meidoManager = meidoManager;
-            placementButton = new Button(Translation.Get("placementDropdown", "normal"));
-            placementButton.ControlEvent += (o, a) => Debug.Log("Change placement");
-            Controls.Add(placementButton);
+            placementDropdown = new Dropdown(
+                Translation.GetArray("placementDropdown", MaidPlacementUtility.placementTypes)
+            );
+            Controls.Add(placementDropdown);
 
             placementOKButton = new Button(Translation.Get("maidCallWindow", "okButton"));
-            placementOKButton.ControlEvent += (o, a) => Debug.Log("Placement changed");
+            placementOKButton.ControlEvent += (o, a) =>
+            {
+                meidoManager.PlaceMeidos(MaidPlacementUtility.placementTypes[placementDropdown.SelectedItemIndex]);
+            };
             Controls.Add(placementOKButton);
 
             maidSelectorPane = AddPane(new MaidSelectorPane(meidoManager));
@@ -25,7 +29,9 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
         protected override void ReloadTranslation()
         {
-            placementButton.Label = Translation.Get("placementDropdown", "normal");
+            placementDropdown.SetDropdownItems(
+                Translation.GetArray("placementDropdown", MaidPlacementUtility.placementTypes)
+            );
             placementOKButton.Label = Translation.Get("maidCallWindow", "okButton");
         }
 
@@ -37,7 +43,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         public override void Draw()
         {
             GUILayout.BeginHorizontal();
-            placementButton.Draw(GUILayout.Width(150));
+            placementDropdown.Draw(GUILayout.Width(150));
             placementOKButton.Draw();
             GUILayout.EndHorizontal();
 

+ 148 - 0
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/MaidPlacementUtility.cs

@@ -0,0 +1,148 @@
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace COM3D2.MeidoPhotoStudio.Plugin
+{
+    internal class MaidPlacementUtility
+    {
+        private static readonly float pi = Mathf.PI;
+        private static readonly float tau = Mathf.PI * 2f;
+        public static readonly string[] placementTypes = {
+            "horizontalRow", "verticalRow", "diagonalRow", "diagonalRowInverse", "wave", "waveInverse",
+            "v", "vInverse", "circleInner", "circleOuter", "fanInner", "fanOuter"
+        };
+
+        public static int AlternatingSequence(int x)
+        {
+            return (int)((x % 2 == 0 ? 1 : -1) * Mathf.Ceil(x / 2f));
+        }
+
+        public static void ApplyPlacement(string placementType, IList<Meido> list)
+        {
+            switch (placementType)
+            {
+                case "horizontalRow": PlacementRow(list, false); break;
+                case "verticalRow": PlacementRow(list, true); break;
+                case "diagonalRow": PlacementDiagonal(list, false); break;
+                case "diagonalRowInverse": PlacementDiagonal(list, true); break;
+                case "wave": PlacementWave(list, false); break;
+                case "waveInverse": PlacementWave(list, true); break;
+                case "v": PlacementV(list, false); break;
+                case "vInverse": PlacementV(list, true); break;
+                case "circleOuter": PlacementCircle(list, false); break;
+                case "circleInner": PlacementCircle(list, true); break;
+                case "fanInner": PlacementFan(list, false); break;
+                case "fanOuter": PlacementFan(list, true); break;
+                default: return;
+            }
+        }
+
+        public static void PlacementRow(IList<Meido> list, bool vertical = false)
+        {
+            for (int i = 0; i < list.Count; i++)
+            {
+                Vector3 position = Vector3.zero;
+
+                Maid maid = list[i].Maid;
+
+                float a = AlternatingSequence(i) * 0.6f;
+
+                if (vertical) position.z = a;
+                else position.x = a;
+
+                maid.SetPos(position);
+                maid.SetRot(Vector3.zero);
+            }
+        }
+
+        public static void PlacementDiagonal(IList<Meido> list, bool inverse = false)
+        {
+            for (int i = 0; i < list.Count; i++)
+            {
+                Maid maid = list[i].Maid;
+
+                float z = AlternatingSequence(i) * 0.5f;
+
+                maid.SetPos(inverse ? new Vector3(z, 0, -z) : new Vector3(z, 0, z));
+                maid.SetRot(Vector3.zero);
+            }
+        }
+
+        public static void PlacementWave(IList<Meido> list, bool inverse = false)
+        {
+            for (int i = 0; i < list.Count; i++)
+            {
+                Maid maid = list[i].Maid;
+
+                float x = AlternatingSequence(i) * 0.4f;
+                float z = (inverse ? -1 : 1) * Mathf.Cos(AlternatingSequence(i) * pi) * 0.35f;
+
+                maid.SetPos(new Vector3(x, 0, z));
+                maid.SetRot(Vector3.zero);
+            }
+        }
+
+        public static void PlacementV(IList<Meido> list, bool inverse = false)
+        {
+            for (int i = 0; i < list.Count; i++)
+            {
+                Maid maid = list[i].Maid;
+
+                float x = AlternatingSequence(i) * 0.4f;
+                float z = (inverse ? 1 : -1) * Mathf.Abs(AlternatingSequence(i)) * 0.4f;
+
+                maid.SetPos(new Vector3(x, 0, z));
+                maid.SetRot(Vector3.zero);
+            }
+        }
+
+        public static void PlacementCircle(IList<Meido> list, bool inner = false)
+        {
+            int maidCount = list.Count;
+
+            float radius = (0.3f + 0.1f * maidCount);
+
+            for (int i = 0; i < maidCount; i++)
+            {
+                Maid maid = list[i].Maid;
+
+                float angle = (pi / 2f) + tau * AlternatingSequence(i) / maidCount;
+
+                float x = Mathf.Cos(angle) * radius;
+                float z = Mathf.Sin(angle) * radius;
+
+                float rotation = Mathf.Atan2(x, z);
+                if (inner) rotation += pi;
+
+                maid.SetPos(new Vector3(x, 0, z));
+                maid.SetRot(new Vector3(0, rotation * Mathf.Rad2Deg, 0));
+            }
+        }
+
+        public static void PlacementFan(IList<Meido> list, bool outer = false)
+        {
+            int maidCount = list.Count;
+
+            float radius = (0.2f + 0.2f * maidCount);
+
+            list[0].Maid.SetPos(Vector3.zero);
+            list[0].Maid.SetRot(Vector3.zero);
+
+            for (int i = 1; i < maidCount; i++)
+            {
+                Maid maid = list[i].Maid;
+
+                float angle = pi * AlternatingSequence(i - 1) / maidCount;
+
+                float x = Mathf.Sin(angle) * radius;
+                float z = Mathf.Cos(angle) * radius;
+
+                float rotation = Mathf.Atan2(x, z);
+                if (outer) rotation += pi;
+
+                maid.SetPos(new Vector3(-x, 0, -z));
+                maid.SetRot(new Vector3(0, rotation * Mathf.Rad2Deg, 0));
+            }
+        }
+    }
+}

+ 5 - 0
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Managers/MeidoManager.cs

@@ -153,6 +153,11 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             else return null;
         }
 
+        public void PlaceMeidos(string placementType)
+        {
+            MaidPlacementUtility.ApplyPlacement(placementType, ActiveMeidoList);
+        }
+
         private void UndressAll()
         {
             if (!HasActiveMeido) return;