Browse Source

Change method of setting global GUI visibility

habeebweeb 4 years ago
parent
commit
57e0b56341

+ 10 - 4
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Controls/DropDown.cs

@@ -150,7 +150,8 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private static int currentDropdownID;
         private static int selectedItemIndex;
         private static bool initialized = false;
-        public static bool Visible { get; private set; }
+        public static bool Visible { get; set; }
+        public static bool DropdownOpen { get; private set; }
         private static bool onScrollBar = false;
         public static Rect dropdownWindow;
         private static Rect dropdownScrollRect;
@@ -203,6 +204,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             dropdownScrollRect = new Rect(0, 0, dropdownWindow.width, dropdownWindow.height);
             dropdownRect = new Rect(0, 0, dropdownWindow.width - 18, calculatedListHeight);
 
+            DropdownOpen = true;
             Visible = true;
         }
 
@@ -231,16 +233,20 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 bool clickedMe = dropdownWindow.Contains(mousePos);
                 onScrollBar = mousePos.x > dropdownWindow.x + dropdownWindow.width - 12f;
                 if (buttonRect.Contains(mousePos)) clickedYou = true;
-                if (!clickedMe) Visible = false;
+                if (!clickedMe) DropdownOpen = false;
             }
 
             if (selection != selectedItemIndex || (clicked && !onScrollBar))
             {
                 SelectionChange?.Invoke(null, new DropdownSelectArgs(currentDropdownID, selection));
-                Visible = false;
+                DropdownOpen = false;
             }
 
-            if (!Visible) DropdownClose?.Invoke(null, new DropdownCloseArgs(currentDropdownID, scrollPos, clickedYou));
+            if (!DropdownOpen)
+            {
+                Visible = false;
+                DropdownClose?.Invoke(null, new DropdownCloseArgs(currentDropdownID, scrollPos, clickedYou));
+            }
         }
 
         private static void InitializeStyle()

+ 1 - 2
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/CallWindowPanes/MaidSelectorPane.cs

@@ -11,7 +11,6 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private Vector2 maidListScrollPos;
         private Button clearMaidsButton;
         private Button callMaidsButton;
-        public event EventHandler MaidCall;
         public MaidSelectorPane(MeidoManager meidoManager) : base()
         {
             this.meidoManager = meidoManager;
@@ -21,7 +20,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             Controls.Add(clearMaidsButton);
 
             callMaidsButton = new Button("Call");
-            callMaidsButton.ControlEvent += (s, a) => MaidCall?.Invoke(this, EventArgs.Empty);
+            callMaidsButton.ControlEvent += (s, a) => this.meidoManager.OnBeginCallMeidos(this.selectedMaidList);
             Controls.Add(callMaidsButton);
         }
 

+ 0 - 8
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Windows/MainWindows/MaidCallWindow.cs

@@ -23,14 +23,6 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             Controls.Add(placementOKButton);
 
             maidSelectorPane = new MaidSelectorPane(meidoManager);
-            maidSelectorPane.MaidCall += (s, e) =>
-            {
-                this.meidoManager.IsFade = true;
-                GameMain.Instance.MainCamera.FadeOut(0.01f, false, () =>
-                {
-                    this.meidoManager.CallMeidos(maidSelectorPane.selectedMaidList);
-                }, false);
-            };
         }
 
         public override void Draw(params GUILayoutOption[] layoutOptions)

+ 15 - 12
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Managers/MeidoManager.cs

@@ -13,10 +13,10 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         public List<Meido> ActiveMeidoList { get; private set; }
         public Meido ActiveMeido => ActiveMeidoList.Count > 0 ? ActiveMeidoList[selectedMeido] : null;
         public bool HasActiveMeido => ActiveMeido != null;
-        public bool IsFade { get; set; } = false;
         public int numberOfMeidos;
         public event EventHandler<MeidoChangeEventArgs> SelectMeido;
-        public event EventHandler CalledMeidos;
+        public event EventHandler EndCallMeidos;
+        public event EventHandler BeginCallMeidos;
         public event EventHandler AnimeChange;
         private int selectedMeido = 0;
         public int SelectedMeido
@@ -94,7 +94,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             foreach (Meido meido in ActiveMeidoList)
             {
                 meido.SelectMeido -= ChangeMeido;
-                meido.BodyLoad -= EndCallMeidos;
+                meido.BodyLoad -= OnEndCallMeidos;
                 meido.AnimeChange -= OnAnimeChangeEvent;
                 meido.Unload();
             }
@@ -106,7 +106,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             foreach (Meido meido in meidos)
             {
                 meido.SelectMeido -= ChangeMeido;
-                meido.BodyLoad -= EndCallMeidos;
+                meido.BodyLoad -= OnEndCallMeidos;
                 meido.AnimeChange -= OnAnimeChangeEvent;
                 meido.Deactivate();
             }
@@ -115,8 +115,6 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
         public void CallMeidos(List<int> selectedMaids)
         {
-            IsFade = true;
-
             UnloadMeidos();
 
             foreach (int slot in selectedMaids)
@@ -124,7 +122,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 Meido meido = meidos[slot];
                 ActiveMeidoList.Add(meido);
                 meido.SelectMeido += ChangeMeido;
-                meido.BodyLoad += EndCallMeidos;
+                meido.BodyLoad += OnEndCallMeidos;
                 meido.AnimeChange += OnAnimeChangeEvent;
             }
 
@@ -137,7 +135,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             SelectedMeido = 0;
             OnSelectMeido(new MeidoChangeEventArgs(SelectedMeido));
 
-            if (selectedMaids.Count == 0) EndCallMeidos(this, EventArgs.Empty);
+            if (selectedMaids.Count == 0) OnEndCallMeidos(this, EventArgs.Empty);
         }
 
         private void OnAnimeChangeEvent(object sender, EventArgs args)
@@ -157,16 +155,21 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             OnSelectMeido(args);
         }
 
-        private void EndCallMeidos(object sender, EventArgs args)
+        public void OnBeginCallMeidos(List<int> selectList)
+        {
+            this.BeginCallMeidos?.Invoke(this, EventArgs.Empty);
+            GameMain.Instance.MainCamera.FadeOut(0.01f, false, () => CallMeidos(selectList), false);
+        }
+
+        private void OnEndCallMeidos(object sender, EventArgs args)
         {
             if (!IsBusy)
             {
-                IsFade = false;
                 GameMain.Instance.MainCamera.FadeIn(1f);
-                CalledMeidos?.Invoke(this, EventArgs.Empty);
+                EndCallMeidos?.Invoke(this, EventArgs.Empty);
                 foreach (Meido meido in ActiveMeidoList)
                 {
-                    meido.BodyLoad -= EndCallMeidos;
+                    meido.BodyLoad -= OnEndCallMeidos;
                 }
             }
         }

+ 26 - 14
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Managers/WindowManager.cs

@@ -23,13 +23,28 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private Rect messageWindowRect;
         private MeidoManager meidoManager;
         private bool initializeWindows = false;
-        public bool Visible { get; set; }
+        public bool MainWindowVisible { get; set; }
+        public bool MessageWindowVisible
+        {
+            get => Windows[Window.Message].Visible;
+            set
+            {
+                Windows[Window.Message].Visible = value;
+            }
+        }
+        public bool DropdownVisible
+        {
+            get => DropdownHelper.Visible;
+            set
+            {
+                DropdownHelper.Visible = value;
+            }
+        }
         public WindowManager(MeidoManager meidoManager, EnvironmentManager environmentManager, MessageWindowManager messageWindowManager)
         {
             TabsPane.TabChange += ChangeTab;
             this.meidoManager = meidoManager;
             this.meidoManager.SelectMeido += MeidoSelect;
-            this.meidoManager.CalledMeidos += (s, a) => Visible = true;
 
             mainWindowRect.y = Screen.height * 0.08f;
             mainWindowRect.x = Screen.width;
@@ -65,24 +80,22 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         {
             if (Input.GetKeyDown(KeyCode.M))
             {
-                (Windows[Window.Message] as MessageWindow).SetVisibility();
+                (Windows[Window.Message] as MessageWindow).ToggleVisibility();
             }
 
             if (Input.GetKeyDown(KeyCode.Tab))
             {
-                Visible = !Visible;
+                MainWindowVisible = !MainWindowVisible;
             }
 
-            if (this.meidoManager.IsFade) Visible = false;
-
             HandleZoom();
         }
 
         private void HandleZoom()
         {
-            bool mainWindowVisible = Windows[currentWindow].Visible;
-            bool dropdownVisible = DropdownHelper.Visible;
-            bool messageWindowVisible = Windows[currentWindow].Visible;
+            bool mainWindowVisible = MainWindowVisible;
+            bool dropdownVisible = DropdownVisible;
+            bool messageWindowVisible = MessageWindowVisible;
             if (mainWindowVisible || dropdownVisible || messageWindowVisible)
             {
                 if (Input.mouseScrollDelta.y != 0f)
@@ -103,12 +116,10 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
         public void OnGUI()
         {
-            if (!Visible) return;
-
             GUIStyle windowStyle = new GUIStyle(GUI.skin.box);
             GameMain.Instance.MainCamera.SetControl(true);
 
-            if (Windows[currentWindow].Visible)
+            if (MainWindowVisible)
             {
                 mainWindowRect.width = 230;
                 mainWindowRect.height = Screen.height * 0.8f;
@@ -118,7 +129,8 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
                 mainWindowRect = GUI.Window(Constants.mainWindowID, mainWindowRect, Windows[CurrentWindow].OnGUI, "", windowStyle);
             }
-            if (Windows[Window.Message].Visible)
+
+            if (MessageWindowVisible)
             {
                 messageWindowRect.width = Mathf.Clamp(Screen.width * 0.4f, 440, Mathf.Infinity);
                 messageWindowRect.height = Mathf.Clamp(Screen.height * 0.15f, 150, Mathf.Infinity);
@@ -136,7 +148,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 messageWindowRect = GUI.Window(Constants.messageWindowID, messageWindowRect, Windows[Window.Message].OnGUI, "", windowStyle);
             }
 
-            if (DropdownHelper.Visible) DropdownHelper.HandleDropdown();
+            if (DropdownVisible) DropdownHelper.HandleDropdown();
         }
     }
 }

+ 9 - 3
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/MeidoPhotoStudio.cs

@@ -18,6 +18,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private Constants.Scene currentScene;
         private bool initialized = false;
         private bool isActive = false;
+        private bool uiActive = false;
         private MeidoPhotoStudio()
         {
             MeidoPhotoStudio.instance = this;
@@ -42,7 +43,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                     if (!initialized)
                     {
                         Initialize();
-                        windowManager.Visible = true;
+                        windowManager.MainWindowVisible = true;
                     }
                     else
                     {
@@ -50,6 +51,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                     }
                 }
 
+
                 if (isActive)
                 {
                     meidoManager.Update();
@@ -59,7 +61,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         }
         private void OnGUI()
         {
-            if (isActive)
+            if (uiActive)
             {
                 windowManager.OnGUI();
             }
@@ -91,8 +93,9 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             messageWindowManager.Deactivate();
 
             isActive = false;
+            uiActive = false;
             initialized = false;
-            windowManager.Visible = false;
+            windowManager.MainWindowVisible = false;
             GameMain.Instance.SoundMgr.PlayBGM("bgm009.ogg", 1f, true);
             GameObject go = GameObject.Find("UI Root").transform.Find("DailyPanel").gameObject;
             go.SetActive(true);
@@ -117,6 +120,8 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         {
             initialized = true;
             meidoManager = new MeidoManager();
+            meidoManager.BeginCallMeidos += (s, a) => this.uiActive = false;
+            meidoManager.EndCallMeidos += (s, a) => this.uiActive = true;
             environmentManager = new EnvironmentManager();
             messageWindowManager = new MessageWindowManager();
             windowManager = new WindowManager(meidoManager, environmentManager, messageWindowManager);
@@ -124,6 +129,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             environmentManager.Initialize();
 
             isActive = true;
+            uiActive = true;
 
             #region maid stuff
             // if (maid)