EditorFastNoiseGradientComponent.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 "EditorFastNoiseGradientComponent.h"
  9. namespace FastNoiseGem
  10. {
  11. void EditorFastNoiseGradientComponent::Reflect(AZ::ReflectContext* context)
  12. {
  13. EditorGradientComponentBase::Reflect(context);
  14. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  15. {
  16. serializeContext->Class<EditorFastNoiseGradientComponent, EditorGradientComponentBase>()
  17. ->Version(0)
  18. ;
  19. if (auto editContext = serializeContext->GetEditContext())
  20. {
  21. editContext->Class<EditorFastNoiseGradientComponent>(
  22. EditorFastNoiseGradientComponent::s_componentName, EditorFastNoiseGradientComponent::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, EditorFastNoiseGradientComponent::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, &EditorFastNoiseGradientComponent::OnGenerateRandomSeed)
  34. ;
  35. }
  36. }
  37. }
  38. AZ::u32 EditorFastNoiseGradientComponent::ConfigurationChanged()
  39. {
  40. bool noiseTypeChanged = m_component.m_configuration.m_noiseType != m_configuration.m_noiseType;
  41. EditorGradientComponentBase::ConfigurationChanged();
  42. // Repopulate the menu based on the new attribute visibility if our noise type has changed
  43. return noiseTypeChanged ? AZ::Edit::PropertyRefreshLevels::EntireTree : AZ::Edit::PropertyRefreshLevels::None;
  44. }
  45. AZ::Crc32 EditorFastNoiseGradientComponent::OnGenerateRandomSeed()
  46. {
  47. // The random seed has to be at least 1 to be valid on all platforms for this gradient type
  48. m_configuration.m_seed = AZ::GetMax(rand(), 1);
  49. return ConfigurationChanged();
  50. }
  51. } //namespace FastNoiseGem