3
0

UiRadioButtonGroupComponent.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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/UiRadioButtonGroupBus.h>
  11. #include <LyShine/Bus/UiRadioButtonGroupCommunicationBus.h>
  12. #include <LyShine/Bus/UiInitializationBus.h>
  13. #include <LyShine/UiComponentTypes.h>
  14. namespace AZ
  15. {
  16. class ReflectContext;
  17. }
  18. ////////////////////////////////////////////////////////////////////////////////////////////////////
  19. class UiRadioButtonGroupComponent
  20. : public AZ::Component
  21. , public UiRadioButtonGroupBus::Handler
  22. , public UiRadioButtonGroupCommunicationBus::Handler
  23. {
  24. public: // member functions
  25. AZ_COMPONENT(UiRadioButtonGroupComponent, LyShine::UiRadioButtonGroupComponentUuid, AZ::Component);
  26. UiRadioButtonGroupComponent();
  27. ~UiRadioButtonGroupComponent() override;
  28. // UiRadioButtonInterface
  29. AZ::EntityId GetCheckedRadioButton() override;
  30. void SetState(AZ::EntityId radioButton, bool isOn) override;
  31. bool GetAllowUncheck() override;
  32. void SetAllowUncheck(bool allowUncheck) override;
  33. void AddRadioButton(AZ::EntityId radioButton) override;
  34. void RemoveRadioButton(AZ::EntityId radioButton) override;
  35. bool ContainsRadioButton(AZ::EntityId radioButton) override;
  36. const LyShine::ActionName& GetChangedActionName() override;
  37. void SetChangedActionName(const LyShine::ActionName& actionName) override;
  38. // ~UiRadioButtonInterface
  39. // UiRadioButtonGroupCommunicationInterface
  40. bool RegisterRadioButton(AZ::EntityId radioButton) override;
  41. void UnregisterRadioButton(AZ::EntityId radioButton) override;
  42. void RequestRadioButtonStateChange(AZ::EntityId radioButton, bool newState) override;
  43. // ~UiRadioButtonGroupCommunicationInterface
  44. protected: // member functions
  45. // AZ::Component
  46. void Activate() override;
  47. void Deactivate() override;
  48. // ~AZ::Component
  49. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  50. {
  51. provided.push_back(AZ_CRC("UiRadioButtonGroupService"));
  52. }
  53. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  54. {
  55. incompatible.push_back(AZ_CRC("UiRadioButtonGroupService"));
  56. }
  57. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  58. {
  59. required.push_back(AZ_CRC("UiElementService", 0x3dca7ad4));
  60. }
  61. static void Reflect(AZ::ReflectContext* context);
  62. private: // member functions
  63. AZ_DISABLE_COPY_MOVE(UiRadioButtonGroupComponent);
  64. //! Internal function with the common code for setting the state of the radio button group
  65. void SetStateCommon(AZ::EntityId radioButton, bool isOn, bool sendNotifications);
  66. private: // data
  67. bool m_allowUncheck;
  68. AZ::EntityId m_checkedEntity;
  69. AZStd::unordered_set<AZ::EntityId> m_radioButtons;
  70. LyShine::ActionName m_changedActionName;
  71. };