HierarchyWindow.cs 3.5 KB

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