UiCoinCountComponent.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 <UiCoinCountBus.h>
  10. #include <AzCore/Component/Component.h>
  11. #include <AzCore/EBus/ScheduledEvent.h>
  12. namespace MultiplayerSample
  13. {
  14. class UiCoinCountComponent
  15. : public AZ::Component
  16. #if AZ_TRAIT_CLIENT
  17. , public UiCoinCountNotificationBus::Handler
  18. #endif
  19. {
  20. public:
  21. AZ_COMPONENT(UiCoinCountComponent, "{ede1871e-70fa-4d63-9dc4-aa451b1b3fa9}");
  22. static void Reflect(AZ::ReflectContext* context);
  23. void Activate() override;
  24. void Deactivate() override;
  25. #if AZ_TRAIT_CLIENT
  26. //! UiCoinCountNotificationBus overrides ...
  27. //! @{
  28. void OnCoinCountChanged(uint16_t totalCoinsCollectedByLocalPlayer) override;
  29. //! }@
  30. #endif
  31. private:
  32. #if AZ_TRAIT_CLIENT
  33. // Color change effect
  34. // @{
  35. void OnTick(AZ::TimeMs delta);
  36. AZ::ScheduledEvent m_gameFrameTick{[this]()
  37. {
  38. OnTick(m_gameFrameTick.TimeInQueueMs());
  39. }, AZ::Name("UiCoinCountComponent")};
  40. #endif
  41. AZ::EntityId m_coinsTextForLocalPlayer;
  42. AZ::Color m_recentlyChangedCoinTextColor = AZ::Colors::Green;
  43. AZ::Color m_coinTextColor = AZ::Colors::White;
  44. AZ::TimeMs m_coinTextColorEffectDuration{ 300 };
  45. AZ::TimeMs m_coinTextColorEffect = AZ::Time::ZeroTimeMs;
  46. // }@
  47. };
  48. } // namespace MultiplayerSample