SettingsWindow.cs 4.5 KB

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