UIGameplayEventButton.lua 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. ----------------------------------------------------------------------------------------------------
  2. --
  3. -- Copyright (c) Contributors to the Open 3D Engine Project.
  4. -- For complete copyright and license terms please see the LICENSE at the root of this distribution.
  5. --
  6. -- SPDX-License-Identifier: Apache-2.0 OR MIT
  7. --
  8. --
  9. --
  10. ----------------------------------------------------------------------------------------------------
  11. local UIGameplayEventButton = {
  12. Properties = {
  13. Debug = false,
  14. Event = { default = "", description = "Event name" },
  15. Value = { default = "", description = "Event value" },
  16. InputEvent = { default = "", description = "Optional input event name"}
  17. }
  18. }
  19. function UIGameplayEventButton:OnActivate()
  20. self.buttonHandler = UiButtonNotificationBus.Connect(self, self.entityId)
  21. self.gameplayNotificationId = GameplayNotificationId(EntityId(0), self.Properties.Event, "float")
  22. if self.Properties.InputEvent ~= "" then
  23. local id = InputEventNotificationId(self.Properties.InputEvent)
  24. self.inputHandler = InputEventNotificationBus.Connect(self, id)
  25. end
  26. end
  27. function UIGameplayEventButton:OnPressed(value)
  28. GameplayNotificationBus.Event.OnEventBegin(self.gameplayNotificationId, self.Properties.Value)
  29. end
  30. function UIGameplayEventButton:OnButtonClick()
  31. GameplayNotificationBus.Event.OnEventBegin(self.gameplayNotificationId, self.Properties.Value)
  32. end
  33. function UIGameplayEventButton:OnDeactivate()
  34. if self.buttonHandler ~= nil then
  35. self.buttonHandler:Disconnect()
  36. end
  37. if self.inputHandler ~= nil then
  38. self.inputHandler:Disconnect()
  39. end
  40. end
  41. return UIGameplayEventButton