LayerControllerComponent.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 <AzCore/Component/Component.h>
  10. #include <AzCore/Component/TickBus.h>
  11. #include <AzCore/std/string/string.h>
  12. #include <GraphCanvas/Utils/StateControllers/StackStateController.h>
  13. #include <GraphCanvas/Components/LayerBus.h>
  14. #include <GraphCanvas/Components/Nodes/Group/NodeGroupBus.h>
  15. #include <GraphCanvas/Components/SceneBus.h>
  16. #include <GraphCanvas/Components/VisualBus.h>
  17. namespace GraphCanvas
  18. {
  19. class StyleManagerRequests;
  20. class LayerUtils
  21. {
  22. public:
  23. static int AlwaysOnTopZValue();
  24. static int AlwaysOnBottomZValue();
  25. };
  26. class LayerControllerComponent
  27. : public AZ::Component
  28. , public StateController<AZStd::string>::Notifications::Handler
  29. , public RootGraphicsItemNotificationBus::Handler
  30. , public LayerControllerRequestBus::Handler
  31. , public SceneMemberNotificationBus::Handler
  32. , public SceneNotificationBus::Handler
  33. , public GroupableSceneMemberNotificationBus::MultiHandler
  34. , public AZ::SystemTickBus::Handler
  35. {
  36. friend class LayerUtils;
  37. protected:
  38. // Offsets that can be set to offset within an individual layer.
  39. // This will allow us to manually sort each element into its own display category, while still adhering to other layering rules.
  40. enum LayerOffset
  41. {
  42. OffsetIndexForce = -1,
  43. // Controls the relative layering of each element inside of a particular layer.
  44. // In reverse display order here(higher up means lower down in the z-order)
  45. ConnectionOffset,
  46. NodeOffset,
  47. NodeGroupOffset,
  48. CommentOffset,
  49. BookmarkAnchorOffset,
  50. OffsetCount
  51. };
  52. LayerControllerComponent(AZStd::string_view layeringElement, LayerOffset layerOffset);
  53. public:
  54. static void Reflect(AZ::ReflectContext* context);
  55. AZ_COMPONENT(LayerControllerComponent, "{A85BE3B4-18D5-45D4-91B2-B5529C999E3D}", AZ::Component);
  56. LayerControllerComponent();
  57. ~LayerControllerComponent() override = default;
  58. // Component
  59. void Init() override;
  60. void Activate() override;
  61. void Deactivate() override;
  62. ////
  63. // SystemTickBus
  64. void OnSystemTick() override;
  65. ////
  66. // SceneMemberNotificationBus
  67. void OnSceneSet(const AZ::EntityId& sceneId) override;
  68. ////
  69. // SceneNotificationsBus
  70. void OnStylesChanged() override;
  71. void OnSelectionChanged() override;
  72. ////
  73. // RootGraphicsItemNotificationBus
  74. void OnDisplayStateChanged(RootGraphicsItemDisplayState oldState, RootGraphicsItemDisplayState newState) override;
  75. ////
  76. // StateController::Notifications
  77. void OnStateChanged(const AZStd::string& state) override;
  78. ////
  79. // LayerControllerRequestBus
  80. StateController<AZStd::string>* GetLayerModifierController() override;
  81. int GetSelectionOffset() const override;
  82. int GetGroupLayerOffset() const override;
  83. ////
  84. // GroupableSceneMemberNotifications
  85. void OnGroupChanged() override;
  86. ////
  87. int GetLayerOffset() const;
  88. protected:
  89. void SetBaseModifier(AZStd::string_view baseModifier);
  90. void SetGroupLayerOffset(int groupOffset);
  91. void SetSelectionLayerOffset(int selectionOffset);
  92. private:
  93. int CalculateZValue(int layer);
  94. void UpdateZValue();
  95. void ComputeCurrentLayer();
  96. int m_layer = 0;
  97. int m_layerOffset = 0;
  98. int m_selectionOffset = 0;
  99. int m_groupLayerOffset = 0;
  100. bool m_isInspected = false;
  101. GroupableSceneMemberRequests* m_groupableRequests = nullptr;
  102. SceneMemberUIRequests* m_uiRequests = nullptr;
  103. AZStd::string m_baseModifier;
  104. StackStateController< AZStd::string > m_externalLayerModifier;
  105. AZStd::string m_baseLayering;
  106. AZStd::string m_currentStyle;
  107. EditorId m_editorId;
  108. };
  109. }