SettingsWindow.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System;
  2. using BansheeEngine;
  3. namespace BansheeEditor
  4. {
  5. /// <summary>
  6. /// Displays project and editor settings
  7. /// </summary>
  8. [DefaultSize(300, 200)]
  9. internal sealed class SettingsWindow : EditorWindow
  10. {
  11. internal const string ActiveCodeEditorKey = "__ActiveCodeEditor";
  12. private GUIFloatField defaultHandleSizeField;
  13. private GUIToggleField autoLoadLastProjectField;
  14. private GUIListBoxField codeEditorField;
  15. /// <summary>
  16. /// Opens the settings window if its not open already.
  17. /// </summary>
  18. [MenuItem("Tools/Settings", 9297, true)]
  19. private static void OpenSettingsWindow()
  20. {
  21. OpenWindow<SettingsWindow>();
  22. }
  23. /// <inheritdoc/>
  24. protected override LocString GetDisplayName()
  25. {
  26. return new LocEdString("Settings");
  27. }
  28. private void OnInitialize()
  29. {
  30. GUIToggle projectFoldout = new GUIToggle(new LocEdString("Project"), EditorStyles.Foldout);
  31. GUIToggle editorFoldout = new GUIToggle(new LocEdString("Editor"), EditorStyles.Foldout);
  32. defaultHandleSizeField = new GUIFloatField(new LocEdString("Handle size"), 200);
  33. defaultHandleSizeField.OnChanged += (x) => { EditorSettings.DefaultHandleSize = x; };
  34. autoLoadLastProjectField = new GUIToggleField(new LocEdString("Automatically load last project"), 200);
  35. autoLoadLastProjectField.OnChanged += (x) => { EditorSettings.AutoLoadLastProject = x; };
  36. CodeEditorType[] availableEditors = CodeEditor.AvailableEditors;
  37. Array.Resize(ref availableEditors, availableEditors.Length + 1);
  38. availableEditors[availableEditors.Length - 1] = CodeEditorType.None;
  39. string[] availableEditorNames = new string[availableEditors.Length];
  40. for (int i = 0; i < availableEditors.Length; i++)
  41. availableEditorNames[i] = Enum.GetName(typeof (CodeEditorType), availableEditors[i]);
  42. codeEditorField = new GUIListBoxField(availableEditorNames, new LocEdString("Code editor"), 200);
  43. codeEditorField.OnSelectionChanged += x =>
  44. {
  45. EditorSettings.SetInt(ActiveCodeEditorKey, (int)availableEditors[x]);
  46. CodeEditor.ActiveEditor = availableEditors[x];
  47. };
  48. GUILayout mainLayout = GUI.AddLayoutY();
  49. mainLayout.AddElement(projectFoldout);
  50. GUILayout projectLayoutOuterY = mainLayout.AddLayoutY();
  51. projectLayoutOuterY.AddSpace(5);
  52. GUILayout projectLayoutOuterX = projectLayoutOuterY.AddLayoutX();
  53. projectLayoutOuterX.AddSpace(5);
  54. GUILayout projectLayout = projectLayoutOuterX.AddLayoutY();
  55. projectLayoutOuterX.AddSpace(5);
  56. projectLayoutOuterY.AddSpace(5);
  57. mainLayout.AddElement(editorFoldout);
  58. GUILayout editorLayoutOuterY = mainLayout.AddLayoutY();
  59. editorLayoutOuterY.AddSpace(5);
  60. GUILayout editorLayoutOuterX = editorLayoutOuterY.AddLayoutX();
  61. editorLayoutOuterX.AddSpace(5);
  62. GUILayout editorLayout = editorLayoutOuterX.AddLayoutY();
  63. editorLayoutOuterX.AddSpace(5);
  64. editorLayoutOuterY.AddSpace(5);
  65. mainLayout.AddFlexibleSpace();
  66. editorLayout.AddElement(defaultHandleSizeField);
  67. editorLayout.AddElement(autoLoadLastProjectField);
  68. projectFoldout.Value = true;
  69. editorFoldout.Value = true;
  70. projectFoldout.OnToggled += (x) => projectLayout.Active = x;
  71. editorFoldout.OnToggled += (x) => editorLayout.Active = x;
  72. }
  73. private void OnEditorUpdate()
  74. {
  75. defaultHandleSizeField.Value = EditorSettings.DefaultHandleSize;
  76. autoLoadLastProjectField.Value = EditorSettings.AutoLoadLastProject;
  77. CodeEditorType[] availableEditors = CodeEditor.AvailableEditors;
  78. int idx = Array.IndexOf(availableEditors, CodeEditor.ActiveEditor);
  79. if (idx != -1)
  80. codeEditorField.Index = idx;
  81. }
  82. }
  83. }