Browse Source

Clean up window related classes

- BaseWindowPane has been merged into BaseWindow.
- Activate/Deactivate have been added to the BasePane class.
- Activate/Deactivate have been overridden in BaseWindow to now call
each child pane's respective methods.

This was pretty much done so I could get GUI to do clean up stuff when
MPS is being activated/deactivated.
habeebweeb 3 years ago
parent
commit
822112d54c

+ 4 - 0
src/MeidoPhotoStudio.Plugin/GUI/Panes/BasePane.cs

@@ -22,5 +22,9 @@ namespace MeidoPhotoStudio.Plugin
         public virtual void UpdatePane() { }
 
         public virtual void Draw() { }
+
+        public virtual void Activate() { }
+
+        public virtual void Deactivate() { }
     }
 }

+ 1 - 6
src/MeidoPhotoStudio.Plugin/GUI/Panes/MainWindowPanes/BaseMainWindowPane.cs

@@ -1,13 +1,8 @@
 namespace MeidoPhotoStudio.Plugin
 {
-    public abstract class BaseMainWindowPane : BaseWindowPane
+    public abstract class BaseMainWindowPane : BaseWindow
     {
         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);
-        }
     }
 }

+ 52 - 13
src/MeidoPhotoStudio.Plugin/GUI/Windows/BaseWindow.cs

@@ -1,13 +1,17 @@
+using System.Collections.Generic;
 using UnityEngine;
 
 namespace MeidoPhotoStudio.Plugin
 {
-    public abstract class BaseWindow : BaseWindowPane
+    public abstract class BaseWindow : BasePane
     {
         private static int id = 765;
         private static int ID => id++;
         public readonly int windowID = ID;
-        protected Rect windowRect = new Rect(0f, 0f, 480f, 270f);
+        protected readonly List<BasePane> Panes = new();
+        protected Vector2 scrollPos;
+        public bool ActiveWindow { get; set; }
+        protected Rect windowRect = new(0f, 0f, 480f, 270f);
         public virtual Rect WindowRect
         {
             get => windowRect;
@@ -16,35 +20,70 @@ namespace MeidoPhotoStudio.Plugin
                 value.x = Mathf.Clamp(
                     value.x, -value.width + Utility.GetPix(20), Screen.width - Utility.GetPix(20)
                 );
+
                 value.y = Mathf.Clamp(
                     value.y, -value.height + Utility.GetPix(20), Screen.height - Utility.GetPix(20)
                 );
+
                 windowRect = value;
             }
         }
-        protected Vector2 MiddlePosition => new Vector2(
-            (Screen.width / 2) - (windowRect.width / 2), (Screen.height / 2) - (windowRect.height / 2)
+        protected Vector2 MiddlePosition => new(
+            (float)Screen.width / 2 - windowRect.width / 2, (float)Screen.height / 2 - windowRect.height / 2
         );
 
-        public virtual void HandleZoom()
+        protected T AddPane<T>(T pane) where T : BasePane
         {
-            if (Input.mouseScrollDelta.y != 0f && Visible)
-            {
-                Vector2 mousePos = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y);
-                if (WindowRect.Contains(mousePos)) Input.ResetInputAxes();
-            }
+            Panes.Add(pane);
+            pane.SetParent(this);
+            return pane;
         }
 
-        public virtual void Update() => HandleZoom();
+        public override void SetParent(BaseWindow window)
+        {
+            foreach (var pane in Panes) 
+                pane.SetParent(window);
+        }
 
-        public virtual void Activate() { }
+        private void HandleZoom()
+        {
+            if (Input.mouseScrollDelta.y == 0f || !Visible) return;
+
+            var mousePos = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y);
 
-        public virtual void Deactivate() { }
+            if (WindowRect.Contains(mousePos))
+                Input.ResetInputAxes();
+        }
+
+        public virtual void Update() =>
+            HandleZoom();
 
         public virtual void GUIFunc(int id)
         {
             Draw();
             GUI.DragWindow();
         }
+
+        public virtual void UpdatePanes()
+        {
+            foreach (var pane in Panes)
+                pane.UpdatePane();
+        }
+
+        public override void Activate()
+        {
+            base.Activate();
+
+            foreach (var pane in Panes)
+                pane.Activate();
+        }
+
+        public override void Deactivate()
+        {
+            base.Deactivate();
+
+            foreach (var pane in Panes)
+                pane.Deactivate();
+        }
     }
 }

+ 0 - 23
src/MeidoPhotoStudio.Plugin/GUI/Windows/BaseWindowPane.cs

@@ -1,23 +0,0 @@
-using System.Collections.Generic;
-using UnityEngine;
-
-namespace MeidoPhotoStudio.Plugin
-{
-    public abstract class BaseWindowPane : BasePane
-    {
-        protected List<BasePane> Panes = new List<BasePane>();
-        protected Vector2 scrollPos;
-        public bool ActiveWindow { get; set; }
-
-        public T AddPane<T>(T pane) where T : BasePane
-        {
-            Panes.Add(pane);
-            return pane;
-        }
-
-        public virtual void UpdatePanes()
-        {
-            foreach (BasePane pane in Panes) pane.UpdatePane();
-        }
-    }
-}

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

@@ -64,6 +64,7 @@ namespace MeidoPhotoStudio.Plugin
 
         public override void Activate()
         {
+            base.Activate();
             updating = true;
             tabsPane.SelectedTab = Constants.Window.Call;
             updating = false;

+ 0 - 2
src/MeidoPhotoStudio.Plugin/GUI/Windows/SceneWindow.cs

@@ -40,8 +40,6 @@ namespace MeidoPhotoStudio.Plugin
             directoryList = AddPane(new SceneManagerDirectoryPane(sceneManager, sceneModalWindow));
 
             sceneGrid = AddPane(new SceneManagerScenePane(sceneManager, sceneModalWindow));
-
-            sceneGrid.SetParent(this);
         }
 
         public override void GUIFunc(int id)