HierarchyWindow.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using bs;
  4. namespace bs.Editor
  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 GUIScrollArea treeScrollArea;
  15. private GUISceneTreeView treeView;
  16. private GUILayout progressLayout;
  17. private GUIProgressBar loadProgressBar;
  18. private GUILabel loadLabel;
  19. private bool loadingProgressShown = false;
  20. /// <summary>
  21. /// Opens the hierarchy window.
  22. /// </summary>
  23. [MenuItem("Windows/Hierarchy", ButtonModifier.CtrlAlt, ButtonCode.H, 6000)]
  24. private static void OpenHierarchyWindow()
  25. {
  26. OpenWindow<HierarchyWindow>();
  27. }
  28. /// <inheritdoc/>
  29. protected override LocString GetDisplayName()
  30. {
  31. return new LocEdString("Hierarchy");
  32. }
  33. /// <inheritdoc/>
  34. void IGlobalShortcuts.OnDeletePressed()
  35. {
  36. treeView.DeleteSelection();
  37. }
  38. /// <inheritdoc/>
  39. void IGlobalShortcuts.OnRenamePressed()
  40. {
  41. treeView.RenameSelection();
  42. }
  43. /// <inheritdoc/>
  44. void IGlobalShortcuts.OnDuplicatePressed()
  45. {
  46. treeView.DuplicateSelection();
  47. }
  48. /// <inheritdoc/>
  49. void IGlobalShortcuts.OnCopyPressed()
  50. {
  51. treeView.CopySelection();
  52. }
  53. /// <inheritdoc/>
  54. void IGlobalShortcuts.OnCutPressed()
  55. {
  56. treeView.CutSelection();
  57. }
  58. /// <inheritdoc/>
  59. void IGlobalShortcuts.OnPastePressed()
  60. {
  61. treeView.PasteToSelection();
  62. }
  63. private void OnInitialize()
  64. {
  65. treeScrollArea = new GUIScrollArea();
  66. GUI.AddElement(treeScrollArea);
  67. treeView = new GUISceneTreeView(GUIOption.FlexibleHeight(20), GUIOption.FlexibleWidth(20));
  68. treeScrollArea.Layout.AddElement(treeView);
  69. // Loading progress
  70. loadLabel = new GUILabel(new LocEdString("Loading scene..."));
  71. loadProgressBar = new GUIProgressBar();
  72. progressLayout = GUI.AddLayoutY();
  73. progressLayout.AddFlexibleSpace();
  74. GUILayout loadLabelLayout = progressLayout.AddLayoutX();
  75. loadLabelLayout.AddFlexibleSpace();
  76. loadLabelLayout.AddElement(loadLabel);
  77. loadLabelLayout.AddFlexibleSpace();
  78. GUILayout progressBarLayout = progressLayout.AddLayoutX();
  79. progressBarLayout.AddFlexibleSpace();
  80. progressBarLayout.AddElement(loadProgressBar);
  81. progressBarLayout.AddFlexibleSpace();
  82. progressLayout.AddFlexibleSpace();
  83. progressLayout.Active = false;
  84. EditorVirtualInput.OnButtonUp += OnButtonUp;
  85. }
  86. private void OnEditorUpdate()
  87. {
  88. UpdateLoadingProgress();
  89. treeView.Update();
  90. }
  91. private void OnDestroy()
  92. {
  93. EditorVirtualInput.OnButtonUp -= OnButtonUp;
  94. }
  95. /// <summary>
  96. /// Checks if the load progress bar needs to be shown, shows/hides it and updates the progress accordingly.
  97. /// </summary>
  98. private void UpdateLoadingProgress()
  99. {
  100. bool needsProgress = EditorApplication.IsSceneLoading;
  101. if (needsProgress && !loadingProgressShown)
  102. {
  103. progressLayout.Active = true;
  104. treeScrollArea.Active = false;
  105. loadingProgressShown = true;
  106. }
  107. else if(!needsProgress && loadingProgressShown)
  108. {
  109. progressLayout.Active = false;
  110. treeScrollArea.Active = true;
  111. loadingProgressShown = false;
  112. }
  113. if (needsProgress)
  114. loadProgressBar.Percent = EditorApplication.SceneLoadProgress;
  115. }
  116. /// <summary>
  117. /// Triggered when the user presses a virtual button.
  118. /// </summary>
  119. /// <param name="btn">Button that was pressed.</param>
  120. /// <param name="deviceIdx">Index of the device it was pressed on. </param>
  121. private void OnButtonUp(VirtualButton btn, int deviceIdx)
  122. {
  123. if (!HasFocus)
  124. return;
  125. IGlobalShortcuts shortcuts = this;
  126. if (btn == EditorApplication.CopyKey)
  127. shortcuts.OnCopyPressed();
  128. else if (btn == EditorApplication.CutKey)
  129. shortcuts.OnCutPressed();
  130. else if (btn == EditorApplication.PasteKey)
  131. shortcuts.OnPastePressed();
  132. else if (btn == EditorApplication.DuplicateKey)
  133. shortcuts.OnDuplicatePressed();
  134. else if (btn == EditorApplication.RenameKey)
  135. shortcuts.OnRenamePressed();
  136. else if (btn == EditorApplication.DeleteKey)
  137. shortcuts.OnDeletePressed();
  138. else if(btn == EditorApplication.PasteKey)
  139. shortcuts.OnPastePressed();
  140. }
  141. }
  142. /** @} */
  143. }