MainWindow.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. namespace COM3D2.MeidoPhotoStudio.Plugin
  4. {
  5. internal class MainWindow : BaseWindow
  6. {
  7. private MeidoManager meidoManager;
  8. private PropManager propManager;
  9. private LightManager lightManager;
  10. private Dictionary<Constants.Window, BaseMainWindowPane> windowPanes;
  11. private TabsPane tabsPane;
  12. private Button settingsButton;
  13. private BaseMainWindowPane currentWindowPane;
  14. public override Rect WindowRect
  15. {
  16. set
  17. {
  18. value.width = 240f;
  19. value.height = Screen.height * 0.9f;
  20. value.x = Mathf.Clamp(value.x, 0, Screen.width - value.width);
  21. value.y = Mathf.Clamp(value.y, -value.height + 30, Screen.height - 50);
  22. windowRect = value;
  23. }
  24. }
  25. private Constants.Window selectedWindow = Constants.Window.Call;
  26. public BaseMainWindowPane this[Constants.Window id]
  27. {
  28. get => windowPanes[id];
  29. set => AddWindow(id, value);
  30. }
  31. // TODO: Find a better way of doing this
  32. public MainWindow(MeidoManager meidoManager, PropManager propManager, LightManager lightManager) : base()
  33. {
  34. this.meidoManager = meidoManager;
  35. this.meidoManager.UpdateMeido += UpdateMeido;
  36. this.propManager = propManager;
  37. this.propManager.DoguSelectChange += (s, a) => ChangeWindow(Constants.Window.BG2);
  38. this.lightManager = lightManager;
  39. this.lightManager.Select += (s, a) => ChangeWindow(Constants.Window.BG);
  40. windowPanes = new Dictionary<Constants.Window, BaseMainWindowPane>();
  41. WindowRect = new Rect(Screen.width, Screen.height * 0.08f, 240f, Screen.height * 0.9f);
  42. tabsPane = new TabsPane();
  43. tabsPane.TabChange += (s, a) => ChangeTab();
  44. settingsButton = new Button("Settings");
  45. settingsButton.ControlEvent += (s, a) =>
  46. {
  47. if (selectedWindow == Constants.Window.Settings) ChangeTab();
  48. else
  49. {
  50. settingsButton.Label = "Close";
  51. SetCurrentWindow(Constants.Window.Settings);
  52. }
  53. };
  54. }
  55. public override void Activate()
  56. {
  57. this.updating = true;
  58. tabsPane.SelectedTab = Constants.Window.Call;
  59. this.updating = false;
  60. this.Visible = true;
  61. }
  62. public void AddWindow(Constants.Window id, BaseMainWindowPane window)
  63. {
  64. if (windowPanes.ContainsKey(id))
  65. {
  66. Panes.Remove(windowPanes[id]);
  67. }
  68. windowPanes[id] = window;
  69. windowPanes[id].SetTabsPane(tabsPane);
  70. Panes.Add(windowPanes[id]);
  71. }
  72. private void ChangeTab()
  73. {
  74. settingsButton.Label = "Settings";
  75. SetCurrentWindow(tabsPane.SelectedTab);
  76. }
  77. private void SetCurrentWindow(Constants.Window window)
  78. {
  79. if (currentWindowPane != null) currentWindowPane.ActiveWindow = false;
  80. selectedWindow = window;
  81. currentWindowPane = windowPanes[selectedWindow];
  82. currentWindowPane.ActiveWindow = true;
  83. currentWindowPane.UpdatePanes();
  84. }
  85. public override void Update()
  86. {
  87. base.Update();
  88. if (InputManager.GetKeyDown(MpsKey.ToggleUI))
  89. {
  90. this.Visible = !this.Visible;
  91. }
  92. }
  93. public override void Draw()
  94. {
  95. currentWindowPane?.Draw();
  96. GUI.enabled = true;
  97. GUILayout.FlexibleSpace();
  98. GUIStyle labelStyle = new GUIStyle(GUI.skin.label)
  99. {
  100. fontSize = 10,
  101. alignment = TextAnchor.LowerLeft
  102. };
  103. GUILayout.BeginHorizontal();
  104. GUILayout.Label(MeidoPhotoStudio.pluginString, labelStyle);
  105. GUILayout.FlexibleSpace();
  106. settingsButton.Draw(GUILayout.ExpandWidth(false));
  107. GUILayout.EndHorizontal();
  108. GUI.DragWindow();
  109. }
  110. private void UpdateMeido(object sender, MeidoUpdateEventArgs args)
  111. {
  112. if (args.FromMeido)
  113. {
  114. Constants.Window newWindow = args.IsBody ? Constants.Window.Pose : Constants.Window.Face;
  115. ChangeWindow(newWindow);
  116. }
  117. else currentWindowPane.UpdatePanes();
  118. }
  119. private void ChangeWindow(Constants.Window window)
  120. {
  121. if (this.selectedWindow == window) currentWindowPane.UpdatePanes();
  122. else tabsPane.SelectedTab = window;
  123. }
  124. }
  125. }