UiRadioButtonComponent.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 "UiInteractableComponent.h"
  10. #include <LyShine/Bus/UiRadioButtonBus.h>
  11. #include <LyShine/Bus/UiRadioButtonCommunicationBus.h>
  12. #include <LyShine/Bus/UiInitializationBus.h>
  13. #include <LyShine/Bus/UiInteractableBus.h>
  14. #include <LyShine/UiComponentTypes.h>
  15. ////////////////////////////////////////////////////////////////////////////////////////////////////
  16. class UiRadioButtonComponent
  17. : public UiInteractableComponent
  18. , public UiRadioButtonBus::Handler
  19. , public UiRadioButtonCommunicationBus::Handler
  20. , public UiInitializationBus::Handler
  21. {
  22. public: // member functions
  23. AZ_COMPONENT(UiRadioButtonComponent, LyShine::UiRadioButtonComponentUuid, AZ::Component);
  24. UiRadioButtonComponent();
  25. ~UiRadioButtonComponent() override;
  26. // UiRadioButtonInterface
  27. bool GetState() override;
  28. AZ::EntityId GetGroup() override;
  29. AZ::EntityId GetCheckedEntity() override;
  30. void SetCheckedEntity(AZ::EntityId entityId) override;
  31. AZ::EntityId GetUncheckedEntity() override;
  32. void SetUncheckedEntity(AZ::EntityId entityId) override;
  33. const LyShine::ActionName& GetTurnOnActionName() override;
  34. void SetTurnOnActionName(const LyShine::ActionName& actionName) override;
  35. const LyShine::ActionName& GetTurnOffActionName() override;
  36. void SetTurnOffActionName(const LyShine::ActionName& actionName) override;
  37. const LyShine::ActionName& GetChangedActionName() override;
  38. void SetChangedActionName(const LyShine::ActionName& actionName) override;
  39. // ~UiRadioButtonInterface
  40. // UiRadioButtonCommunicationInterface
  41. void SetState(bool isOn, bool sendNotifications) override;
  42. void SetGroup(AZ::EntityId group) override;
  43. // ~UiRadioButtonCommunicationInterface
  44. // UiInitializationInterface
  45. void InGamePostActivate() override;
  46. // ~UiInitializationInterface
  47. // UiInteractableInterface
  48. bool HandleReleased(AZ::Vector2 point) override;
  49. bool HandleEnterReleased() override;
  50. // ~UiInteractableInterface
  51. protected: // member functions
  52. // AZ::Component
  53. void Activate() override;
  54. void Deactivate() override;
  55. // ~AZ::Component
  56. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  57. {
  58. provided.push_back(AZ_CRC("UiInteractableService", 0x1d474c98));
  59. provided.push_back(AZ_CRC("UiStateActionsService"));
  60. provided.push_back(AZ_CRC("UiNavigationService"));
  61. }
  62. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  63. {
  64. incompatible.push_back(AZ_CRC("UiInteractableService", 0x1d474c98));
  65. incompatible.push_back(AZ_CRC("UiNavigationService"));
  66. incompatible.push_back(AZ_CRC("UiStateActionsService"));
  67. }
  68. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  69. {
  70. required.push_back(AZ_CRC("UiElementService", 0x3dca7ad4));
  71. required.push_back(AZ_CRC("UiTransformService", 0x3a838e34));
  72. }
  73. static void Reflect(AZ::ReflectContext* context);
  74. private: // member functions
  75. AZ_DISABLE_COPY_MOVE(UiRadioButtonComponent);
  76. using EntityComboBoxVec = AZStd::vector< AZStd::pair< AZ::EntityId, AZStd::string > >;
  77. EntityComboBoxVec PopulateChildEntityList();
  78. EntityComboBoxVec PopulateGroupsEntityList();
  79. bool HandleReleasedCommon(const AZ::Vector2& point);
  80. private: // data
  81. bool m_isOn;
  82. AZ::EntityId m_group; //!< The group this radio button belongs to.
  83. AZ::EntityId m_optionalCheckedEntity; //!< The optional child element to show when ON.
  84. AZ::EntityId m_optionalUncheckedEntity; //!< The optional child element to show when OFF.
  85. LyShine::ActionName m_turnOnActionName;
  86. LyShine::ActionName m_turnOffActionName;
  87. LyShine::ActionName m_changedActionName;
  88. };