BsGUISceneTreeView.h 8.7 KB

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