BsGUISceneTreeView.h 8.5 KB

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