Browse Source

Move meido selection to MeidoManager

Have meido manager handle selecting/deselecting meidos for spawning and
despawning.
habeebweeb 4 years ago
parent
commit
9e17181cb9

+ 3 - 7
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/CallWindowPanes/MaidSelectorPane.cs

@@ -12,7 +12,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         {
             this.meidoManager = meidoManager;
             clearMaidsButton = new Button(Translation.Get("maidCallWindow", "clearButton"));
-            clearMaidsButton.ControlEvent += (s, a) => this.meidoManager.SelectMeidoList.Clear();
+            clearMaidsButton.ControlEvent += (s, a) => this.meidoManager.ClearSelectList();
 
             callMaidsButton = new Button(Translation.Get("maidCallWindow", "callButton"));
             callMaidsButton.ControlEvent += (s, a) => this.meidoManager.CallMeidos();
@@ -49,13 +49,9 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             {
                 Meido meido = meidoManager.Meidos[i];
                 float y = i * buttonHeight;
-                bool selectedMaid = meidoManager.SelectMeidoList.Contains(i);
+                bool selectedMaid = meidoManager.SelectedMeidoSet.Contains(i);
 
-                if (GUI.Button(new Rect(0f, y, buttonWidth, buttonHeight), ""))
-                {
-                    if (selectedMaid) meidoManager.SelectMeidoList.Remove(i);
-                    else meidoManager.SelectMeidoList.Add(i);
-                }
+                if (GUI.Button(new Rect(0f, y, buttonWidth, buttonHeight), string.Empty)) meidoManager.SelectMeido(i);
 
                 if (selectedMaid)
                 {

+ 24 - 1
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Managers/MeidoManager.cs

@@ -12,6 +12,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private int undress;
         private int numberOfMeidos;
         public Meido[] Meidos { get; private set; }
+        public HashSet<int> SelectedMeidoSet { get; } = new HashSet<int>();
         public List<int> SelectMeidoList { get; } = new List<int>();
         public List<Meido> ActiveMeidoList { get; } = new List<Meido>();
         public Meido ActiveMeido => ActiveMeidoList.Count > 0 ? ActiveMeidoList[SelectedMeido] : null;
@@ -25,6 +26,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             get => selectedMeido;
             private set => selectedMeido = Utility.Bound(value, 0, ActiveMeidoList.Count - 1);
         }
+        public int EditMaidIndex { get; private set; }
         public bool Busy => ActiveMeidoList.Any(meido => meido.Busy);
         private bool globalGravity;
         public bool GlobalGravity
@@ -76,8 +78,9 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 meido.GravityMove -= OnGravityMove;
                 meido.Deactivate();
             }
-            SelectMeidoList.Clear();
+
             ActiveMeidoList.Clear();
+            ClearSelectList();
         }
 
         public void Update()
@@ -169,6 +172,26 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             OnEndCallMeidos(this, EventArgs.Empty);
         }
 
+        public void SelectMeido(int index)
+        {
+            if (SelectedMeidoSet.Contains(index))
+            {
+                SelectedMeidoSet.Remove(index);
+                SelectMeidoList.Remove(index);
+            }
+            else
+            {
+                SelectedMeidoSet.Add(index);
+                SelectMeidoList.Add(index);
+            }
+        }
+
+        public void ClearSelectList()
+        {
+            SelectedMeidoSet.Clear();
+            SelectMeidoList.Clear();
+        }
+
         public Meido GetMeido(string guid)
         {
             return string.IsNullOrEmpty(guid) ? null : ActiveMeidoList.Find(meido => meido.Maid.status.guid == guid);