MainWindow.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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, BaseWindowPane> windowPanes;
  11. private TabsPane tabsPane;
  12. private Button ReloadTranslationButton;
  13. private BaseWindowPane 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 BaseWindowPane 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, BaseWindowPane>();
  41. windowRect = new Rect(Screen.width, Screen.height * 0.08f, 230f, 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. windowRect.width = 240f;
  50. windowRect.height = Screen.height * 0.9f;
  51. }
  52. public override void Activate()
  53. {
  54. this.updating = true;
  55. tabsPane.SelectedTab = Constants.Window.Call;
  56. this.updating = false;
  57. this.Visible = true;
  58. }
  59. public void AddWindow(Constants.Window id, BaseWindowPane window)
  60. {
  61. if (windowPanes.ContainsKey(id))
  62. {
  63. Panes.Remove(windowPanes[id]);
  64. }
  65. windowPanes[id] = window;
  66. Panes.Add(windowPanes[id]);
  67. }
  68. private void ChangeTab()
  69. {
  70. this.selectedWindow = (Constants.Window)tabsPane.SelectedTab;
  71. SetCurrentWindow();
  72. }
  73. private void SetCurrentWindow()
  74. {
  75. if (currentWindowPane != null) currentWindowPane.ActiveWindow = false;
  76. currentWindowPane = windowPanes[selectedWindow];
  77. currentWindowPane.ActiveWindow = true;
  78. currentWindowPane.UpdatePanes();
  79. }
  80. public override void Update()
  81. {
  82. base.Update();
  83. if (Input.GetKeyDown(KeyCode.Tab))
  84. {
  85. this.Visible = !this.Visible;
  86. }
  87. }
  88. public override void Draw()
  89. {
  90. tabsPane.Draw();
  91. currentWindowPane?.Draw();
  92. GUI.enabled = true;
  93. GUILayout.FlexibleSpace();
  94. ReloadTranslationButton.Draw();
  95. GUIStyle labelStyle = new GUIStyle(GUI.skin.label);
  96. labelStyle.fontSize = 10;
  97. labelStyle.alignment = TextAnchor.LowerLeft;
  98. GUILayout.Label(MeidoPhotoStudio.pluginString, labelStyle);
  99. GUI.DragWindow();
  100. }
  101. private void UpdateMeido(object sender, MeidoUpdateEventArgs args)
  102. {
  103. if (args.FromMeido)
  104. {
  105. Constants.Window newWindow = args.IsBody ? Constants.Window.Pose : Constants.Window.Face;
  106. ChangeWindow(newWindow);
  107. }
  108. else currentWindowPane.UpdatePanes();
  109. }
  110. private void ChangeWindow(Constants.Window window)
  111. {
  112. if (this.selectedWindow == window) currentWindowPane.UpdatePanes();
  113. else tabsPane.SelectedTab = window;
  114. }
  115. }
  116. }