InputEventBindings.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 <AzCore/RTTI/TypeInfo.h>
  10. #include <AzFramework/Asset/SimpleAsset.h>
  11. #include <AzCore/Memory/SystemAllocator.h>
  12. #include <AzCore/Memory/Memory.h>
  13. #include "InputEventGroup.h"
  14. namespace StartingPointInput
  15. {
  16. /*!
  17. * InputEventBinding asset type configuration.
  18. * Reflect as: AzFramework::SimpleAssetReference<InputEventBindings>
  19. * This base class holds a list of InputEventGroups which organizes raw input processors by the
  20. * gameplay events they generate, Ex. Held(eKI_Space) -> "Jump"
  21. */
  22. class InputEventBindings
  23. {
  24. public:
  25. virtual ~InputEventBindings()
  26. {
  27. }
  28. AZ_CLASS_ALLOCATOR(InputEventBindings, AZ::SystemAllocator);
  29. AZ_RTTI(InputEventBindings, "{14FFD4A8-AE46-4E23-B45B-6A7C4F787A91}")
  30. static void Reflect(AZ::ReflectContext* reflection)
  31. {
  32. AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflection);
  33. if (serializeContext)
  34. {
  35. serializeContext->Class<InputEventBindings>()
  36. ->Version(1)
  37. ->Field("Input Event Groups", &InputEventBindings::m_inputEventGroups);
  38. AZ::EditContext* editContext = serializeContext->GetEditContext();
  39. if (editContext)
  40. {
  41. editContext->Class<InputEventBindings>("Input Event Bindings", "Holds InputEventBindings")
  42. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  43. ->DataElement(0, &InputEventBindings::m_inputEventGroups, "Input Event Groups", "Input Event Groups");
  44. }
  45. }
  46. }
  47. void Activate(const AzFramework::LocalUserId& localUserId)
  48. {
  49. for (InputEventGroup& inputEventGroup : m_inputEventGroups)
  50. {
  51. inputEventGroup.Activate(localUserId);
  52. }
  53. }
  54. void Deactivate(const AzFramework::LocalUserId& localUserId)
  55. {
  56. for (InputEventGroup& inputEventGroup : m_inputEventGroups)
  57. {
  58. inputEventGroup.Deactivate(localUserId);
  59. }
  60. }
  61. void Cleanup()
  62. {
  63. for (InputEventGroup& inputEventGroup : m_inputEventGroups)
  64. {
  65. inputEventGroup.Cleanup();
  66. }
  67. }
  68. void Swap(InputEventBindings* other)
  69. {
  70. m_inputEventGroups.swap(other->m_inputEventGroups);
  71. }
  72. protected:
  73. AZStd::vector<InputEventGroup> m_inputEventGroups;
  74. };
  75. class InputEventBindingsAsset
  76. : public AZ::Data::AssetData
  77. {
  78. public:
  79. AZ_CLASS_ALLOCATOR(InputEventBindingsAsset, AZ::SystemAllocator);
  80. AZ_RTTI(InputEventBindingsAsset, "{25971C7A-26E2-4D08-A146-2EFCC1C36B0C}", AZ::Data::AssetData);
  81. InputEventBindingsAsset() = default;
  82. virtual ~InputEventBindingsAsset()
  83. {
  84. m_bindings.Cleanup();
  85. }
  86. InputEventBindings m_bindings;
  87. static void Reflect(AZ::ReflectContext* context)
  88. {
  89. AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context);
  90. if (serialize)
  91. {
  92. serialize->Class<InputEventBindingsAsset>()
  93. ->Attribute(AZ::Edit::Attributes::EnableForAssetEditor, true)
  94. ->Field("Bindings", &InputEventBindingsAsset::m_bindings)
  95. ;
  96. AZ::EditContext* edit = serialize->GetEditContext();
  97. if (edit)
  98. {
  99. edit->Class<InputEventBindingsAsset>("Input to Event Bindings Asset", "")
  100. ->DataElement(0, &InputEventBindingsAsset::m_bindings, "Bindings", "")
  101. ->Attribute(AZ::Edit::Attributes::Visibility, AZ_CRC("PropertyVisibility_ShowChildrenOnly", 0xef428f20))
  102. ;
  103. }
  104. }
  105. }
  106. private:
  107. InputEventBindingsAsset(const InputEventBindingsAsset&) = delete;
  108. };
  109. } // namespace Input