MainWindow.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace COM3D2.MeidoPhotoStudio.Plugin
  5. {
  6. internal class MainWindow : BaseWindow
  7. {
  8. private MeidoManager meidoManager;
  9. private Dictionary<Constants.Window, BaseWindowPane> windowPanes;
  10. private TabsPane tabsPane;
  11. private Button ReloadTranslationButton;
  12. private BaseWindowPane currentWindowPane;
  13. public override Rect WindowRect
  14. {
  15. get
  16. {
  17. windowRect.width = 240f;
  18. windowRect.height = Screen.height * 0.9f;
  19. windowRect.x = Mathf.Clamp(windowRect.x, 0, Screen.width - windowRect.width);
  20. windowRect.y = Mathf.Clamp(windowRect.y, -windowRect.height + 30, Screen.height - 50);
  21. return windowRect;
  22. }
  23. set => windowRect = value;
  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. public MainWindow(MeidoManager meidoManager) : base()
  32. {
  33. this.meidoManager = meidoManager;
  34. this.meidoManager.UpdateMeido += UpdateMeido;
  35. windowPanes = new Dictionary<Constants.Window, BaseWindowPane>();
  36. windowRect = new Rect(Screen.width, Screen.height * 0.08f, 230f, Screen.height * 0.9f);
  37. tabsPane = new TabsPane();
  38. tabsPane.TabChange += (s, a) => ChangeTab();
  39. ReloadTranslationButton = new Button("Reload Translation");
  40. ReloadTranslationButton.ControlEvent += (s, a) =>
  41. {
  42. Translation.ReloadTranslation();
  43. };
  44. }
  45. public override void Activate()
  46. {
  47. this.updating = true;
  48. tabsPane.SelectedTab = Constants.Window.Call;
  49. this.updating = false;
  50. this.Visible = true;
  51. }
  52. public void AddWindow(Constants.Window id, BaseWindowPane window)
  53. {
  54. if (windowPanes.ContainsKey(id))
  55. {
  56. Panes.Remove(windowPanes[id]);
  57. }
  58. windowPanes[id] = window;
  59. Panes.Add(windowPanes[id]);
  60. }
  61. private void ChangeTab()
  62. {
  63. this.selectedWindow = (Constants.Window)tabsPane.SelectedTab;
  64. SetCurrentWindow();
  65. }
  66. private void SetCurrentWindow()
  67. {
  68. if (currentWindowPane != null) currentWindowPane.ActiveWindow = false;
  69. currentWindowPane = windowPanes[selectedWindow];
  70. currentWindowPane.ActiveWindow = true;
  71. currentWindowPane.UpdatePanes();
  72. }
  73. public override void Update()
  74. {
  75. base.Update();
  76. if (Input.GetKeyDown(KeyCode.Tab))
  77. {
  78. this.Visible = !this.Visible;
  79. }
  80. }
  81. public override void Draw()
  82. {
  83. tabsPane.Draw();
  84. currentWindowPane?.Draw();
  85. GUI.enabled = true;
  86. GUILayout.FlexibleSpace();
  87. ReloadTranslationButton.Draw();
  88. GUIStyle labelStyle = new GUIStyle(GUI.skin.label);
  89. labelStyle.fontSize = 10;
  90. labelStyle.alignment = TextAnchor.LowerLeft;
  91. GUILayout.Label("MeidoPhotoStudio 1.0.0", labelStyle);
  92. GUI.DragWindow();
  93. }
  94. private void UpdateMeido(object sender, MeidoUpdateEventArgs args)
  95. {
  96. if (args.FromMeido)
  97. {
  98. Constants.Window newWindow = args.IsBody ? Constants.Window.Pose : Constants.Window.Face;
  99. if (this.selectedWindow == newWindow) currentWindowPane.UpdatePanes();
  100. else tabsPane.SelectedTab = newWindow;
  101. }
  102. else currentWindowPane.UpdatePanes();
  103. }
  104. }
  105. }