UiElementLuaBus.cpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. #include "UiElementLuaBus.h"
  9. #include <LyShine/Bus/UiElementBus.h>
  10. #include <AzCore/Component/ComponentApplicationBus.h>
  11. #include <AzCore/Serialization/SerializeContext.h>
  12. #include <AzCore/RTTI/BehaviorContext.h>
  13. namespace AZ
  14. {
  15. AZ_TYPE_INFO_SPECIALIZE(UiElementLuaProxy, "{77FDAF4D-23B5-4004-8679-14AA1BBC7B5E}");
  16. }
  17. ////////////////////////////////////////////////////////////////////////////////////////////////////
  18. // PUBLIC MEMBER FUNCTIONS
  19. ////////////////////////////////////////////////////////////////////////////////////////////////////
  20. bool UiElementLuaProxy::IsEnabled()
  21. {
  22. CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_WARNING,
  23. "UiElementLuaProxy:IsEnabled is deprecated. Please use UiElementBus:IsEnabled instead\n");
  24. bool isEnabled = false;
  25. UiElementBus::EventResult(isEnabled, m_targetEntity, &UiElementBus::Events::IsEnabled);
  26. return isEnabled;
  27. }
  28. void UiElementLuaProxy::SetIsEnabled(bool isEnabled)
  29. {
  30. CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_WARNING,
  31. "UiElementLuaProxy:SetIsEnabled is deprecated. Please use UiElementBus:SetIsEnabled instead\n");
  32. UiElementBus::Event(m_targetEntity, &UiElementBus::Events::SetIsEnabled, isEnabled);
  33. }
  34. void UiElementLuaProxy::BusConnect(AZ::EntityId entityId)
  35. {
  36. CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_WARNING,
  37. "UiElementLuaProxy:BusConnect is deprecated. Please use the UiElement bus directly instead\n");
  38. AZ::Entity* elementEntity = nullptr;
  39. AZ::ComponentApplicationBus::BroadcastResult(elementEntity, &AZ::ComponentApplicationBus::Events::FindEntity, entityId);
  40. if (elementEntity)
  41. {
  42. m_targetEntity = entityId;
  43. // Use this object to handle UiElementLuaBus calls for the given entity
  44. UiElementLuaBus::Handler::BusConnect(m_targetEntity);
  45. }
  46. else
  47. {
  48. CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_WARNING, "UiElementLuaProxy:BusConnect: Element entity not found by ID\n");
  49. }
  50. }
  51. ////////////////////////////////////////////////////////////////////////////////////////////////////
  52. // PUBLIC STATIC MEMBER FUNCTIONS
  53. ////////////////////////////////////////////////////////////////////////////////////////////////////
  54. void UiElementLuaProxy::Reflect(AZ::ReflectContext* context)
  55. {
  56. AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context);
  57. if (behaviorContext)
  58. {
  59. behaviorContext->Class<UiElementLuaProxy>("UiElementLuaProxy")
  60. ->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::All)
  61. ->Attribute(AZ::Script::Attributes::Storage, AZ::Script::Attributes::StorageType::Value)
  62. ->Method("BusConnect", &UiElementLuaProxy::BusConnect)
  63. ->Method("IsEnabled", &UiElementLuaProxy::IsEnabled)
  64. ->Method("SetIsEnabled", &UiElementLuaProxy::SetIsEnabled)
  65. ;
  66. }
  67. }