SceneManagerTitleBar.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using UnityEngine;
  2. namespace COM3D2.MeidoPhotoStudio.Plugin
  3. {
  4. internal class SceneManagerTitleBarPane : BasePane
  5. {
  6. public event System.EventHandler closeChange;
  7. private SceneManager sceneManager;
  8. private Button kankyoToggle;
  9. private Button refreshButton;
  10. private Dropdown sortDropdown;
  11. private Toggle descendingToggle;
  12. private Button closeButton;
  13. private string sortLabel;
  14. private static readonly string[] sortModes = new[] { "sortName", "sortCreated", "sortModified" };
  15. public SceneManagerTitleBarPane(SceneManager sceneManager)
  16. {
  17. this.sceneManager = sceneManager;
  18. kankyoToggle = new Button(Translation.Get("sceneManager", "kankyoToggle"));
  19. kankyoToggle.ControlEvent += (s, a) => sceneManager.ToggleKankyoMode();
  20. refreshButton = new Button(Translation.Get("sceneManager", "refreshButton"));
  21. refreshButton.ControlEvent += (s, a) => sceneManager.Refresh();
  22. sortDropdown = new Dropdown(
  23. Translation.GetArray("sceneManager", sortModes), (int)sceneManager.CurrentSortMode
  24. );
  25. sortDropdown.SelectionChange += (s, a) =>
  26. {
  27. SceneManager.SortMode sortMode = (SceneManager.SortMode)sortDropdown.SelectedItemIndex;
  28. if (sceneManager.CurrentSortMode == sortMode) return;
  29. sceneManager.SortScenes(sortMode);
  30. };
  31. descendingToggle = new Toggle(
  32. Translation.Get("sceneManager", "descendingToggle"), sceneManager.SortDescending
  33. );
  34. descendingToggle.ControlEvent += (s, a) =>
  35. {
  36. sceneManager.SortDescending = descendingToggle.Value;
  37. sceneManager.SortScenes(sceneManager.CurrentSortMode);
  38. };
  39. closeButton = new Button("X");
  40. closeButton.ControlEvent += (s, a) => closeChange?.Invoke(this, System.EventArgs.Empty);
  41. sortLabel = Translation.Get("sceneManager", "sortLabel");
  42. }
  43. protected override void ReloadTranslation()
  44. {
  45. kankyoToggle.Label = Translation.Get("sceneManager", "kankyoToggle");
  46. refreshButton.Label = Translation.Get("sceneManager", "refreshButton");
  47. sortDropdown.SetDropdownItems(Translation.GetArray("sceneManager", sortModes));
  48. descendingToggle.Label = Translation.Get("sceneManager", "descendingToggle");
  49. sortLabel = Translation.Get("sceneManager", "sortLabel");
  50. }
  51. public override void Draw()
  52. {
  53. GUIStyle buttonStyle = new GUIStyle(GUI.skin.button);
  54. buttonStyle.fontSize = Utility.GetPix(12);
  55. GUILayoutOption buttonHeight = GUILayout.Height(Utility.GetPix(20));
  56. GUILayout.BeginHorizontal();
  57. GUILayout.BeginHorizontal(GUILayout.Width(Utility.GetPix(SceneManagerDirectoryPane.listWidth)));
  58. Color originalColour = GUI.backgroundColor;
  59. if (sceneManager.KankyoMode) GUI.backgroundColor = Color.green;
  60. kankyoToggle.Draw(buttonStyle, buttonHeight);
  61. GUI.backgroundColor = originalColour;
  62. GUILayout.FlexibleSpace();
  63. refreshButton.Draw(buttonStyle, buttonHeight);
  64. GUILayout.EndHorizontal();
  65. GUILayout.BeginHorizontal();
  66. GUILayout.Space(Utility.GetPix(15));
  67. GUIStyle labelStyle = new GUIStyle(GUI.skin.label);
  68. labelStyle.fontSize = buttonStyle.fontSize;
  69. GUILayout.Label(sortLabel, labelStyle);
  70. GUIStyle dropdownStyle = new GUIStyle(DropdownHelper.DefaultDropdownStyle);
  71. dropdownStyle.fontSize = buttonStyle.fontSize;
  72. sortDropdown.Draw(buttonStyle, dropdownStyle, buttonHeight, GUILayout.Width(Utility.GetPix(100)));
  73. GUIStyle toggleStyle = new GUIStyle(GUI.skin.toggle);
  74. toggleStyle.fontSize = buttonStyle.fontSize;
  75. descendingToggle.Draw(toggleStyle);
  76. GUILayout.FlexibleSpace();
  77. closeButton.Draw();
  78. GUILayout.EndHorizontal();
  79. GUILayout.EndHorizontal();
  80. }
  81. }
  82. }