BsGUISceneTreeView.h 8.4 KB

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