UiCheckboxComponent.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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/UiCheckboxBus.h>
  11. #include <LyShine/Bus/UiInitializationBus.h>
  12. #include <LyShine/Bus/UiInteractableBus.h>
  13. #include <LyShine/UiComponentTypes.h>
  14. #include <AzCore/Serialization/SerializeContext.h>
  15. #include <LmbrCentral/Rendering/TextureAsset.h>
  16. ////////////////////////////////////////////////////////////////////////////////////////////////////
  17. class UiCheckboxComponent
  18. : public UiInteractableComponent
  19. , public UiCheckboxBus::Handler
  20. , public UiInitializationBus::Handler
  21. {
  22. public: // member functions
  23. AZ_COMPONENT(UiCheckboxComponent, LyShine::UiCheckboxComponentUuid, AZ::Component);
  24. UiCheckboxComponent();
  25. ~UiCheckboxComponent() override;
  26. // UiCheckboxInterface
  27. bool GetState() override;
  28. void SetState(bool isOn) override;
  29. bool ToggleState() override;
  30. StateChangeCallback GetStateChangeCallback() override;
  31. void SetStateChangeCallback(StateChangeCallback onChange) override;
  32. void SetCheckedEntity(AZ::EntityId entityId) override;
  33. AZ::EntityId GetCheckedEntity() override;
  34. void SetUncheckedEntity(AZ::EntityId entityId) override;
  35. AZ::EntityId GetUncheckedEntity() override;
  36. const LyShine::ActionName& GetTurnOnActionName() override;
  37. void SetTurnOnActionName(const LyShine::ActionName& actionName) override;
  38. const LyShine::ActionName& GetTurnOffActionName() override;
  39. void SetTurnOffActionName(const LyShine::ActionName& actionName) override;
  40. const LyShine::ActionName& GetChangedActionName() override;
  41. void SetChangedActionName(const LyShine::ActionName& actionName) override;
  42. // ~UiCheckboxInterface
  43. // UiInitializationInterface
  44. void InGamePostActivate() override;
  45. // ~UiInitializationInterface
  46. // UiInteractableInterface
  47. bool HandleReleased(AZ::Vector2 point) override;
  48. bool HandleEnterReleased() override;
  49. // ~UiInteractableInterface
  50. protected: // member functions
  51. // AZ::Component
  52. void Activate() override;
  53. void Deactivate() override;
  54. // ~AZ::Component
  55. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  56. {
  57. provided.push_back(AZ_CRC("UiInteractableService", 0x1d474c98));
  58. provided.push_back(AZ_CRC("UiStateActionsService"));
  59. provided.push_back(AZ_CRC("UiNavigationService"));
  60. }
  61. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  62. {
  63. incompatible.push_back(AZ_CRC("UiInteractableService", 0x1d474c98));
  64. incompatible.push_back(AZ_CRC("UiNavigationService"));
  65. incompatible.push_back(AZ_CRC("UiStateActionsService"));
  66. }
  67. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  68. {
  69. required.push_back(AZ_CRC("UiElementService", 0x3dca7ad4));
  70. required.push_back(AZ_CRC("UiTransformService", 0x3a838e34));
  71. }
  72. static void Reflect(AZ::ReflectContext* context);
  73. private: // member functions
  74. AZ_DISABLE_COPY_MOVE(UiCheckboxComponent);
  75. using EntityComboBoxVec = AZStd::vector< AZStd::pair< AZ::EntityId, AZStd::string > >;
  76. EntityComboBoxVec PopulateChildEntityList();
  77. bool HandleReleasedCommon(const AZ::Vector2& point);
  78. private: // static member functions
  79. static bool VersionConverter(AZ::SerializeContext& context,
  80. AZ::SerializeContext::DataElementNode& classElement);
  81. private: // data
  82. bool m_isOn;
  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. StateChangeCallback m_onChange;
  86. LyShine::ActionName m_turnOnActionName;
  87. LyShine::ActionName m_turnOffActionName;
  88. LyShine::ActionName m_changedActionName;
  89. };