MainWindow.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 ReloadTranslationButton;
  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. ReloadTranslationButton = new Button("Reload Translation");
  45. ReloadTranslationButton.ControlEvent += (s, a) =>
  46. {
  47. Translation.ReinitializeTranslation();
  48. };
  49. }
  50. public override void Activate()
  51. {
  52. this.updating = true;
  53. tabsPane.SelectedTab = Constants.Window.Call;
  54. this.updating = false;
  55. this.Visible = true;
  56. }
  57. public void AddWindow(Constants.Window id, BaseMainWindowPane window)
  58. {
  59. if (windowPanes.ContainsKey(id))
  60. {
  61. Panes.Remove(windowPanes[id]);
  62. }
  63. windowPanes[id] = window;
  64. windowPanes[id].SetTabsPane(tabsPane);
  65. Panes.Add(windowPanes[id]);
  66. }
  67. private void ChangeTab()
  68. {
  69. this.selectedWindow = (Constants.Window)tabsPane.SelectedTab;
  70. SetCurrentWindow();
  71. }
  72. private void SetCurrentWindow()
  73. {
  74. if (currentWindowPane != null) currentWindowPane.ActiveWindow = false;
  75. currentWindowPane = windowPanes[selectedWindow];
  76. currentWindowPane.ActiveWindow = true;
  77. currentWindowPane.UpdatePanes();
  78. }
  79. public override void Update()
  80. {
  81. base.Update();
  82. if (InputManager.GetKeyDown(MpsKey.ToggleUI))
  83. {
  84. this.Visible = !this.Visible;
  85. }
  86. }
  87. public override void Draw()
  88. {
  89. currentWindowPane?.Draw();
  90. GUI.enabled = true;
  91. GUILayout.FlexibleSpace();
  92. ReloadTranslationButton.Draw();
  93. GUIStyle labelStyle = new GUIStyle(GUI.skin.label);
  94. labelStyle.fontSize = 10;
  95. labelStyle.alignment = TextAnchor.LowerLeft;
  96. GUILayout.Label(MeidoPhotoStudio.pluginString, labelStyle);
  97. GUI.DragWindow();
  98. }
  99. private void UpdateMeido(object sender, MeidoUpdateEventArgs args)
  100. {
  101. if (args.FromMeido)
  102. {
  103. Constants.Window newWindow = args.IsBody ? Constants.Window.Pose : Constants.Window.Face;
  104. ChangeWindow(newWindow);
  105. }
  106. else currentWindowPane.UpdatePanes();
  107. }
  108. private void ChangeWindow(Constants.Window window)
  109. {
  110. if (this.selectedWindow == window) currentWindowPane.UpdatePanes();
  111. else tabsPane.SelectedTab = window;
  112. }
  113. }
  114. }