WindowManager.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 MainWindowVisible { get; set; }
  26. public bool MessageWindowVisible
  27. {
  28. get => Windows[Window.Message].Visible;
  29. set
  30. {
  31. Windows[Window.Message].Visible = value;
  32. }
  33. }
  34. public bool DropdownVisible
  35. {
  36. get => DropdownHelper.Visible;
  37. set
  38. {
  39. DropdownHelper.Visible = value;
  40. }
  41. }
  42. public WindowManager(MeidoManager meidoManager, EnvironmentManager environmentManager, MessageWindowManager messageWindowManager)
  43. {
  44. TabsPane.TabChange += ChangeTab;
  45. this.meidoManager = meidoManager;
  46. this.meidoManager.SelectMeido += MeidoSelect;
  47. mainWindowRect.y = Screen.height * 0.08f;
  48. mainWindowRect.x = Screen.width;
  49. Windows = new Dictionary<Window, BaseWindow>()
  50. {
  51. [Window.Call] = new MaidCallWindow(meidoManager),
  52. [Window.Pose] = new MaidPoseWindow(meidoManager),
  53. [Window.Face] = new MaidFaceWindow(meidoManager),
  54. [Window.BG] = new BackgroundWindow(environmentManager),
  55. [Window.BG2] = new Background2Window(environmentManager),
  56. [Window.Message] = new MessageWindow(messageWindowManager)
  57. };
  58. Windows[Window.Message].Visible = false;
  59. }
  60. ~WindowManager()
  61. {
  62. TabsPane.TabChange -= ChangeTab;
  63. }
  64. private void MeidoSelect(object sender, MeidoChangeEventArgs args)
  65. {
  66. if (args.fromMeido)
  67. TabsPane.SelectedTab = args.isBody ? Window.Pose : Window.Face;
  68. }
  69. private void ChangeTab(object sender, EventArgs args)
  70. {
  71. CurrentWindow = TabsPane.SelectedTab;
  72. }
  73. public void Update()
  74. {
  75. if (Input.GetKeyDown(KeyCode.M))
  76. {
  77. (Windows[Window.Message] as MessageWindow).ToggleVisibility();
  78. }
  79. if (Input.GetKeyDown(KeyCode.Tab))
  80. {
  81. MainWindowVisible = !MainWindowVisible;
  82. }
  83. HandleZoom();
  84. }
  85. private void HandleZoom()
  86. {
  87. bool mainWindowVisible = MainWindowVisible;
  88. bool dropdownVisible = DropdownVisible;
  89. bool messageWindowVisible = MessageWindowVisible;
  90. if (mainWindowVisible || dropdownVisible || messageWindowVisible)
  91. {
  92. if (Input.mouseScrollDelta.y != 0f)
  93. {
  94. Vector2 mousePos = Event.current.mousePosition;
  95. if (mainWindowVisible && mainWindowRect.Contains(mousePos)
  96. || dropdownVisible && DropdownHelper.dropdownWindow.Contains(mousePos)
  97. || messageWindowVisible && messageWindowRect.Contains(mousePos)
  98. )
  99. {
  100. GameMain.Instance.MainCamera.SetControl(false);
  101. Input.ResetInputAxes();
  102. }
  103. }
  104. }
  105. }
  106. public void OnGUI()
  107. {
  108. GUIStyle windowStyle = new GUIStyle(GUI.skin.box);
  109. GameMain.Instance.MainCamera.SetControl(true);
  110. if (MainWindowVisible)
  111. {
  112. mainWindowRect.width = 230;
  113. mainWindowRect.height = Screen.height * 0.8f;
  114. mainWindowRect.x = Mathf.Clamp(mainWindowRect.x, 0, Screen.width - mainWindowRect.width);
  115. mainWindowRect.y = Mathf.Clamp(mainWindowRect.y, -mainWindowRect.height + 30, Screen.height - 50);
  116. mainWindowRect = GUI.Window(Constants.mainWindowID, mainWindowRect, Windows[CurrentWindow].OnGUI, "", windowStyle);
  117. }
  118. if (MessageWindowVisible)
  119. {
  120. messageWindowRect.width = Mathf.Clamp(Screen.width * 0.4f, 440, Mathf.Infinity);
  121. messageWindowRect.height = Mathf.Clamp(Screen.height * 0.15f, 150, Mathf.Infinity);
  122. messageWindowRect.x = Mathf.Clamp(messageWindowRect.x, -messageWindowRect.width + Utility.GetPix(20), Screen.width - Utility.GetPix(20));
  123. messageWindowRect.y = Mathf.Clamp(messageWindowRect.y, -messageWindowRect.height + Utility.GetPix(20), Screen.height - Utility.GetPix(20));
  124. if (!initializeWindows)
  125. {
  126. messageWindowRect.x = Screen.width / 2 - messageWindowRect.width / 2;
  127. messageWindowRect.y = Screen.height - messageWindowRect.height;
  128. initializeWindows = true;
  129. }
  130. messageWindowRect = GUI.Window(Constants.messageWindowID, messageWindowRect, Windows[Window.Message].OnGUI, "", windowStyle);
  131. }
  132. if (DropdownVisible) DropdownHelper.HandleDropdown();
  133. }
  134. }
  135. }