EditorRandomGradientComponent.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. #include "EditorRandomGradientComponent.h"
  9. namespace GradientSignal
  10. {
  11. void EditorRandomGradientComponent::Reflect(AZ::ReflectContext* context)
  12. {
  13. EditorGradientComponentBase::Reflect(context);
  14. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  15. {
  16. serializeContext->Class<EditorRandomGradientComponent, EditorGradientComponentBase>()
  17. ->Version(0)
  18. ;
  19. if (auto editContext = serializeContext->GetEditContext())
  20. {
  21. editContext->Class<EditorRandomGradientComponent>(
  22. EditorRandomGradientComponent::s_componentName, EditorRandomGradientComponent::s_componentDescription)
  23. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  24. ->Attribute(AZ::Edit::Attributes::Icon, s_icon)
  25. ->Attribute(AZ::Edit::Attributes::ViewportIcon, s_viewportIcon)
  26. ->Attribute(AZ::Edit::Attributes::HelpPageURL, s_helpUrl)
  27. ->Attribute(AZ::Edit::Attributes::Category, EditorRandomGradientComponent::s_categoryName)
  28. ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("Game"))
  29. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  30. ->UIElement(AZ::Edit::UIHandlers::Button, "GenerateRandomSeed", "Generate a new random seed")
  31. ->Attribute(AZ::Edit::Attributes::NameLabelOverride, "")
  32. ->Attribute(AZ::Edit::Attributes::ButtonText, "Generate Random Seed")
  33. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorRandomGradientComponent::OnGenerateRandomSeed)
  34. ;
  35. }
  36. }
  37. }
  38. AZ::Crc32 EditorRandomGradientComponent::OnGenerateRandomSeed()
  39. {
  40. // The random seed has to be at least 1 to be valid for this gradient type
  41. m_configuration.m_randomSeed = AZStd::max(rand(), 1);
  42. return EditorGradientComponentBase::ConfigurationChanged();
  43. }
  44. }