UiCanvasNotificationLuaBus.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 <LyShine/Bus/UiCanvasBus.h>
  10. #include <AzCore/Component/Component.h>
  11. ////////////////////////////////////////////////////////////////////////////////////////////////////
  12. //! \brief Defines the Lua-specific variant of UiCanvasNotificationBus
  13. class UiCanvasNotificationLuaInterface
  14. : public AZ::ComponentBus
  15. {
  16. public:
  17. virtual ~UiCanvasNotificationLuaInterface() {}
  18. // UiCanvasNotificationBus
  19. virtual void OnAction(AZ::EntityId entityId, const char* actionName) = 0;
  20. // ~UiCanvasNotificationBus
  21. };
  22. typedef AZ::EBus<UiCanvasNotificationLuaInterface> UiCanvasNotificationLuaBus;
  23. ////////////////////////////////////////////////////////////////////////////////////////////////////
  24. //! \brief Listens for UiCanvasNotificationBus actions and forwards the calls to the Lua-specific version
  25. //!
  26. //! For this to work, the Lua script must create a UiCanvasNotificationLuaProxy object and call BusConnect,
  27. //! passing the entity ID of the entity they want to listen for action notifications from. For example:
  28. //! self.uiCanvasNotificationLuaProxy = UiCanvasNotificationLuaProxy();
  29. //! self.uiCanvasNotificationLuaProxy:BusConnect(canvasEntityId);
  30. class UiCanvasNotificationLuaProxy
  31. : public UiCanvasNotificationBus::Handler
  32. {
  33. public: // member functions
  34. UiCanvasNotificationLuaProxy();
  35. ~UiCanvasNotificationLuaProxy() override;
  36. // UiCanvasNotificationBus
  37. void OnAction(AZ::EntityId entityId, const LyShine::ActionName& actionName) override;
  38. // ~UiCanvasNotificationBus
  39. //! \brief Connects to the given entity's canvas notifications to forward to Lua
  40. void BusConnect(AZ::EntityId entityId);
  41. static void Reflect(AZ::ReflectContext* context);
  42. private: // members
  43. AZ::EntityId m_targetEntity;
  44. };