Ver código fonte

Add MyRoom props pane and add prop tabs

habeebweeb 4 anos atrás
pai
commit
5a9473cd74

+ 30 - 0
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Constants.cs

@@ -88,6 +88,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             InitializeFaceBlends();
             InitializeBGs();
             InitializeDogu();
+            InitializeMyRoomProps();
         }
 
         public static void InitializePoses()
@@ -473,6 +474,35 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             HandItemsInitialized = true;
         }
 
+        private static void InitializeMyRoomProps()
+        {
+            PlacementData.CreateData();
+            List<PlacementData.Data> myRoomData = PlacementData.GetAllDatas(false);
+            myRoomData.Sort((a, b) =>
+            {
+                int res = a.categoryID.CompareTo(b.categoryID);
+                if (res == 0) res = a.ID.CompareTo(b.ID);
+                return res;
+            });
+
+            foreach (PlacementData.Data data in myRoomData)
+            {
+                string category = PlacementData.GetCategoryName(data.categoryID);
+
+                if (!MyRoomPropDict.ContainsKey(category))
+                {
+                    MyRoomPropCategories.Add(category);
+                    MyRoomPropDict[category] = new List<MyRoomItem>();
+                }
+
+                string asset = !string.IsNullOrEmpty(data.resourceName) ? data.resourceName : data.assetName;
+
+                MyRoomItem item = new MyRoomItem() { PrefabName = asset, ID = data.ID };
+
+                MyRoomPropDict[category].Add(item);
+            }
+        }
+
         private static CsvParser OpenCsvParser(string nei, AFileSystemBase fs)
         {
             try

+ 96 - 0
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/BackgroundWindow2Panes/MyRoomPropsPane.cs

@@ -0,0 +1,96 @@
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace COM3D2.MeidoPhotoStudio.Plugin
+{
+    using static MenuFileUtility;
+    internal class MyRoomPropsPane : BasePane
+    {
+        private PropManager propManager;
+        private Dropdown propCategoryDropdown;
+        private Vector2 propListScrollPos;
+        private string SelectedCategory
+        {
+            get => Constants.MyRoomPropCategories[this.propCategoryDropdown.SelectedItemIndex];
+        }
+        private List<MyRoomItem> myRoomPropList;
+        private string currentCategory;
+
+        public MyRoomPropsPane(PropManager propManager)
+        {
+            this.propManager = propManager;
+
+            this.propCategoryDropdown = new Dropdown(
+                Translation.GetArray("doguCategories", Constants.MyRoomPropCategories)
+            );
+            this.propCategoryDropdown.SelectionChange += (s, a) => ChangePropCategory(SelectedCategory);
+            ChangePropCategory(SelectedCategory);
+        }
+
+        protected override void ReloadTranslation()
+        {
+            this.propCategoryDropdown.SetDropdownItems(
+                Translation.GetArray("doguCategories", Constants.MyRoomPropCategories)
+            );
+        }
+
+        public override void Draw()
+        {
+            float dropdownButtonHeight = 30f;
+            float dropdownButtonWidth = 120f;
+            GUILayoutOption[] dropdownLayoutOptions = new GUILayoutOption[] {
+                GUILayout.Height(dropdownButtonHeight),
+                GUILayout.Width(dropdownButtonWidth)
+            };
+
+            GUILayout.BeginHorizontal();
+            GUILayout.FlexibleSpace();
+            this.propCategoryDropdown.Draw(dropdownLayoutOptions);
+            GUILayout.FlexibleSpace();
+            GUILayout.EndHorizontal();
+
+            float windowHeight = Screen.height * 0.6f;
+
+            int buttonSize = 64;
+            int listCount = myRoomPropList.Count;
+            int offsetLeft = 15;
+            int offsetTop = 85;
+
+            int columns = 3;
+
+            Rect positionRect = new Rect(offsetLeft, offsetTop + dropdownButtonHeight, 220, windowHeight);
+            Rect viewRect = new Rect(
+                0, 0, buttonSize * columns, buttonSize * Mathf.Ceil(listCount / (float)columns) + 5
+            );
+            propListScrollPos = GUI.BeginScrollView(positionRect, propListScrollPos, viewRect);
+
+            for (int i = 0; i < listCount; i++)
+            {
+                float x = i % columns * buttonSize;
+                float y = i / columns * buttonSize;
+                MenuFileUtility.MyRoomItem myRoomItem = myRoomPropList[i];
+                Rect iconRect = new Rect(x, y, buttonSize, buttonSize);
+                if (GUI.Button(iconRect, "")) propManager.SpawnMyRoomProp(myRoomItem);
+                GUI.DrawTexture(iconRect, myRoomItem.Icon);
+            }
+
+            GUI.EndScrollView();
+            GUILayout.Space(windowHeight);
+        }
+
+        private void ChangePropCategory(string category)
+        {
+            if (currentCategory == category) return;
+            currentCategory = category;
+            propListScrollPos = Vector2.zero;
+            this.myRoomPropList = Constants.MyRoomPropDict[category];
+            if (myRoomPropList[0].Icon == null)
+            {
+                foreach (MyRoomItem item in myRoomPropList)
+                {
+                    item.Icon = (Texture2D)MyRoomCustom.PlacementData.GetData(item.ID).GetThumbnail();
+                }
+            }
+        }
+    }
+}

+ 2 - 2
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/BackgroundWindow2Panes/PropsPane.cs

@@ -90,8 +90,8 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 GUILayout.Width(dropdownButtonWidth)
             };
 
-            MiscGUI.Header(this.header);
-            MiscGUI.WhiteLine();
+            // MiscGUI.Header(this.header);
+            // MiscGUI.WhiteLine();
 
             GUILayout.BeginHorizontal();
             this.prevDoguCategoryButton.Draw(arrowLayoutOptions);

+ 21 - 4
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/MainWindowPanes/BG2WindowPane.cs

@@ -10,20 +10,37 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private MeidoManager meidoManager;
         private PropsPane propsPane;
         private AttachPropPane attachPropPane;
+        private MyRoomPropsPane myRoomPropsPane;
+        private SelectionGrid propTabs;
+        private BasePane currentPropsPane;
 
         public BG2WindowPane(MeidoManager meidoManager, EnvironmentManager environmentManager)
         {
             this.environmentManager = environmentManager;
             this.meidoManager = meidoManager;
 
-            this.propsPane = new PropsPane(this.environmentManager.PropManager);
-            this.attachPropPane = new AttachPropPane(this.meidoManager, this.environmentManager.PropManager);
+            PropManager propManager = this.environmentManager.PropManager;
+            this.propsPane = new PropsPane(propManager);
+            this.myRoomPropsPane = new MyRoomPropsPane(propManager);
+            this.attachPropPane = new AttachPropPane(this.meidoManager, propManager);
+
+            this.Panes.Add(propsPane);
+            this.Panes.Add(myRoomPropsPane);
+
+            this.propTabs = new SelectionGrid(Translation.GetArray("propTabs", new[] { "Props", "MyRoom", "Mod" }));
+            this.propTabs.ControlEvent += (s, a) =>
+            {
+                currentPropsPane = this.Panes[this.propTabs.SelectedItemIndex];
+            };
+            this.currentPropsPane = this.Panes[0];
         }
 
         public override void Draw()
         {
-            this.propsPane.Draw();
-            this.attachPropPane.Draw();
+            this.propTabs.Draw();
+            MiscGUI.WhiteLine();
+            this.currentPropsPane.Draw();
+            if (this.propTabs.SelectedItemIndex == 0) this.attachPropPane.Draw();
         }
 
         public override void UpdatePanes()

+ 35 - 27
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Managers/PropManager.cs

@@ -76,9 +76,14 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
         private GameObject GetDeploymentObject()
         {
-            GameObject go = GameObject.Find("Deployment Object Parent");
-            if (go == null) go = new GameObject("Deployment Object Parent");
-            return go;
+        public void SpawnMyRoomProp(MenuFileUtility.MyRoomItem item)
+        {
+            MyRoomCustom.PlacementData.Data data = MyRoomCustom.PlacementData.GetData(item.ID);
+            GameObject dogu = GameObject.Instantiate(data.GetPrefab());
+            string name = Translation.Get("myRoomPropNames", item.PrefabName);
+            if (dogu != null) AttachDragPoint(dogu, name, new Vector3(0f, 0f, 0.5f));
+            else Debug.Log($"Could not load MyRoomCreative prop '{item.PrefabName}'");
+        }
         }
 
         public void SpawnObject(string assetName)
@@ -223,30 +228,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
             if (dogu != null)
             {
-                // TODO: Figure out why some props aren't centred properly
-                // Doesn't happen in MM but even after copy pasting the code, it doesn't work :/
-                GameObject deploymentObject = GetDeploymentObject();
-                GameObject finalDogu = new GameObject(doguName);
-
-                dogu.transform.localScale = doguScale;
-
-                dogu.transform.SetParent(finalDogu.transform, true);
-                finalDogu.transform.SetParent(deploymentObject.transform, false);
-
-                finalDogu.transform.position = doguPosition;
-
-                DragPointDogu dragDogu = DragPoint.Make<DragPointDogu>(
-                    PrimitiveType.Cube, Vector3.one * 0.12f, DragPoint.LightBlue
-                );
-                dragDogu.Initialize(() => finalDogu.transform.position, () => Vector3.zero);
-                dragDogu.Set(finalDogu.transform);
-                dragDogu.AddGizmo();
-                dragDogu.ConstantScale = true;
-                dragDogu.Delete += DeleteDogu;
-                dragDogu.DragPointScale = CubeSmall ? DragPointGeneral.smallCube : 1f;
-
-                doguList.Add(dragDogu);
-                OnDoguListChange();
+                AttachDragPoint(dogu, doguName, doguPosition);
             }
             else
             {
@@ -254,6 +236,32 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             }
         }
 
+        private void AttachDragPoint(GameObject dogu, string name, Vector3 position)
+        {
+            // TODO: Figure out why some props aren't centred properly
+            // Doesn't happen in MM but even after copy pasting the code, it doesn't work :/
+            GameObject deploymentObject = GetDeploymentObject();
+            GameObject finalDogu = new GameObject(name);
+
+            dogu.transform.SetParent(finalDogu.transform, true);
+            finalDogu.transform.SetParent(deploymentObject.transform, false);
+
+            finalDogu.transform.position = position;
+
+            DragPointDogu dragDogu = DragPoint.Make<DragPointDogu>(
+                PrimitiveType.Cube, Vector3.one * 0.12f, DragPoint.LightBlue
+            );
+            dragDogu.Initialize(() => finalDogu.transform.position, () => Vector3.zero);
+            dragDogu.Set(finalDogu.transform);
+            dragDogu.AddGizmo(scale: 0.45f, mode: CustomGizmo.GizmoMode.World);
+            dragDogu.ConstantScale = true;
+            dragDogu.Delete += DeleteDogu;
+            dragDogu.DragPointScale = CubeSmall ? DragPointGeneral.smallCube : 1f;
+
+            doguList.Add(dragDogu);
+            OnDoguListChange();
+        }
+
         public DragPointDogu GetDogu(int doguIndex)
         {
             if (doguList.Count == 0 || doguIndex >= doguList.Count || doguIndex < 0) return null;