EditorMixedGradientComponent.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 <GradientSignal/Editor/EditorGradientComponentBase.h>
  10. #include <GradientSignal/Components/MixedGradientComponent.h>
  11. namespace GradientSignal
  12. {
  13. template<>
  14. struct HasCustomSetSamplerOwner<MixedGradientConfig>
  15. : AZStd::true_type
  16. {
  17. };
  18. template<typename T>
  19. bool ValidateGradientEntityIds(T& configuration, AZStd::enable_if_t<AZStd::is_same<T, MixedGradientConfig>::value>* = nullptr)
  20. {
  21. bool validated = true;
  22. for (auto& layer : configuration.m_layers)
  23. {
  24. validated &= layer.m_gradientSampler.ValidateGradientEntityId();
  25. }
  26. return validated;
  27. }
  28. template<typename T>
  29. void SetSamplerOwnerEntity(T& configuration, AZ::EntityId entityId, AZStd::enable_if_t<AZStd::is_same<T, MixedGradientConfig>::value>* = nullptr)
  30. {
  31. for (auto& layer : configuration.m_layers)
  32. {
  33. layer.m_gradientSampler.m_ownerEntityId = entityId;
  34. }
  35. }
  36. class EditorMixedGradientComponent
  37. : public EditorGradientComponentBase<MixedGradientComponent, MixedGradientConfig>
  38. {
  39. public:
  40. using BaseClassType = EditorGradientComponentBase<MixedGradientComponent, MixedGradientConfig>;
  41. AZ_EDITOR_COMPONENT(EditorMixedGradientComponent, EditorMixedGradientComponentTypeId, BaseClassType);
  42. static void Reflect(AZ::ReflectContext* context);
  43. // AZ::Component overrides ...
  44. void Init() override;
  45. void Activate() override;
  46. static constexpr const char* const s_categoryName = "Gradient Modifiers";
  47. static constexpr const char* const s_componentName = "Gradient Mixer";
  48. static constexpr const char* const s_componentDescription = "Generates a new gradient by combining other gradients";
  49. static constexpr const char* const s_icon = "Editor/Icons/Components/GradientModifier.svg";
  50. static constexpr const char* const s_viewportIcon = "Editor/Icons/Components/Viewport/GradientModifier.svg";
  51. static constexpr const char* const s_helpUrl = "https://o3de.org/docs/user-guide/components/reference/gradient-modifiers/gradient-mixer/";
  52. protected:
  53. AZ::u32 ConfigurationChanged() override;
  54. private:
  55. void ForceOneEntry();
  56. };
  57. }