Browse Source

Tweak GUI for maid seleciton and props

A grid of buttons require me to use GUI rather than GUILayout for
positioning. Need to pass GUI window to child panes to get the rect
information for positioning and layout.
habeebweeb 4 years ago
parent
commit
37481f04ed

+ 1 - 0
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Controls/DropDown.cs

@@ -53,6 +53,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             DropdownHelper.DropdownClose += OnCloseDropdown;
         }
 
+        // TODO: I don't think this works the way I think it does
         ~Dropdown()
         {
             DropdownHelper.SelectionChange -= OnChangeSelection;

+ 11 - 8
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/BackgroundWindow2Panes/ModPropsPane.cs

@@ -81,6 +81,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             }
         }
 
+        public float buttonSize = 54f;
         public override void Draw()
         {
             const float dropdownButtonHeight = 30f;
@@ -113,17 +114,20 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
             if (shouldDraw)
             {
-                float windowHeight = Screen.height * 0.7f;
-
-                const int buttonSize = 50;
-                const int offsetLeft = 15;
-                const int offsetTop = 85;
+                Rect windowRect = parent.WindowRect;
+                float windowHeight = windowRect.height;
+                float windowWidth = windowRect.width;
 
+                // const float buttonSize = 50f;
+                const float offsetTop = 80f;
                 const int columns = 4;
+                float buttonSize = (windowWidth / columns) - 10f;
 
-                Rect positionRect = new Rect(offsetLeft, offsetTop + dropdownButtonHeight, 220, windowHeight);
+                Rect positionRect = new Rect(
+                    5f, offsetTop + dropdownButtonHeight, windowWidth - 10f, windowHeight - 145f
+                );
                 Rect viewRect = new Rect(
-                    0, 0, buttonSize * columns, (buttonSize * Mathf.Ceil(currentListCount / (float)columns)) + 5
+                    0f, 0f, buttonSize * columns, (buttonSize * Mathf.Ceil(currentListCount / (float)columns)) + 5
                 );
                 propListScrollPos = GUI.BeginScrollView(positionRect, propListScrollPos, viewRect);
 
@@ -141,7 +145,6 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 }
 
                 GUI.EndScrollView();
-                GUILayout.Space(windowHeight);
             }
         }
 

+ 10 - 7
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/BackgroundWindow2Panes/MyRoomPropsPane.cs

@@ -44,18 +44,22 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             GUILayout.FlexibleSpace();
             GUILayout.EndHorizontal();
 
-            float windowHeight = Screen.height * 0.6f;
+            Rect windowRect = parent.WindowRect;
 
-            const int buttonSize = 64;
-            const int offsetLeft = 15;
-            const int offsetTop = 85;
+            float windowHeight = windowRect.height;
+            float windowWidth = windowRect.width;
+
+            const float offsetTop = 80f;
             const int columns = 3;
+            float buttonSize = (windowWidth / columns) - 10f;
 
             int listCount = myRoomPropList.Count;
 
-            Rect positionRect = new Rect(offsetLeft, offsetTop + dropdownButtonHeight, 220, windowHeight);
+            Rect positionRect = new Rect(
+                5f, offsetTop + dropdownButtonHeight, windowWidth - 10f, windowHeight - 145f
+            );
             Rect viewRect = new Rect(
-                0, 0, buttonSize * columns, (buttonSize * Mathf.Ceil(listCount / (float)columns)) + 5
+                0f, 0f, buttonSize * columns, (buttonSize * Mathf.Ceil(listCount / (float)columns)) + 5f
             );
             propListScrollPos = GUI.BeginScrollView(positionRect, propListScrollPos, viewRect);
 
@@ -70,7 +74,6 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             }
 
             GUI.EndScrollView();
-            GUILayout.Space(windowHeight);
         }
 
         private void ChangePropCategory(string category)

+ 2 - 8
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/BasePane.cs

@@ -1,27 +1,21 @@
 using System;
-using System.Collections.Generic;
 
 namespace COM3D2.MeidoPhotoStudio.Plugin
 {
     internal abstract class BasePane
     {
         protected BaseWindow parent;
-        protected List<BaseControl> Controls { get; set; }
         protected bool updating;
         public virtual bool Visible { get; set; }
         public virtual bool Enabled { get; set; }
 
-        protected BasePane()
-        {
-            Translation.ReloadTranslationEvent += OnReloadTranslation;
-            Controls = new List<BaseControl>();
-        }
+        protected BasePane() => Translation.ReloadTranslationEvent += OnReloadTranslation;
 
         ~BasePane() => Translation.ReloadTranslationEvent -= OnReloadTranslation;
 
         private void OnReloadTranslation(object sender, EventArgs args) => ReloadTranslation();
 
-        public void SetParent(BaseWindow window) => parent = window;
+        public virtual void SetParent(BaseWindow window) => parent = window;
 
         protected virtual void ReloadTranslation() { }
 

+ 15 - 12
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/CallWindowPanes/MaidSelectorPane.cs

@@ -13,11 +13,9 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             this.meidoManager = meidoManager;
             clearMaidsButton = new Button(Translation.Get("maidCallWindow", "clearButton"));
             clearMaidsButton.ControlEvent += (s, a) => this.meidoManager.SelectMeidoList.Clear();
-            Controls.Add(clearMaidsButton);
 
             callMaidsButton = new Button(Translation.Get("maidCallWindow", "callButton"));
             callMaidsButton.ControlEvent += (s, a) => this.meidoManager.CallMeidos();
-            Controls.Add(callMaidsButton);
         }
 
         protected override void ReloadTranslation()
@@ -38,11 +36,13 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             GUIStyle labelSelectedStyle = new GUIStyle(labelStyle);
             labelSelectedStyle.normal.textColor = Color.black;
 
-            float windowHeight = Screen.height * 0.8f;
-            const int buttonHeight = 85;
-            const int buttonWidth = 205;
-            Rect positionRect = new Rect(5, 115, buttonWidth + 15, windowHeight - 140);
-            Rect viewRect = new Rect(0, 0, buttonWidth - 5, (buttonHeight * meidoManager.Meidos.Length) + 5);
+            Rect windowRect = parent.WindowRect;
+            float windowHeight = windowRect.height;
+            float buttonWidth = windowRect.width - 30f;
+            const float buttonHeight = 85f;
+
+            Rect positionRect = new Rect(5, 115f, windowRect.width - 10f, windowHeight - 150f);
+            Rect viewRect = new Rect(0, 0, buttonWidth, (buttonHeight * meidoManager.Meidos.Length) + 5f);
             maidListScrollPos = GUI.BeginScrollView(positionRect, maidListScrollPos, viewRect);
 
             for (int i = 0; i < meidoManager.Meidos.Length; i++)
@@ -51,7 +51,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 float y = i * buttonHeight;
                 bool selectedMaid = meidoManager.SelectMeidoList.Contains(i);
 
-                if (GUI.Button(new Rect(0, y, buttonWidth, buttonHeight), ""))
+                if (GUI.Button(new Rect(0f, y, buttonWidth, buttonHeight), ""))
                 {
                     if (selectedMaid) meidoManager.SelectMeidoList.Remove(i);
                     else meidoManager.SelectMeidoList.Add(i);
@@ -60,15 +60,18 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 if (selectedMaid)
                 {
                     int selectedIndex = meidoManager.SelectMeidoList.IndexOf(i) + 1;
-                    GUI.DrawTexture(new Rect(5, y + 5, buttonWidth - 10, buttonHeight - 10), Texture2D.whiteTexture);
+                    GUI.DrawTexture(
+                        new Rect(5f, y + 5f, buttonWidth - 10f, buttonHeight - 10f), Texture2D.whiteTexture
+                    );
                     GUI.Label(
-                        new Rect(0, y + 5, buttonWidth - 10, buttonHeight), selectedIndex.ToString(), selectLabelStyle
+                        new Rect(0f, y + 5f, buttonWidth - 10f, buttonHeight),
+                        selectedIndex.ToString(), selectLabelStyle
                     );
                 }
 
-                GUI.DrawTexture(new Rect(5, y, buttonHeight, buttonHeight), meido.Portrait);
+                GUI.DrawTexture(new Rect(5f, y, buttonHeight, buttonHeight), meido.Portrait);
                 GUI.Label(
-                    new Rect(95, y + 30, buttonWidth - 80, buttonHeight),
+                    new Rect(95f, y + 30f, buttonWidth - 80f, buttonHeight),
                     $"{meido.LastName}\n{meido.FirstName}", selectedMaid ? labelSelectedStyle : labelStyle
                 );
             }

+ 5 - 0
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/MainWindowPanes/BaseMainWindowPane.cs

@@ -4,5 +4,10 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
     {
         protected TabsPane tabsPane;
         public void SetTabsPane(TabsPane tabsPane) => this.tabsPane = tabsPane;
+        /* Main window panes have panes within them while being a pane itself of the main window */
+        public override void SetParent(BaseWindow window)
+        {
+            foreach (BasePane pane in Panes) pane.SetParent(window);
+        }
     }
 }

+ 0 - 2
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/MainWindowPanes/CallWindowPane.cs

@@ -15,13 +15,11 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             placementDropdown = new Dropdown(
                 Translation.GetArray("placementDropdown", MaidPlacementUtility.placementTypes)
             );
-            Controls.Add(placementDropdown);
 
             placementOKButton = new Button(Translation.Get("maidCallWindow", "okButton"));
             placementOKButton.ControlEvent += (o, a) => this.meidoManager.PlaceMeidos(
                 MaidPlacementUtility.placementTypes[placementDropdown.SelectedItemIndex]
             );
-            Controls.Add(placementOKButton);
 
             maidSelectorPane = AddPane(new MaidSelectorPane(this.meidoManager));
         }

+ 1 - 3
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Windows/BaseWindow.cs

@@ -6,7 +6,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
     {
         private static int id = 765;
         private static int ID => id++;
-        public readonly int windowID;
+        public readonly int windowID = ID;
         protected Rect windowRect = new Rect(0f, 0f, 480f, 270f);
         public virtual Rect WindowRect
         {
@@ -26,8 +26,6 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             (Screen.width / 2) - (windowRect.width / 2), (Screen.height / 2) - (windowRect.height / 2)
         );
 
-        protected BaseWindow() => windowID = ID;
-
         public virtual void HandleZoom()
         {
             if (Input.mouseScrollDelta.y != 0f && Visible)

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

@@ -77,6 +77,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             }
             windowPanes[id] = window;
             windowPanes[id].SetTabsPane(tabsPane);
+            windowPanes[id].SetParent(this);
             Panes.Add(windowPanes[id]);
         }
 

+ 0 - 4
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Windows/MessageWindow.cs

@@ -29,18 +29,14 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             windowRect.y = Screen.height - WindowRect.height;
             this.messageWindowManager = messageWindowManager;
             nameTextField = new TextField();
-            Controls.Add(nameTextField);
 
             fontSizeSlider = new Slider(MessageWindowManager.fontBounds);
             fontSizeSlider.ControlEvent += ChangeFontSize;
-            Controls.Add(fontSizeSlider);
 
             messageTextArea = new TextArea();
-            Controls.Add(messageTextArea);
 
             okButton = new Button("OK");
             okButton.ControlEvent += ShowMessage;
-            Controls.Add(okButton);
         }
 
         public void ToggleVisibility()