BsGUISceneTreeView.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsEditorPrerequisites.h"
  5. #include "GUI/BsGUITreeView.h"
  6. #include "Utility/BsEvent.h"
  7. #include "Utility/BsServiceLocator.h"
  8. namespace bs
  9. {
  10. /** @addtogroup GUI-Editor-Internal
  11. * @{
  12. */
  13. /** Contains SceneObject%s currently involved in a drag and drop operation. */
  14. struct BS_ED_EXPORT DraggedSceneObjects
  15. {
  16. DraggedSceneObjects(UINT32 numObjects);
  17. ~DraggedSceneObjects();
  18. UINT32 numObjects;
  19. HSceneObject* objects;
  20. };
  21. /** GUI element that displays all SceneObject%s in the current scene in the active project in a tree view. */
  22. class BS_ED_EXPORT GUISceneTreeView : public GUITreeView
  23. {
  24. /** Tree element with SceneObject%-specific data. */
  25. struct SceneTreeElement : public GUITreeView::TreeElement
  26. {
  27. SceneTreeElement()
  28. :mId(0), mIsPrefabInstance(false)
  29. { }
  30. HSceneObject mSceneObject;
  31. UINT64 mId;
  32. bool mIsPrefabInstance;
  33. };
  34. public:
  35. /** Returns type name of the GUI element used for finding GUI element styles. */
  36. static const String& getGUITypeName();
  37. /**
  38. * Creates a new resource tree view element.
  39. *
  40. * @param[in] backgroundStyle Name of the style for the tree view background.
  41. * @param[in] elementBtnStyle Name of the style for a normal tree view element.
  42. * @param[in] foldoutBtnStyle Name of the style for a foldout element (for example for a folder).
  43. * @param[in] selectionBackgroundStyle Name of the style for the background of selected elements.
  44. * @param[in] highlightBackgroundStyle Name of the style for the background of highlighted elements.
  45. * @param[in] editBoxStyle Name of the style for element that is being renamed.
  46. * @param[in] dragHighlightStyle Name of the style for the element being dragged over.
  47. * @param[in] dragSepHighlightStyle Name of the style for the separator displayed while dragging an element
  48. * between two other elements.
  49. */
  50. static GUISceneTreeView* create(
  51. const String& backgroundStyle = StringUtil::BLANK, const String& elementBtnStyle = StringUtil::BLANK,
  52. const String& foldoutBtnStyle = StringUtil::BLANK, const String& highlightBackgroundStyle = StringUtil::BLANK,
  53. const String& selectionBackgroundStyle = StringUtil::BLANK, const String& editBoxStyle = StringUtil::BLANK,
  54. const String& dragHighlightStyle = StringUtil::BLANK, const String& dragSepHighlightStyle = StringUtil::BLANK);
  55. /**
  56. * Creates a new resource tree view element.
  57. *
  58. * @param[in] options Options that allow you to control how is the element positioned and
  59. * sized. This will override any similar options set by style.
  60. * @param[in] backgroundStyle Name of the style for the tree view background.
  61. * @param[in] elementBtnStyle Name of the style for a normal tree view element.
  62. * @param[in] foldoutBtnStyle Name of the style for a foldout element (for example for a folder).
  63. * @param[in] highlightBackgroundStyle Name of the style for the background of highlighted elements.
  64. * @param[in] selectionBackgroundStyle Name of the style for the background of selected elements.
  65. * @param[in] editBoxStyle Name of the style for element that is being renamed.
  66. * @param[in] dragHighlightStyle Name of the style for the element being dragged over.
  67. * @param[in] dragSepHighlightStyle Name of the style for the separator displayed while dragging an element
  68. * between two other elements.
  69. */
  70. static GUISceneTreeView* create(const GUIOptions& options,
  71. const String& backgroundStyle = StringUtil::BLANK, const String& elementBtnStyle = StringUtil::BLANK,
  72. const String& foldoutBtnStyle = StringUtil::BLANK, const String& highlightBackgroundStyle = StringUtil::BLANK,
  73. const String& selectionBackgroundStyle = StringUtil::BLANK, const String& editBoxStyle = StringUtil::BLANK,
  74. const String& dragHighlightStyle = StringUtil::BLANK, const String& dragSepHighlightStyle = StringUtil::BLANK);
  75. /** Returns a list of SceneObject&s currently selected (if any). */
  76. Vector<HSceneObject> getSelection() const;
  77. /** Changes the active selection to the provided SceneObject%s. */
  78. void setSelection(const Vector<HSceneObject>& objects);
  79. /** Scrolls to and highlights the selected object (does not select it). */
  80. void ping(const HSceneObject& object);
  81. /** @copydoc GUITreeView::duplicateSelection */
  82. void duplicateSelection() override;
  83. /** @copydoc GUITreeView::copySelection */
  84. void copySelection() override;
  85. /** @copydoc GUITreeView::cutSelection */
  86. void cutSelection() override;
  87. /** @copydoc GUITreeView::paste */
  88. void paste() override;
  89. /** Triggered whenever the selection changes. Call getSelection() to retrieve new selection. */
  90. Event<void()> onSelectionChanged;
  91. /**
  92. * Triggered whenever the scene is modified in any way from within the scene tree view (for example object is
  93. * deleted, added, etc.).
  94. */
  95. Event<void()> onModified;
  96. /**
  97. * Triggered when a resource drag and drop operation finishes over the scene tree view. Provided scene object
  98. * is the tree view element that the operation finished over (or null if none), and the list of paths is the list
  99. * of relative paths of the resources that were dropped.
  100. */
  101. Event<void(const HSceneObject&, const Vector<Path>&)> onResourceDropped;
  102. static const MessageId SELECTION_CHANGED_MSG;
  103. protected:
  104. virtual ~GUISceneTreeView();
  105. protected:
  106. SceneTreeElement mRootElement;
  107. GUISceneTreeView(const String& backgroundStyle, const String& elementBtnStyle,
  108. const String& foldoutBtnStyle, const String& highlightBackgroundStyle, const String& selectionBackgroundStyle,
  109. const String& editBoxStyle, const String& dragHighlightStyle, const String& dragSepHighlightStyle, const GUIDimensions& dimensions);
  110. /**
  111. * Checks it the SceneObject referenced by this tree element changed in any way and updates the tree element. This
  112. * can involve recursing all children and updating them as well.
  113. */
  114. void updateTreeElement(SceneTreeElement* element);
  115. /**
  116. * Triggered when a drag and drop operation that was started by the tree view ends, regardless if it was processed
  117. * or not.
  118. */
  119. void dragAndDropFinalize();
  120. /** @copydoc GUITreeView::getRootElement */
  121. TreeElement& getRootElement() override { return mRootElement; }
  122. /** @copydoc GUITreeView::getRootElementConst */
  123. const TreeElement& getRootElementConst() const override { return mRootElement; }
  124. /** @copydoc GUITreeView::updateTreeElementHierarchy */
  125. void updateTreeElementHierarchy() override;
  126. /** @copydoc GUITreeView::renameTreeElement */
  127. void renameTreeElement(TreeElement* element, const String& name) override;
  128. /** @copydoc GUITreeView::deleteTreeElement */
  129. void deleteTreeElement(TreeElement* element) override;
  130. /** @copydoc GUITreeView::acceptDragAndDrop */
  131. bool acceptDragAndDrop() const override;
  132. /** @copydoc GUITreeView::dragAndDropStart */
  133. void dragAndDropStart(const Vector<TreeElement*>& elements) override;
  134. /** @copydoc GUITreeView::dragAndDropEnded */
  135. void dragAndDropEnded(TreeElement* overTreeElement) override;
  136. /** @copydoc GUITreeView::_acceptDragAndDrop */
  137. bool _acceptDragAndDrop(Vector2I position, UINT32 typeId) const override;
  138. /** @copydoc GUITreeView::selectionChanged */
  139. void selectionChanged() override;
  140. /** Deletes the internal TreeElement representation without actually deleting the referenced SceneObject. */
  141. void deleteTreeElementInternal(TreeElement* element);
  142. /** Attempts to find a tree element referencing the specified scene object. */
  143. SceneTreeElement* findTreeElement(const HSceneObject& so);
  144. /** Creates a new scene object as a child of the currently selected object (if any). */
  145. void createNewSO();
  146. /** Removes all elements from the list used for copy/cut operations. */
  147. void clearCopyList();
  148. /**
  149. * Cleans duplicate objects from the provided scene object list. This involves removing child elements if their
  150. * parents are already part of the list.
  151. */
  152. static void cleanDuplicates(Vector<HSceneObject>& objects);
  153. Vector<HSceneObject> mCopyList;
  154. bool mCutFlag;
  155. static const Color PREFAB_TINT;
  156. };
  157. typedef ServiceLocator<GUISceneTreeView> SceneTreeViewLocator;
  158. /** @} */
  159. }