SceneManagerDirectoryPane.cs 4.1 KB

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