BsGUISceneTreeView.h 8.6 KB

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