SceneManagerDirectoryPane.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using UnityEngine;
  2. namespace COM3D2.MeidoPhotoStudio.Plugin
  3. {
  4. public class SceneManagerDirectoryPane : BasePane
  5. {
  6. public static readonly int listWidth = 200;
  7. private readonly SceneManager sceneManager;
  8. private readonly SceneModalWindow sceneModalWindow;
  9. private readonly Button createDirectoryButton;
  10. private readonly Button deleteDirectoryButton;
  11. private readonly TextField directoryTextField;
  12. private readonly Button cancelButton;
  13. private readonly Texture2D selectedTexture = Utility.MakeTex(2, 2, new Color(0.5f, 0.5f, 0.5f, 0.4f));
  14. private Vector2 listScrollPos;
  15. private bool createDirectoryMode;
  16. public SceneManagerDirectoryPane(SceneManager sceneManager, SceneModalWindow sceneModalWindow)
  17. {
  18. this.sceneManager = sceneManager;
  19. this.sceneModalWindow = sceneModalWindow;
  20. createDirectoryButton = new Button(Translation.Get("sceneManager", "createDirectoryButton"));
  21. createDirectoryButton.ControlEvent += (s, a) => createDirectoryMode = true;
  22. deleteDirectoryButton = new Button(Translation.Get("sceneManager", "deleteDirectoryButton"));
  23. deleteDirectoryButton.ControlEvent += (s, a) => this.sceneModalWindow.ShowDirectoryDialogue();
  24. directoryTextField = new TextField();
  25. directoryTextField.ControlEvent += (s, a) =>
  26. {
  27. sceneManager.AddDirectory(directoryTextField.Value);
  28. createDirectoryMode = false;
  29. directoryTextField.Value = string.Empty;
  30. };
  31. cancelButton = new Button("X");
  32. cancelButton.ControlEvent += (s, a) => createDirectoryMode = false;
  33. }
  34. protected override void ReloadTranslation()
  35. {
  36. createDirectoryButton.Label = Translation.Get("sceneManager", "createDirectoryButton");
  37. deleteDirectoryButton.Label = Translation.Get("sceneManager", "deleteDirectoryButton");
  38. }
  39. public override void Draw()
  40. {
  41. GUIStyle directoryStyle = new GUIStyle(GUI.skin.button)
  42. {
  43. fontSize = Utility.GetPix(12),
  44. alignment = TextAnchor.MiddleLeft,
  45. margin = new RectOffset(0, 0, 0, 0)
  46. };
  47. GUIStyle directorySelectedStyle = new GUIStyle(directoryStyle);
  48. directorySelectedStyle.normal.textColor = Color.white;
  49. directorySelectedStyle.normal.background = selectedTexture;
  50. directorySelectedStyle.hover.background = selectedTexture;
  51. GUILayout.BeginVertical(GUILayout.Width(Utility.GetPix(listWidth)));
  52. listScrollPos = GUILayout.BeginScrollView(listScrollPos);
  53. for (int i = 0; i < sceneManager.CurrentDirectoryList.Count; i++)
  54. {
  55. GUIStyle style = i == sceneManager.CurrentDirectoryIndex ? directorySelectedStyle : directoryStyle;
  56. string directoryName = sceneManager.CurrentDirectoryList[i];
  57. if (GUILayout.Button(directoryName, style, GUILayout.Height(Utility.GetPix(20))))
  58. {
  59. sceneManager.SelectDirectory(i);
  60. }
  61. }
  62. GUILayout.EndScrollView();
  63. GUILayout.BeginHorizontal();
  64. GUIStyle buttonStyle = new GUIStyle(GUI.skin.button) { fontSize = Utility.GetPix(12) };
  65. GUILayoutOption buttonHeight = GUILayout.Height(Utility.GetPix(20));
  66. if (createDirectoryMode)
  67. {
  68. directoryTextField.Draw(buttonHeight, GUILayout.Width(Utility.GetPix(listWidth - 30)));
  69. cancelButton.Draw(buttonStyle, buttonHeight, GUILayout.ExpandWidth(false));
  70. }
  71. else
  72. {
  73. createDirectoryButton.Draw(buttonStyle, buttonHeight);
  74. GUI.enabled = sceneManager.CurrentDirectoryIndex > 0;
  75. deleteDirectoryButton.Draw(buttonStyle, buttonHeight, GUILayout.ExpandWidth(false));
  76. GUI.enabled = true;
  77. }
  78. GUILayout.EndHorizontal();
  79. GUILayout.EndVertical();
  80. }
  81. }
  82. }