ImGuiLYEntityOutliner.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include "ImGuiManager.h"
  10. #ifdef IMGUI_ENABLED
  11. #include "ImGuiBus.h"
  12. #include <AzCore/std/containers/map.h>
  13. #include <AzCore/Serialization/SerializeContext.h>
  14. namespace ImGui
  15. {
  16. class ImGuiLYEntityOutliner
  17. : public ImGuiEntityOutlinerRequestBus::Handler
  18. {
  19. public:
  20. ImGuiLYEntityOutliner();
  21. ~ImGuiLYEntityOutliner();
  22. // Called from owner
  23. void Initialize();
  24. void Shutdown();
  25. // Draw the Im Gui Menu
  26. void ImGuiUpdate();
  27. // Toggle the menu on and off
  28. void ToggleEnabled() { m_enabled = !m_enabled; }
  29. // Called by the owner to draw a component view sub menu
  30. void ImGuiUpdate_DrawComponentViewSubMenu();
  31. // -- ImGuiEntityOutlinerRequestBus::Handler Interface ---------------------
  32. void RemoveEntityView(AZ::EntityId entity) override;
  33. void RequestEntityView(AZ::EntityId entity) override;
  34. void RemoveComponentView(ImGuiEntComponentId component) override;
  35. void RequestComponentView(ImGuiEntComponentId component) override;
  36. void RequestAllViewsForComponent(const AZ::TypeId& comType) override;
  37. void EnableTargetViewMode(bool enabled) override;
  38. void EnableComponentDebug(const AZ::TypeId& comType, int priority = 1, bool enableMenuBar = false) override;
  39. void SetEnabled(bool enabled) override;
  40. void AddAutoEnableSearchString(const AZStd::string& searchString) override;
  41. // -- ImGuiEntityOutlinerRequestBus::Handler Interface ---------------------
  42. private:
  43. class EntityInfoNode; // Forward declare for smart pointer type, so smart pointer type can go in struct
  44. // We should use smart pointers for these guys, just to double verify these get deleted
  45. typedef _smart_ptr<EntityInfoNode> EntityInfoNodePtr;
  46. // A small class to build a quick tree structure to represent the entity hierarchy
  47. class EntityInfoNode
  48. : public _reference_target_t
  49. {
  50. public:
  51. EntityInfoNode(const AZ::EntityId &entityId, EntityInfoNodePtr parentNode)
  52. : m_entityId(entityId), m_parent(parentNode), m_descendantCount(0) {}
  53. // The entity id of the ent on this node
  54. AZ::EntityId m_entityId;
  55. // The Node Ptr to the parent node ( where we can get their ID and such )
  56. EntityInfoNodePtr m_parent;
  57. // A Vector of our children via their nodes
  58. AZStd::vector<EntityInfoNodePtr> m_children;
  59. // A Cached count of this node's descendants, created at hierarchy creation time
  60. int m_descendantCount;
  61. // A Cached value of what is considered this entity's highest priority component to debug
  62. AZ::TypeId m_highestPriorityComponentDebug;
  63. };
  64. // A small struct to store common items used for an Entity Outliner Display Option
  65. struct EntOutlineDisplayOption
  66. {
  67. EntOutlineDisplayOption(bool enabled, const ImVec4 color)
  68. : m_enabled(enabled), m_color(color) {}
  69. bool m_enabled;
  70. ImVec4 m_color;
  71. };
  72. int m_totalEntitiesFound;
  73. EntityInfoNodePtr m_rootEntityInfo;
  74. AZStd::map<AZ::EntityId, EntityInfoNodePtr> m_entityIdToInfoNodePtrMap;
  75. // Delete the provided entity info struct pointer and any children recursively
  76. void DeleteEntityInfoAndDecendants(EntityInfoNodePtr entityInfo);
  77. EntityInfoNodePtr FindEntityInfoByEntityId(const AZ::EntityId &entityId, EntityInfoNodePtr searchNode);
  78. // Grab the root slice and re figure out the entity hierarchy
  79. void RefreshEntityHierarchy();
  80. int RefreshEntityHierarchy_FillCacheAndSort(EntityInfoNodePtr entityInfo);
  81. // Update Helper function to recursively draw and entity info and its children
  82. void ImGuiUpdate_RecursivelyDisplayEntityInfoAndDecendants(EntityInfoNodePtr node, bool justDrawChildren = false, bool drawInspectButton = true, bool drawTargetButton = true, bool drawDebugButton = true, bool sameLine = true, bool drawComponents = false);
  83. void ImGuiUpdate_RecursivelyDisplayEntityInfoAndDecendants_DrawDisplayOptions(EntityInfoNodePtr node, bool drawInspectButton, bool drawTargetButton, bool drawDebugButton, bool sameLine, bool drawComponents);
  84. // Update Helper Functions for Entity and Component Views
  85. bool ImGuiUpdate_DrawEntityView(const AZ::EntityId &ent);
  86. void ImGuiUpdate_DrawComponent(void *instance, const AZ::SerializeContext::ClassData *classData, const AZ::SerializeContext::ClassElement *classElement);
  87. bool ImGuiUpdate_DrawComponentView(const ImGui::ImGuiEntComponentId &entCom);
  88. // Update Helper Functions for the menu bar
  89. void ImGuiUpdate_DrawViewOptions();
  90. void ImGuiUpdate_DrawAutoEnableOptions();
  91. // Different options for the Outliner Display
  92. bool m_enabled;
  93. bool m_drawTargetViewButton;
  94. // Display options
  95. EntOutlineDisplayOption m_displayName;
  96. EntOutlineDisplayOption m_displayChildCount;
  97. EntOutlineDisplayOption m_displayDescentdantCount;
  98. EntOutlineDisplayOption m_displayEntityState;
  99. EntOutlineDisplayOption m_displayParentInfo;
  100. EntOutlineDisplayOption m_displayLocalPos;
  101. EntOutlineDisplayOption m_displayLocalRotation;
  102. EntOutlineDisplayOption m_displayWorldPos;
  103. EntOutlineDisplayOption m_displayWorldRotation;
  104. // Quick enum for IMGui drop down menu
  105. enum class HierarchyUpdateType : int
  106. {
  107. Constant = 0,
  108. UpdateTick,
  109. };
  110. HierarchyUpdateType m_hierarchyUpdateType;
  111. float m_hierarchyUpdateTickTimeCurrent;
  112. float m_hierarchyUpdateTickTimeTotal;
  113. // Sets of entity and component view windows
  114. AZStd::unordered_set<AZ::EntityId> m_entitiesToView;
  115. AZStd::unordered_set<ImGui::ImGuiEntComponentId> m_componentsToView;
  116. // data and interface for dealing with component debug windows and priorities, 1 per component types
  117. struct ComponentDebugInfo
  118. {
  119. ComponentDebugInfo(int priority, bool enableMenuBar, bool autoLaunchEnabled)
  120. : m_priority(priority)
  121. , m_autoLaunchEnabled(autoLaunchEnabled)
  122. , m_menuBarEnabled(enableMenuBar) {}
  123. ComponentDebugInfo() : ComponentDebugInfo(-1, false, false) {};
  124. int m_priority;
  125. bool m_autoLaunchEnabled;
  126. bool m_menuBarEnabled;
  127. };
  128. AZStd::list<AZ::TypeId> m_componentDebugSortedList; // list is for quick iteration, sorting and ordering
  129. AZStd::map<AZ::TypeId, ComponentDebugInfo> m_componentDebugInfoMap; // map is for quick lookup of debug info without iterating through the above vector
  130. // A list of strings that are used to find component names to auto enable
  131. AZStd::unordered_set<AZStd::string> m_autoEnableComponentSearchStrings;
  132. void RefreshAutoEnableBasedOnSearchStrings();
  133. bool ComponentHasDebug(const AZ::TypeId& comType);
  134. };
  135. }
  136. #endif // IMGUI_ENABLED