TabsPane.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using UnityEngine;
  3. namespace MeidoPhotoStudio.Plugin;
  4. public class TabsPane : BasePane
  5. {
  6. private static readonly string[] tabNames = { "call", "pose", "face", "bg", "bg2" };
  7. private readonly SelectionGrid Tabs;
  8. public event EventHandler TabChange;
  9. private Constants.Window selectedTab;
  10. public Constants.Window SelectedTab
  11. {
  12. get => selectedTab;
  13. set => Tabs.SelectedItemIndex = (int)value;
  14. }
  15. public TabsPane()
  16. {
  17. Translation.ReloadTranslationEvent += (_, _) =>
  18. ReloadTranslation();
  19. Tabs = new(Translation.GetArray("tabs", tabNames));
  20. Tabs.ControlEvent += (_, _) =>
  21. OnChangeTab();
  22. }
  23. public override void Draw()
  24. {
  25. Tabs.Draw(GUILayout.ExpandWidth(false));
  26. MpsGui.BlackLine();
  27. }
  28. protected override void ReloadTranslation()
  29. {
  30. updating = true;
  31. Tabs.SetItems(Translation.GetArray("tabs", tabNames), Tabs.SelectedItemIndex);
  32. updating = false;
  33. }
  34. private void OnChangeTab()
  35. {
  36. if (updating)
  37. return;
  38. selectedTab = (Constants.Window)Tabs.SelectedItemIndex;
  39. TabChange?.Invoke(null, EventArgs.Empty);
  40. }
  41. }