SceneManagerTitleBar.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using UnityEngine;
  2. namespace COM3D2.MeidoPhotoStudio.Plugin
  3. {
  4. public class SceneManagerTitleBarPane : BasePane
  5. {
  6. private static readonly string[] sortModes = new[] { "sortName", "sortCreated", "sortModified" };
  7. private readonly SceneManager sceneManager;
  8. private readonly Button kankyoToggle;
  9. private readonly Button refreshButton;
  10. private readonly Dropdown sortDropdown;
  11. private readonly Toggle descendingToggle;
  12. private readonly Button closeButton;
  13. private string sortLabel;
  14. public event System.EventHandler CloseChange;
  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) { fontSize = Utility.GetPix(12) };
  54. GUILayoutOption buttonHeight = GUILayout.Height(Utility.GetPix(20));
  55. GUILayout.BeginHorizontal();
  56. GUILayout.BeginHorizontal(GUILayout.Width(Utility.GetPix(SceneManagerDirectoryPane.listWidth)));
  57. Color originalColour = GUI.backgroundColor;
  58. if (sceneManager.KankyoMode) GUI.backgroundColor = Color.green;
  59. kankyoToggle.Draw(buttonStyle, buttonHeight);
  60. GUI.backgroundColor = originalColour;
  61. GUILayout.FlexibleSpace();
  62. refreshButton.Draw(buttonStyle, buttonHeight);
  63. GUILayout.EndHorizontal();
  64. GUILayout.BeginHorizontal();
  65. GUILayout.Space(Utility.GetPix(15));
  66. GUIStyle labelStyle = new GUIStyle(GUI.skin.label) { fontSize = buttonStyle.fontSize };
  67. GUILayout.Label(sortLabel, labelStyle);
  68. GUIStyle dropdownStyle = new GUIStyle(DropdownHelper.DefaultDropdownStyle)
  69. {
  70. fontSize = buttonStyle.fontSize
  71. };
  72. sortDropdown.Draw(buttonStyle, dropdownStyle, buttonHeight, GUILayout.Width(Utility.GetPix(100)));
  73. GUIStyle toggleStyle = new GUIStyle(GUI.skin.toggle) { fontSize = buttonStyle.fontSize };
  74. descendingToggle.Draw(toggleStyle);
  75. GUILayout.FlexibleSpace();
  76. closeButton.Draw();
  77. GUILayout.EndHorizontal();
  78. GUILayout.EndHorizontal();
  79. }
  80. }
  81. }