UiSliderComponent.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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/UiSliderBus.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 <AzCore/Math/Vector3.h>
  16. #include <LmbrCentral/Rendering/TextureAsset.h>
  17. ////////////////////////////////////////////////////////////////////////////////////////////////////
  18. class UiSliderComponent
  19. : public UiInteractableComponent
  20. , public UiSliderBus::Handler
  21. , public UiInitializationBus::Handler
  22. {
  23. public: // member functions
  24. AZ_COMPONENT(UiSliderComponent, LyShine::UiSliderComponentUuid, AZ::Component);
  25. UiSliderComponent();
  26. ~UiSliderComponent() override;
  27. // UiSliderInterface
  28. float GetValue() override;
  29. void SetValue(float value) override;
  30. float GetMinValue() override;
  31. void SetMinValue(float value) override;
  32. float GetMaxValue() override;
  33. void SetMaxValue(float value) override;
  34. float GetStepValue() override;
  35. void SetStepValue(float step) override;
  36. ValueChangeCallback GetValueChangingCallback() override;
  37. void SetValueChangingCallback(ValueChangeCallback onChange) override;
  38. const LyShine::ActionName& GetValueChangingActionName() override;
  39. void SetValueChangingActionName(const LyShine::ActionName& actionName) override;
  40. ValueChangeCallback GetValueChangedCallback() override;
  41. void SetValueChangedCallback(ValueChangeCallback onChange) override;
  42. const LyShine::ActionName& GetValueChangedActionName() override;
  43. void SetValueChangedActionName(const LyShine::ActionName& actionName) override;
  44. void SetTrackEntity(AZ::EntityId entityId) override;
  45. AZ::EntityId GetTrackEntity() override;
  46. void SetFillEntity(AZ::EntityId entityId) override;
  47. AZ::EntityId GetFillEntity() override;
  48. void SetManipulatorEntity(AZ::EntityId entityId) override;
  49. AZ::EntityId GetManipulatorEntity() override;
  50. // ~UiSliderInterface
  51. // UiInitializationInterface
  52. void InGamePostActivate() override;
  53. // ~UiInitializationInterface
  54. // UiInteractableInterface
  55. bool HandlePressed(AZ::Vector2 point, bool& shouldStayActive) override;
  56. bool HandleReleased(AZ::Vector2 point) override;
  57. bool HandleEnterPressed(bool& shouldStayActive) override;
  58. bool HandleAutoActivation() override;
  59. bool HandleKeyInputBegan(const AzFramework::InputChannel::Snapshot& inputSnapshot, AzFramework::ModifierKeyMask activeModifierKeys) override;
  60. void InputPositionUpdate(AZ::Vector2 point) override;
  61. bool DoesSupportDragHandOff(AZ::Vector2 startPoint) override;
  62. bool OfferDragHandOff(AZ::EntityId currentActiveInteractable, AZ::Vector2 startPoint, AZ::Vector2 currentPoint, float dragThreshold) override;
  63. void LostActiveStatus() override;
  64. // ~UiInteractableInterface
  65. protected: // member functions
  66. // AZ::Component
  67. void Activate() override;
  68. void Deactivate() override;
  69. // ~AZ::Component
  70. // UiInteractableComponent
  71. bool IsAutoActivationSupported() override;
  72. // ~UiInteractableComponent
  73. UiInteractableStatesInterface::State ComputeInteractableState() override;
  74. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  75. {
  76. provided.push_back(AZ_CRC("UiInteractableService", 0x1d474c98));
  77. provided.push_back(AZ_CRC("UiNavigationService"));
  78. provided.push_back(AZ_CRC("UiStateActionsService"));
  79. }
  80. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  81. {
  82. incompatible.push_back(AZ_CRC("UiInteractableService", 0x1d474c98));
  83. incompatible.push_back(AZ_CRC("UiNavigationService"));
  84. incompatible.push_back(AZ_CRC("UiStateActionsService"));
  85. }
  86. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  87. {
  88. required.push_back(AZ_CRC("UiElementService", 0x3dca7ad4));
  89. required.push_back(AZ_CRC("UiTransformService", 0x3a838e34));
  90. }
  91. static void Reflect(AZ::ReflectContext* context);
  92. private: // member functions
  93. AZ_DISABLE_COPY_MOVE(UiSliderComponent);
  94. using EntityComboBoxVec = AZStd::vector< AZStd::pair< AZ::EntityId, AZStd::string > >;
  95. EntityComboBoxVec PopulateChildEntityList();
  96. float GetValueFromPoint(AZ::Vector2 point);
  97. float GetValidDragDistanceInPixels(AZ::Vector2 startPoint, AZ::Vector2 endPoint);
  98. bool CheckForDragOrHandOffToParent(AZ::EntityId currentActiveInteractable, AZ::Vector2 startPoint, AZ::Vector2 currentPoint, float childDragThreshold, bool& handOffDone);
  99. void DoChangedActions();
  100. void DoChangingActions();
  101. private: // static member functions
  102. static bool VersionConverter(AZ::SerializeContext& context,
  103. AZ::SerializeContext::DataElementNode& classElement);
  104. private: // data
  105. float m_value;
  106. float m_minValue;
  107. float m_maxValue;
  108. float m_stepValue;
  109. bool m_isDragging;
  110. bool m_isActive; // true when interactable can be manipulated by key input
  111. ValueChangeCallback m_onValueChanged;
  112. ValueChangeCallback m_onValueChanging;
  113. LyShine::ActionName m_valueChangedActionName;
  114. LyShine::ActionName m_valueChangingActionName;
  115. AZ::EntityId m_trackEntity;
  116. AZ::EntityId m_fillEntity;
  117. AZ::EntityId m_manipulatorEntity;
  118. };