HierarchyWindow.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using BansheeEngine;
  4. namespace BansheeEditor
  5. {
  6. /// <summary>
  7. /// Editor window that displays the scene hierarchy tree view, displaying all scene objects in the current scene.
  8. /// </summary>
  9. public class HierarchyWindow : EditorWindow, IGlobalShortcuts
  10. {
  11. private GUISceneTreeView treeView;
  12. /// <summary>
  13. /// Opens the hierarchy window.
  14. /// </summary>
  15. [MenuItem("Windows/Hierarchy", ButtonModifier.CtrlAlt, ButtonCode.H, 6000)]
  16. private static void OpenHierarchyWindow()
  17. {
  18. OpenWindow<HierarchyWindow>();
  19. }
  20. /// <inheritdoc/>
  21. protected override LocString GetDisplayName()
  22. {
  23. return new LocEdString("Hierarchy");
  24. }
  25. /// <inheritdoc/>
  26. void IGlobalShortcuts.OnDeletePressed()
  27. {
  28. treeView.DeleteSelection();
  29. }
  30. /// <inheritdoc/>
  31. void IGlobalShortcuts.OnRenamePressed()
  32. {
  33. treeView.RenameSelection();
  34. }
  35. /// <inheritdoc/>
  36. void IGlobalShortcuts.OnDuplicatePressed()
  37. {
  38. treeView.DuplicateSelection();
  39. }
  40. /// <inheritdoc/>
  41. void IGlobalShortcuts.OnCopyPressed()
  42. {
  43. treeView.CopySelection();
  44. }
  45. /// <inheritdoc/>
  46. void IGlobalShortcuts.OnCutPressed()
  47. {
  48. treeView.CutSelection();
  49. }
  50. /// <inheritdoc/>
  51. void IGlobalShortcuts.OnPastePressed()
  52. {
  53. treeView.PasteToSelection();
  54. }
  55. private void OnInitialize()
  56. {
  57. GUIScrollArea scrollArea = new GUIScrollArea();
  58. GUI.AddElement(scrollArea);
  59. treeView = new GUISceneTreeView(GUIOption.FlexibleHeight(20), GUIOption.FlexibleWidth(20));
  60. scrollArea.Layout.AddElement(treeView);
  61. EditorVirtualInput.OnButtonUp += OnButtonUp;
  62. }
  63. private void OnEditorUpdate()
  64. {
  65. treeView.Update();
  66. }
  67. private void OnDestroy()
  68. {
  69. EditorVirtualInput.OnButtonUp -= OnButtonUp;
  70. }
  71. /// <summary>
  72. /// Triggered when the user presses a virtual button.
  73. /// </summary>
  74. /// <param name="btn">Button that was pressed.</param>
  75. /// <param name="deviceIdx">Index of the device it was pressed on. </param>
  76. private void OnButtonUp(VirtualButton btn, int deviceIdx)
  77. {
  78. if (!HasFocus)
  79. return;
  80. IGlobalShortcuts shortcuts = this;
  81. if (btn == EditorApplication.CopyKey)
  82. shortcuts.OnCopyPressed();
  83. else if (btn == EditorApplication.CutKey)
  84. shortcuts.OnCutPressed();
  85. else if (btn == EditorApplication.PasteKey)
  86. shortcuts.OnPastePressed();
  87. else if (btn == EditorApplication.DuplicateKey)
  88. shortcuts.OnDuplicatePressed();
  89. else if (btn == EditorApplication.RenameKey)
  90. shortcuts.OnRenamePressed();
  91. else if (btn == EditorApplication.DeleteKey)
  92. shortcuts.OnDeletePressed();
  93. else if(btn == EditorApplication.PasteKey)
  94. shortcuts.OnPastePressed();
  95. }
  96. }
  97. }