Browse Source

Add cube drag point pane

Toggles for drag point cube active and small scale for bg, maid and
props
habeebweeb 4 năm trước cách đây
mục cha
commit
e6ed389ebd

+ 77 - 0
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/BackgroundWindowPanes/DragPointPane.cs

@@ -0,0 +1,77 @@
+using UnityEngine;
+
+namespace COM3D2.MeidoPhotoStudio.Plugin
+{
+    internal class DragPointPane : BasePane
+    {
+        private string header;
+        private Toggle propsCubeToggle;
+        private Toggle smallCubeToggle;
+        private Toggle maidCubeToggle;
+        private Toggle bgCubeToggle;
+        private enum DragPointSetting
+        {
+            Prop, Maid, Background, Size
+        };
+
+        public DragPointPane()
+        {
+            this.header = Translation.Get("movementCube", "header");
+            this.propsCubeToggle = new Toggle(Translation.Get("movementCube", "props"), PropManager.CubeActive);
+            this.smallCubeToggle = new Toggle(Translation.Get("movementCube", "small"));
+            this.maidCubeToggle = new Toggle(Translation.Get("movementCube", "maid"), DragPointManager.CubeActive);
+            this.bgCubeToggle = new Toggle(Translation.Get("movementCube", "bg"), EnvironmentManager.CubeActive);
+
+            this.propsCubeToggle.ControlEvent += (s, a) =>
+            {
+                ChangeDragPointSetting(DragPointSetting.Prop, this.propsCubeToggle.Value);
+            };
+            this.smallCubeToggle.ControlEvent += (s, a) =>
+            {
+                ChangeDragPointSetting(DragPointSetting.Size, this.smallCubeToggle.Value);
+            };
+            this.maidCubeToggle.ControlEvent += (s, a) =>
+            {
+                ChangeDragPointSetting(DragPointSetting.Maid, this.maidCubeToggle.Value);
+            };
+            this.bgCubeToggle.ControlEvent += (s, a) =>
+            {
+                ChangeDragPointSetting(DragPointSetting.Background, this.bgCubeToggle.Value);
+            };
+        }
+
+        public override void Draw()
+        {
+            MiscGUI.Header(header);
+            MiscGUI.WhiteLine();
+
+            GUILayout.BeginHorizontal();
+            this.propsCubeToggle.Draw();
+            this.smallCubeToggle.Draw();
+            this.maidCubeToggle.Draw();
+            this.bgCubeToggle.Draw();
+            GUILayout.EndHorizontal();
+        }
+
+        private void ChangeDragPointSetting(DragPointSetting setting, bool value)
+        {
+            switch (setting)
+            {
+                case DragPointSetting.Prop:
+                    PropManager.CubeActive = value;
+                    break;
+                case DragPointSetting.Background:
+                    EnvironmentManager.CubeActive = value;
+                    break;
+                case DragPointSetting.Maid:
+                    DragPointManager.CubeActive = value;
+                    break;
+                case DragPointSetting.Size:
+                    DragPointManager.CubeSmall = value;
+                    EnvironmentManager.CubeSmall = value;
+                    PropManager.CubeSmall = value;
+                    break;
+            }
+        }
+    }
+}

+ 4 - 0
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/MainWindowPanes/BGWindowPane.cs

@@ -9,10 +9,12 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private PropsPane propsPane;
         private LightsPane lightsPane;
         private EffectsPane effectsPane;
+        private DragPointPane dragPointPane;
 
         public BGWindowPane(EnvironmentManager environmentManager)
         {
             this.backgroundSelectorPane = new BackgroundSelectorPane(environmentManager);
+            this.dragPointPane = new DragPointPane();
             this.propsPane = new PropsPane(environmentManager.PropManager);
             this.lightsPane = new LightsPane(environmentManager);
 
@@ -26,10 +28,12 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 ["fog"] = new FogPane(effectManager)
             };
         }
+
         public override void Draw()
         {
             this.backgroundSelectorPane.Draw();
             this.propsPane.Draw();
+            this.dragPointPane.Draw();
             this.scrollPos = GUILayout.BeginScrollView(this.scrollPos);
             this.lightsPane.Draw();
             this.effectsPane.Draw();

+ 49 - 12
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Managers/DragPointManager.cs

@@ -81,7 +81,6 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 Bone.Toe01L, Bone.Toe11L, Bone.Toe21L, Bone.Toe01R, Bone.Toe11R, Bone.Toe21R
             }
         };
-
         private static readonly Dictionary<IKMode, DragInfo[]> IKGroupBone = new Dictionary<IKMode, DragInfo[]>()
         {
             [IKMode.None] = new[] {
@@ -111,13 +110,41 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 DragInfo.Gizmo(Bone.UpperArmL), DragInfo.Gizmo(Bone.UpperArmR), DragInfo.Gizmo(Bone.ThighL),
                 DragInfo.Gizmo(Bone.ThighR)
             },
-            [IKMode.BodyTransform] = new[] { DragInfo.Drag(Bone.Body), DragInfo.Drag(Bone.Cube) },
+            [IKMode.BodyTransform] = new[] { DragInfo.Drag(Bone.Body), DragInfo.DragAll(Bone.Cube) },
             [IKMode.BodySelect] = new[] { DragInfo.Drag(Bone.Head), DragInfo.Drag(Bone.Body) },
             [IKMode.FingerRotLocalXZ] = IKGroup[IKMode.FingerRotLocalXZ]
                 .Select(bone => DragInfo.DragBone(bone)).ToArray(),
             [IKMode.FingerRotLocalY] = IKGroup[IKMode.FingerRotLocalY]
                 .Select(bone => DragInfo.DragBone(bone)).ToArray()
         };
+        private static bool cubeActive = false;
+        public static bool CubeActive
+        {
+            get => cubeActive;
+            set
+            {
+                if (value != cubeActive)
+                {
+                    cubeActive = value;
+                    CubeActiveChange?.Invoke(null, EventArgs.Empty);
+                }
+            }
+        }
+        private static bool cubeSmall = false;
+        public static bool CubeSmall
+        {
+            get => cubeSmall;
+            set
+            {
+                if (value != cubeSmall)
+                {
+                    cubeSmall = value;
+                    CubeSmallChange?.Invoke(null, EventArgs.Empty);
+                }
+            }
+        }
+        private static event EventHandler CubeActiveChange;
+        private static event EventHandler CubeSmallChange;
         private Meido meido;
         private Maid maid;
         private Dictionary<Bone, BaseDrag> DragPoint;
@@ -147,7 +174,6 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 this.SetBoneMode(this.isBone);
             }
         }
-        private static bool cubeActive = false;
 
         public DragPointManager(Meido meido)
         {
@@ -156,6 +182,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             this.meido.BodyLoad += Initialize;
         }
 
+
         public void Destroy()
         {
             foreach (KeyValuePair<Bone, BaseDrag> dragPoint in DragPoint)
@@ -164,6 +191,8 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             }
             BoneTransform.Clear();
             DragPoint.Clear();
+            CubeSmallChange -= OnCubeSmall;
+
         }
 
         public void Update()
@@ -214,6 +243,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             InitializeDragPoints();
             this.Active = true;
             this.SetBoneMode(false);
+            CubeSmallChange += OnCubeSmall;
         }
 
         private void SetBoneMode(bool active)
@@ -266,12 +296,11 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                     {
                         DragPoint[bone].gameObject.SetActive(true);
                     }
-
-                    if (ikMode == IKMode.BodyTransform)
-                    {
-                        DragPoint[Bone.Cube].gameObject.SetActive(cubeActive);
-                    }
                 }
+
+                bool cubeVisible = CubeActive && (ikMode == IKMode.BodyTransform);
+                DragPoint[Bone.Cube].SetDragProp(cubeVisible, cubeVisible, cubeVisible);
+                DragPoint[Bone.Cube].gameObject.SetActive(cubeVisible);
             }
             else
             {
@@ -283,7 +312,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 else if (ikMode == IKMode.BodyTransform)
                 {
                     DragPoint[Bone.Body].gameObject.SetActive(true);
-                    DragPoint[Bone.Cube].gameObject.SetActive(cubeActive);
+                    DragPoint[Bone.Cube].gameObject.SetActive(CubeActive);
                 }
                 else if (ikMode == IKMode.UpperRot || ikMode == IKMode.RotLocal)
                 {
@@ -314,6 +343,12 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             }
         }
 
+        private void OnCubeSmall(object sender, EventArgs args)
+        {
+            DragBody dragPoint = (DragBody)DragPoint[Bone.Cube];
+            dragPoint.DragPointScale = dragPoint.BaseScale * (CubeSmall ? 0.4f : 1f);
+        }
+
         private void OnSelectFace(object sender, EventArgs args)
         {
             OnMeidoSelect(new MeidoUpdateEventArgs(meido.ActiveSlot, true, false));
@@ -338,6 +373,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         {
             foreach (KeyValuePair<Bone, BaseDrag> kvp in DragPoint)
             {
+                if (kvp.Key == Bone.Cube) continue;
                 BaseDrag dragPoint = kvp.Value;
                 dragPoint.DragPointScale = dragPoint.BaseScale * scale;
             }
@@ -396,7 +432,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
             // Cube Dragpoint
             DragPoint[Bone.Cube] =
-                BaseDrag.MakeDragPoint(PrimitiveType.Cube, new Vector3(0.12f, 0.12f, 0.12f), BaseDrag.Blue)
+                BaseDrag.MakeDragPoint(PrimitiveType.Cube, Vector3.one * 0.12f, BaseDrag.Blue)
                 .AddComponent<DragBody>()
                 .Initialize(meido,
                     () => maid.transform.position,
@@ -405,6 +441,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             DragBody dragCube = (DragBody)DragPoint[Bone.Cube];
             dragCube.Scale += OnSetDragPointScale;
             dragCube.DragPointVisible = true;
+            // TODO: Make gizmos work on cube
 
             // Body Dragpoint
             DragPoint[Bone.Body] =
@@ -494,7 +531,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
             // Left Mune Dragpoint
             DragPoint[Bone.MuneL] =
-                BaseDrag.MakeDragPoint(PrimitiveType.Sphere, new Vector3(0.12f, 0.12f, 0.12f), BaseDrag.LightBlue)
+                BaseDrag.MakeDragPoint(PrimitiveType.Sphere, Vector3.one * 0.12f, BaseDrag.LightBlue)
                 .AddComponent<DragMune>();
             Transform[] muneIKChainL = new Transform[3] {
                 BoneTransform[Bone.MuneL],
@@ -509,7 +546,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
             // Right Mune Dragpoint
             DragPoint[Bone.MuneR] =
-                BaseDrag.MakeDragPoint(PrimitiveType.Sphere, new Vector3(0.12f, 0.12f, 0.12f), BaseDrag.LightBlue)
+                BaseDrag.MakeDragPoint(PrimitiveType.Sphere, Vector3.one * 0.12f, BaseDrag.LightBlue)
                 .AddComponent<DragMune>();
             Transform[] muneIKChainR = new Transform[3] {
                 BoneTransform[Bone.MuneR],

+ 22 - 0
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Managers/EnvironmentManager.cs

@@ -18,7 +18,21 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 }
             }
         }
+        private static bool cubeSmall;
+        public static bool CubeSmall
+        {
+            get => cubeSmall;
+            set
+            {
+                if (value != cubeSmall)
+                {
+                    cubeSmall = value;
+                    CubeSmallChange?.Invoke(null, EventArgs.Empty);
+                }
+            }
+        }
         private static event EventHandler CubeActiveChange;
+        private static event EventHandler CubeSmallChange;
         private GameObject cameraObject;
         private Camera subCamera;
         private GameObject bgObject;
@@ -88,6 +102,8 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             PropManager.Activate();
             LightManager.Activate();
             EffectManager.Activate();
+
+            CubeSmallChange += OnCubeSmall;
         }
 
         public void Deactivate()
@@ -114,6 +130,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             GameMain.Instance.MainCamera.SetTargetPos(new Vector3(0.5609447f, 1.380762f, -1.382336f), true);
             GameMain.Instance.MainCamera.SetDistance(1.6f, true);
             GameMain.Instance.MainCamera.SetAroundAngle(new Vector2(245.5691f, 6.273283f), true);
+            CubeSmallChange -= OnCubeSmall;
         }
 
         public void Update()
@@ -197,6 +214,11 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             cameraMain.SetTargetPos(new Vector3(0f, 0.9f, 0f), true);
             cameraMain.SetDistance(3f, true);
         }
+
+        private void OnCubeSmall(object sender, EventArgs args)
+        {
+            this.bgDragPoint.DragPointScale = this.bgDragPoint.BaseScale * (CubeSmall ? 0.4f : 1f);
+        }
     }
 
     public struct CameraInfo

+ 49 - 8
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Managers/PropManager.cs

@@ -9,16 +9,47 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 {
     internal class PropManager
     {
+        private static bool cubeActive = true;
+        public static bool CubeActive
+        {
+            get => cubeActive;
+            set
+            {
+                if (value != cubeActive)
+                {
+                    cubeActive = value;
+                    CubeActiveChange?.Invoke(null, EventArgs.Empty);
+                }
+            }
+        }
+        private static bool cubeSmall;
+        public static bool CubeSmall
+        {
+            get => cubeSmall;
+            set
+            {
+                if (value != cubeSmall)
+                {
+                    cubeSmall = value;
+                    CubeSmallChange?.Invoke(null, EventArgs.Empty);
+                }
+            }
+        }
+        private static event EventHandler CubeActiveChange;
+        private static event EventHandler CubeSmallChange;
         private List<DragDogu> doguList = new List<DragDogu>();
         private DragType dragTypeOld = DragType.None;
         private DragType currentDragType = DragType.None;
         private bool showGizmos = false;
-        enum DragType
+        private enum DragType
         {
             None, Move, Rotate, Scale, Delete, Other
         }
 
-        public void Activate() { }
+        public void Activate()
+        {
+            CubeSmallChange += OnCubeSmall;
+        }
 
         public void Deactivate()
         {
@@ -27,19 +58,20 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 GameObject.Destroy(dogu.gameObject);
             }
             doguList.Clear();
+            CubeSmallChange -= OnCubeSmall;
         }
 
         public void Update()
         {
             if (Input.GetKeyDown(KeyCode.Space))
             {
-                showGizmos = !showGizmos;
-                currentDragType = dragTypeOld = DragType.None;
-                UpdateDragType();
+                //     showGizmos = !showGizmos;
+                //     currentDragType = dragTypeOld = DragType.None;
+                //     UpdateDragType();
             }
 
-            if (Input.GetKey(KeyCode.Z) || Input.GetKey(KeyCode.X) || Input.GetKey(KeyCode.C)
-                || Input.GetKey(KeyCode.D)
+            if (CubeActive && (Input.GetKey(KeyCode.Z) || Input.GetKey(KeyCode.X) || Input.GetKey(KeyCode.C)
+                || Input.GetKey(KeyCode.D))
             )
             {
                 currentDragType = DragType.Other;
@@ -56,7 +88,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
         private void UpdateDragType()
         {
-            bool dragPointActive = currentDragType == DragType.Other;
+            bool dragPointActive = (currentDragType == DragType.Other);
             foreach (DragDogu dogu in doguList)
             {
                 dogu.SetDragProp(showGizmos, dragPointActive, dragPointActive);
@@ -198,6 +230,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 dragDogu.Delete += (s, a) => DeleteDogu();
                 dragDogu.SetDragProp(showGizmos, false, false);
                 doguList.Add(dragDogu);
+                dragDogu.DragPointScale = dragDogu.BaseScale * (CubeSmall ? 0.4f : 1f);
             }
         }
 
@@ -214,5 +247,13 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 }
             );
         }
+
+        private void OnCubeSmall(object sender, EventArgs args)
+        {
+            foreach (DragDogu dogu in doguList)
+            {
+                dogu.DragPointScale = dogu.BaseScale * (CubeSmall ? 0.4f : 1f);
+            }
+        }
     }
 }