Browse Source

Add filter for active meido only in call window

This is done to allow for rearranging meido call order without having to
frantically scroll through a potentially huge list.

Closes #37
habeebweeb 3 years ago
parent
commit
4deb43ce77

+ 2 - 1
src/MeidoPhotoStudio.Plugin/Config/MeidoPhotoStudio/Translations/en/translation.ui.json

@@ -9,7 +9,8 @@
     "maidCallWindow": {
         "okButton": "OK",
         "clearButton": "Clear",
-        "callButton": "Call"
+        "callButton": "Call",
+        "activeOnlyToggle": "Active Only"
     },
     "placementDropdown": {
         "normal": "Normal",

+ 72 - 25
src/MeidoPhotoStudio.Plugin/GUI/Panes/CallWindowPanes/MaidSelectorPane.cs

@@ -1,3 +1,4 @@
+using System.Collections.Generic;
 using UnityEngine;
 
 namespace MeidoPhotoStudio.Plugin
@@ -6,8 +7,11 @@ namespace MeidoPhotoStudio.Plugin
     {
         private readonly MeidoManager meidoManager;
         private Vector2 maidListScrollPos;
+        private Vector2 activeMaidListScrollPos;
         private readonly Button clearMaidsButton;
         private readonly Button callMaidsButton;
+        private readonly Toggle activeMeidoListToggle;
+
         public MaidSelectorPane(MeidoManager meidoManager)
         {
             this.meidoManager = meidoManager;
@@ -16,12 +20,28 @@ namespace MeidoPhotoStudio.Plugin
 
             callMaidsButton = new Button(Translation.Get("maidCallWindow", "callButton"));
             callMaidsButton.ControlEvent += (s, a) => this.meidoManager.CallMeidos();
+
+            activeMeidoListToggle = new(Translation.Get("maidCallWindow", "activeOnlyToggle"));
+
+            this.meidoManager.BeginCallMeidos += (_, _) =>
+            {
+                if (meidoManager.SelectedMeidoSet.Count == 0)
+                    activeMeidoListToggle.Value = false;
+            };
         }
 
         protected override void ReloadTranslation()
         {
             clearMaidsButton.Label = Translation.Get("maidCallWindow", "clearButton");
             callMaidsButton.Label = Translation.Get("maidCallWindow", "callButton");
+            activeMeidoListToggle.Label = Translation.Get("maidCallWindow", "activeOnlyToggle");
+        }
+        
+        public override void Activate()
+        {
+            base.Activate();
+            // Leaving this mode enabled pretty much softlocks meido selection so disable it on activation
+            activeMeidoListToggle.Value = false;
         }
 
         public override void Draw()
@@ -31,48 +51,75 @@ namespace MeidoPhotoStudio.Plugin
             callMaidsButton.Draw();
             GUILayout.EndHorizontal();
 
-            GUIStyle labelStyle = new GUIStyle(GUI.skin.label) { fontSize = 14 };
-            GUIStyle selectLabelStyle = new GUIStyle(labelStyle);
-            selectLabelStyle.normal.textColor = Color.black;
-            selectLabelStyle.alignment = TextAnchor.UpperRight;
-            GUIStyle labelSelectedStyle = new GUIStyle(labelStyle);
-            labelSelectedStyle.normal.textColor = Color.black;
+            MpsGui.WhiteLine();
+
+            GUI.enabled = meidoManager.HasActiveMeido;
+
+            activeMeidoListToggle.Draw();
+
+            GUI.enabled = true;
+
+            var onlyActiveMeido = activeMeidoListToggle.Value;
+
+            IList<Meido> meidoList = onlyActiveMeido
+                ? meidoManager.ActiveMeidoList
+                : meidoManager.Meidos;
 
-            Rect windowRect = parent.WindowRect;
-            float windowHeight = windowRect.height;
-            float buttonWidth = windowRect.width - 30f;
+            var labelStyle = new GUIStyle(GUI.skin.label) { fontSize = 14 };
+
+            var selectLabelStyle = new GUIStyle(labelStyle)
+            {
+                normal = { textColor = Color.black },
+                alignment = TextAnchor.UpperRight,
+            };
+
+            var labelSelectedStyle = new GUIStyle(labelStyle)
+            {
+                normal = { textColor = Color.black },
+            };
+
+            var windowRect = parent.WindowRect;
+            var windowHeight = windowRect.height;
+            var buttonWidth = windowRect.width - 30f;
             const float buttonHeight = 85f;
+            const float offsetTop = 130f;
 
-            Rect positionRect = new Rect(5f, 90f, windowRect.width - 10f, windowHeight - 125f);
-            Rect viewRect = new Rect(0f, 0f, buttonWidth, (buttonHeight * meidoManager.Meidos.Length) + 5f);
-            maidListScrollPos = GUI.BeginScrollView(positionRect, maidListScrollPos, viewRect);
+            var positionRect = new Rect(5f, offsetTop, windowRect.width - 10f, windowHeight - (offsetTop + 35));
+            var viewRect = new Rect(0f, 0f, buttonWidth, buttonHeight * meidoList.Count + 5f);
 
-            for (int i = 0; i < meidoManager.Meidos.Length; i++)
+            if (onlyActiveMeido)
+                activeMaidListScrollPos = GUI.BeginScrollView(positionRect, activeMaidListScrollPos, viewRect);
+            else
+                maidListScrollPos = GUI.BeginScrollView(positionRect, maidListScrollPos, viewRect);
+
+            for (var i = 0; i < meidoList.Count; i++)
             {
-                Meido meido = meidoManager.Meidos[i];
-                float y = i * buttonHeight;
-                bool selectedMaid = meidoManager.SelectedMeidoSet.Contains(i);
+                var meido = meidoList[i];
+                var y = i * buttonHeight;
+                var selectedMaid = meidoManager.SelectedMeidoSet.Contains(meido.StockNo);
 
-                if (GUI.Button(new Rect(0f, y, buttonWidth, buttonHeight), string.Empty)) meidoManager.SelectMeido(i);
+                if (GUI.Button(new(0f, y, buttonWidth, buttonHeight), string.Empty))
+                    meidoManager.SelectMeido(meido.StockNo);
 
                 if (selectedMaid)
                 {
-                    int selectedIndex = meidoManager.SelectMeidoList.IndexOf(i) + 1;
-                    GUI.DrawTexture(
-                        new Rect(5f, y + 5f, buttonWidth - 10f, buttonHeight - 10f), Texture2D.whiteTexture
-                    );
+                    var selectedIndex = meidoManager.SelectMeidoList.IndexOf(meido.StockNo) + 1;
+                    GUI.DrawTexture(new(5f, y + 5f, buttonWidth - 10f, buttonHeight - 10f), Texture2D.whiteTexture);
+
                     GUI.Label(
-                        new Rect(0f, y + 5f, buttonWidth - 10f, buttonHeight),
-                        selectedIndex.ToString(), selectLabelStyle
+                        new(0f, y + 5f, buttonWidth - 10f, buttonHeight), selectedIndex.ToString(), selectLabelStyle
                     );
                 }
 
-                if (meido.Portrait) GUI.DrawTexture(new Rect(5f, y, buttonHeight, buttonHeight), meido.Portrait);
+                if (meido.Portrait != null)
+                    GUI.DrawTexture(new(5f, y, buttonHeight, buttonHeight), meido.Portrait);
+
                 GUI.Label(
-                    new Rect(95f, y + 30f, buttonWidth - 80f, buttonHeight),
+                    new(95f, y + 30f, buttonWidth - 80f, buttonHeight),
                     $"{meido.LastName}\n{meido.FirstName}", selectedMaid ? labelSelectedStyle : labelStyle
                 );
             }
+
             GUI.EndScrollView();
         }
     }