WindowManager.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace COM3D2.MeidoPhotoStudio.Plugin
  5. {
  6. using Window = Constants.Window;
  7. public class WindowManager
  8. {
  9. private Dictionary<Window, BaseWindow> Windows;
  10. private static Window currentWindow = Window.Call;
  11. private static Window CurrentWindow
  12. {
  13. get => currentWindow;
  14. set
  15. {
  16. if (value > Window.BG2) currentWindow = Window.BG2;
  17. else if (value < Window.Call) currentWindow = Window.Call;
  18. else currentWindow = value;
  19. }
  20. }
  21. private Rect mainWindowRect;
  22. private Rect messageWindowRect;
  23. private MeidoManager meidoManager;
  24. private bool initializeWindows = false;
  25. public bool Visible { get; set; }
  26. public WindowManager(MeidoManager meidoManager, EnvironmentManager environmentManager)
  27. {
  28. TabsPane.TabChange += ChangeTab;
  29. this.meidoManager = meidoManager;
  30. this.meidoManager.SelectMeido += MeidoSelect;
  31. this.meidoManager.CalledMeidos += (s, a) => Visible = true;
  32. mainWindowRect.y = Screen.height * 0.08f;
  33. mainWindowRect.x = Screen.width;
  34. Windows = new Dictionary<Window, BaseWindow>()
  35. {
  36. [Window.Call] = new MaidCallWindow(meidoManager),
  37. [Window.Pose] = new MaidPoseWindow(meidoManager),
  38. [Window.Face] = new MaidFaceWindow(meidoManager),
  39. [Window.BG] = new BackgroundWindow(environmentManager),
  40. [Window.BG2] = new Background2Window(environmentManager),
  41. [Window.Message] = new MessageWindow()
  42. };
  43. Windows[Window.Message].Visible = false;
  44. }
  45. ~WindowManager()
  46. {
  47. TabsPane.TabChange -= ChangeTab;
  48. }
  49. private void MeidoSelect(object sender, MeidoChangeEventArgs args)
  50. {
  51. if (args.fromMeido)
  52. TabsPane.SelectedTab = args.isBody ? Window.Pose : Window.Face;
  53. }
  54. private void ChangeTab(object sender, EventArgs args)
  55. {
  56. CurrentWindow = TabsPane.SelectedTab;
  57. }
  58. public void Update()
  59. {
  60. if (Input.GetKeyDown(KeyCode.M))
  61. {
  62. (Windows[Window.Message] as MessageWindow).SetVisibility();
  63. }
  64. if (Input.GetKeyDown(KeyCode.Tab))
  65. {
  66. Visible = !Visible;
  67. }
  68. if (this.meidoManager.IsFade) Visible = false;
  69. HandleZoom();
  70. }
  71. private void HandleZoom()
  72. {
  73. bool mainWindowVisible = Windows[currentWindow].Visible;
  74. bool dropdownVisible = DropdownHelper.Visible;
  75. bool messageWindowVisible = Windows[currentWindow].Visible;
  76. if (mainWindowVisible || dropdownVisible || messageWindowVisible)
  77. {
  78. if (Input.mouseScrollDelta.y != 0f)
  79. {
  80. Vector2 mousePos = Event.current.mousePosition;
  81. if (mainWindowVisible && mainWindowRect.Contains(mousePos)
  82. || dropdownVisible && DropdownHelper.dropdownRect.Contains(mousePos)
  83. || messageWindowVisible && messageWindowRect.Contains(mousePos)
  84. )
  85. {
  86. GameMain.Instance.MainCamera.SetControl(false);
  87. Input.ResetInputAxes();
  88. }
  89. }
  90. }
  91. }
  92. public void OnGUI()
  93. {
  94. if (!Visible) return;
  95. GUIStyle windowStyle = new GUIStyle(GUI.skin.box);
  96. GameMain.Instance.MainCamera.SetControl(true);
  97. if (Windows[currentWindow].Visible)
  98. {
  99. mainWindowRect.width = 220;
  100. mainWindowRect.height = Screen.height * 0.8f;
  101. mainWindowRect.x = Mathf.Clamp(mainWindowRect.x, 0, Screen.width - mainWindowRect.width);
  102. mainWindowRect.y = Mathf.Clamp(mainWindowRect.y, -mainWindowRect.height + 30, Screen.height - 50);
  103. mainWindowRect = GUI.Window(Constants.mainWindowID, mainWindowRect, Windows[CurrentWindow].OnGUI, "", windowStyle);
  104. }
  105. if (Windows[Window.Message].Visible)
  106. {
  107. messageWindowRect.width = Mathf.Clamp(Screen.width * 0.4f, 440, Mathf.Infinity);
  108. messageWindowRect.height = Mathf.Clamp(Screen.height * 0.15f, 150, Mathf.Infinity);
  109. messageWindowRect.x = Mathf.Clamp(messageWindowRect.x, -messageWindowRect.width + Utility.GetPix(20), Screen.width - Utility.GetPix(20));
  110. messageWindowRect.y = Mathf.Clamp(messageWindowRect.y, -messageWindowRect.height + Utility.GetPix(20), Screen.height - Utility.GetPix(20));
  111. if (!initializeWindows)
  112. {
  113. messageWindowRect.x = Screen.width / 2 - messageWindowRect.width / 2;
  114. messageWindowRect.y = Screen.height - messageWindowRect.height;
  115. initializeWindows = true;
  116. }
  117. messageWindowRect = GUI.Window(Constants.messageWindowID, messageWindowRect, Windows[Window.Message].OnGUI, "", windowStyle);
  118. }
  119. DropdownHelper.HandleDropdown();
  120. }
  121. }
  122. }