Files
o3de/Gems/StartingPointInput/Code/Source/StartingPointInputGem.cpp
T
Esteban Papp 1f9b284de2 Merge branch 'development' into cmake/SPEC-7179
Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com>

# Conflicts:
#	Code/Editor/Plugins/ComponentEntityEditorPlugin/ComponentEntityEditorPlugin_precompiled.h
#	Code/Editor/Plugins/EditorCommon/EditorCommon_precompiled.h
#	Code/Editor/Plugins/EditorCommon/stdafx.cpp
#	Code/Editor/Plugins/FFMPEGPlugin/FFMPEGPlugin_precompiled.h
#	Code/Editor/Plugins/PerforcePlugin/PerforcePlugin_precompiled.h
#	Code/Editor/Plugins/ProjectSettingsTool/ProjectSettingsTool_precompiled.h
#	Code/Framework/AzToolsFramework/AzToolsFramework/AzToolsFramework_precompiled.h
#	Code/Tools/AssetProcessor/native/precompiled.h
#	Code/Tools/Standalone/StandaloneTools_precompiled.h
#	Gems/AssetMemoryAnalyzer/Code/Source/AssetMemoryAnalyzer_precompiled.h
#	Gems/Atom/Asset/ImageProcessingAtom/Code/Source/ImageProcessing_precompiled.h
#	Gems/Atom/RHI/DX12/Code/Source/RHI/Atom_RHI_DX12_precompiled.h
#	Gems/Atom/RHI/Metal/Code/Include/Platform/Mac/Atom_RHI_Metal_precompiled_Platform.h
#	Gems/Atom/RHI/Metal/Code/Include/Platform/iOS/Atom_RHI_Metal_precompiled_Platform.h
#	Gems/Atom/RHI/Metal/Code/Source/Atom_RHI_Metal_precompiled.h
#	Gems/Atom/RHI/Metal/Code/atom_rhi_metal_common_files.cmake
#	Gems/Atom/RHI/Null/Code/Source/Atom_RHI_Null_precompiled.h
#	Gems/Atom/RHI/Null/Code/atom_rhi_null_common_files.cmake
#	Gems/Atom/RHI/Vulkan/Code/Include/Platform/Android/Atom_RHI_Vulkan_precompiled_Platform.h
#	Gems/Atom/RHI/Vulkan/Code/Include/Platform/Linux/Atom_RHI_Vulkan_precompiled_Platform.h
#	Gems/Atom/RHI/Vulkan/Code/Include/Platform/Mac/Atom_RHI_Vulkan_precompiled_Platform.h
#	Gems/Atom/RHI/Vulkan/Code/Include/Platform/Windows/Atom_RHI_Vulkan_precompiled_Platform.h
#	Gems/Atom/RHI/Vulkan/Code/Source/Atom_RHI_Vulkan_precompiled.h
#	Gems/Atom/RHI/Vulkan/Code/Source/RHI/SwapChain.cpp
#	Gems/Atom/RHI/Vulkan/Code/atom_rhi_vulkan_common_files.cmake
#	Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/AtomFont_precompiled.h
#	Gems/Blast/Code/Source/StdAfx.cpp
#	Gems/Camera/Code/Source/Camera_precompiled.h
#	Gems/EMotionFX/Code/Source/EMotionFX_precompiled.h
#	Gems/FastNoise/Code/Source/FastNoise_precompiled.h
#	Gems/Gestures/Code/Source/Gestures_precompiled.h
#	Gems/GradientSignal/Code/Source/GradientSignal_precompiled.h
#	Gems/GraphCanvas/Code/precompiled.h
#	Gems/ImGui/Code/Source/ImGui_precompiled.h
#	Gems/InAppPurchases/Code/Source/InAppPurchases_precompiled.h
#	Gems/LmbrCentral/Code/Source/LmbrCentral_precompiled.h
#	Gems/LmbrCentral/Code/Tests/ShapeGeometryUtilTest.cpp
#	Gems/LyShine/Code/Editor/UiCanvasEditor_precompiled.h
#	Gems/LyShine/Code/Source/Animation/LyShine_precompiled.h
#	Gems/LyShine/Code/Source/LyShine_precompiled.h
#	Gems/LyShineExamples/Code/Source/LyShineExamples_precompiled.h
#	Gems/Maestro/Code/Source/Cinematics/Maestro_precompiled.h
#	Gems/Maestro/Code/Source/Maestro_precompiled.h
#	Gems/MessagePopup/Code/Source/MessagePopup_precompiled.h
#	Gems/Metastream/Code/Source/Metastream_precompiled.h
#	Gems/Microphone/Code/Source/Microphone_precompiled.h
#	Gems/Multiplayer/Code/Source/Multiplayer_precompiled.h
#	Gems/PhysX/Code/NumericalMethods/Source/NumericalMethods_precompiled.h
#	Gems/PhysX/Code/Source/PhysXUnsupported_precompiled.h
#	Gems/PhysX/Code/Source/PhysX_precompiled.h
#	Gems/PhysX/Code/physx_unsupported_files.cmake
#	Gems/PhysXDebug/Code/Source/PhysXDebugUnsupported_precompiled.h
#	Gems/PhysXDebug/Code/Source/PhysXDebug_precompiled.h
#	Gems/ScriptCanvas/Code/Editor/precompiled.h
#	Gems/ScriptCanvas/Code/Source/precompiled.h
#	Gems/ScriptCanvasDeveloper/Code/Source/precompiled.h
#	Gems/ScriptCanvasPhysics/Code/Source/ScriptCanvasPhysics_precompiled.h
#	Gems/ScriptEvents/Code/Source/precompiled.h
#	Gems/ScriptEvents/Code/Tests/Editor/EditorTests.cpp
#	Gems/ScriptedEntityTweener/Code/Source/ScriptedEntityTweener_precompiled.h
#	Gems/SliceFavorites/Code/Source/SliceFavorites_precompiled.h
#	Gems/StartingPointCamera/Code/Source/StartingPointCamera_precompiled.h
#	Gems/StartingPointInput/Code/Source/StartingPointInput_precompiled.h
#	Gems/StartingPointMovement/Code/Source/StartingPointMovement_precompiled.h
#	Gems/SurfaceData/Code/Source/SurfaceData_precompiled.h
#	Gems/TextureAtlas/Code/Source/TextureAtlas_precompiled.h
#	Gems/TickBusOrderViewer/Code/Source/TickBusOrderViewer_precompiled.h
#	Gems/Twitch/Code/Source/Twitch_precompiled.h
#	Gems/VirtualGamepad/Code/Source/VirtualGamepad_precompiled.h
#	Gems/WhiteBox/Code/Source/WhiteBoxUnsupported_precompiled.h
#	Gems/WhiteBox/Code/Source/WhiteBox_precompiled.h
2021-07-16 15:42:37 -07:00

230 lines
10 KiB
C++

/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include "InputConfigurationComponent.h"
#include "InputEventBindings.h"
#include "InputEventMap.h"
#include "InputLibrary.h"
#include <AzCore/Module/Module.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Module/Environment.h>
#include <AzCore/Component/Component.h>
#include <AzFramework/Asset/GenericAssetHandler.h>
namespace StartingPointInput
{
static bool ConvertToInputEventMap(AZ::SerializeContext& context, AZ::SerializeContext::DataElementNode& classElement)
{
// Capture the old values
AZStd::string deviceType;
classElement.GetChildData(AZ::Crc32("Input Device Type"), deviceType);
AZStd::string inputName;
classElement.GetChildData(AZ::Crc32("Input Name"), inputName);
float eventValueMultiplier;
classElement.GetChildData(AZ::Crc32("Event Value Multiplier"), eventValueMultiplier);
float deadZone;
classElement.GetChildData(AZ::Crc32("Dead Zone"), deadZone);
// Convert to the new class
classElement.Convert(context, AZ::AzTypeInfo<InputEventMap>::Uuid());
// Add the old values to the new class
classElement.AddElementWithData(context, "Input Device Type", deviceType);
classElement.AddElementWithData(context, "Input Name", inputName);
classElement.AddElementWithData(context, "Event Value Multiplier", eventValueMultiplier);
classElement.AddElementWithData(context, "Dead Zone", deadZone);
return true;
}
class BehaviorInputEventNotificationBusHandler : public InputEventNotificationBus::Handler, public AZ::BehaviorEBusHandler
{
public:
AZ_EBUS_BEHAVIOR_BINDER(BehaviorInputEventNotificationBusHandler, "{8AAEEB1A-21E2-4D2E-A719-73552D41F506}", AZ::SystemAllocator,
OnPressed, OnHeld, OnReleased);
void OnPressed(float value) override
{
Call(FN_OnPressed, value);
}
void OnHeld(float value) override
{
Call(FN_OnHeld, value);
}
void OnReleased(float value) override
{
Call(FN_OnReleased, value);
}
};
void InputEventNonIntrusiveConstructor(InputEventNotificationId* thisOutPtr, AZ::ScriptDataContext& dc)
{
if (dc.GetNumArguments() == 0)
{
// Use defaults.
}
else if (dc.GetNumArguments() == 1 && dc.IsString(0))
{
thisOutPtr->m_localUserId = AzFramework::LocalUserIdAny;
const char* actionName = nullptr;
dc.ReadArg(0, actionName);
thisOutPtr->m_actionNameCrc = AZ::Crc32(actionName);
}
else if (dc.GetNumArguments() == 2 && dc.IsClass<AZ::Crc32>(0) && dc.IsString(1))
{
AzFramework::LocalUserId localUserId = 0;
dc.ReadArg(0, localUserId);
thisOutPtr->m_localUserId = localUserId;
const char* actionName = nullptr;
dc.ReadArg(1, actionName);
thisOutPtr->m_actionNameCrc = AZ::Crc32(actionName);
}
else
{
AZ_Error("InputEventNotificationId", false, "The InputEventNotificationId takes one or two args. 1 argument: a string representing the input events name (determined by the event group). 2 arguments: a Crc of the profile channel, and a string representing the input event's name");
}
}
class StartingPointInputSystemComponent : public AZ::Component
{
public:
AZ_COMPONENT(StartingPointInputSystemComponent, "{95DE3485-5E51-42A9-899D-433EC3448AA3}");
static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
{
required.push_back(AZ_CRC("AssetDatabaseService"));
required.push_back(AZ_CRC("AssetCatalogService"));
}
static void Reflect(AZ::ReflectContext* context)
{
InputEventBindingsAsset::Reflect(context);
InputEventBindings::Reflect(context);
InputEventGroup::Reflect(context);
InputEventMap::Reflect(context);
InputLibrary::Reflect(context);
ThumbstickInputEventMap::Reflect(context);
if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<StartingPointInputSystemComponent, AZ::Component>()
->Version(1)
;
serializeContext->ClassDeprecate("Input", "{546C9EBC-90EF-4F03-891A-0736BE2A487E}", &ConvertToInputEventMap);
serializeContext->Class<InputEventNotificationId>()
->Version(1)
->Field("LocalUserId", &InputEventNotificationId::m_localUserId)
->Field("ActionName", &InputEventNotificationId::m_actionNameCrc)
;
if (AZ::EditContext* editContext = serializeContext->GetEditContext())
{
editContext->Class<StartingPointInputSystemComponent>(
"Starting point input", "Manages input bindings and events")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::Category, "Editor")
->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("System"))
;
}
}
if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
{
behaviorContext->Class<InputEventNotificationId>("InputEventNotificationId")
->Constructor<const char*>()
->Attribute(AZ::Script::Attributes::Storage, AZ::Script::Attributes::StorageType::Value)
->Attribute(AZ::Script::Attributes::ConstructorOverride, &InputEventNonIntrusiveConstructor)
->Property("actionNameCrc", BehaviorValueProperty(&InputEventNotificationId::m_actionNameCrc))
->Property("localUserId", BehaviorValueProperty(&InputEventNotificationId::m_localUserId))
->Method("ToString", &InputEventNotificationId::ToString)
->Attribute(AZ::Script::Attributes::Operator, AZ::Script::Attributes::OperatorType::ToString)
->Method("Equal", &InputEventNotificationId::operator==)
->Attribute(AZ::Script::Attributes::Operator, AZ::Script::Attributes::OperatorType::Equal)
->Method("Clone", &InputEventNotificationId::Clone)
->Property("actionName", nullptr, [](InputEventNotificationId* thisPtr, AZStd::string_view value) { *thisPtr = InputEventNotificationId(value.data()); })
->Method("CreateInputEventNotificationId", [](AzFramework::LocalUserId localUserId, AZStd::string_view value) -> InputEventNotificationId { return InputEventNotificationId(localUserId, value.data()); },
{ { { "localUserId", "Local User ID" },
{ "actionName", "The name of the Input event action used to create an InputEventNotificationId" } } });
behaviorContext->EBus<InputEventNotificationBus>("InputEventNotificationBus")
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::List)
->Handler<BehaviorInputEventNotificationBusHandler>()
->Event("OnPressed", &InputEventNotificationBus::Events::OnPressed)
->Event("OnHeld", &InputEventNotificationBus::Events::OnHeld)
->Event("OnReleased", &InputEventNotificationBus::Events::OnReleased);
}
}
void Init() override
{
AZ::EnvironmentVariable<ScriptCanvas::NodeRegistry> nodeRegistryVariable = AZ::Environment::FindVariable<ScriptCanvas::NodeRegistry>(ScriptCanvas::s_nodeRegistryName);
if (nodeRegistryVariable)
{
ScriptCanvas::NodeRegistry& nodeRegistry = nodeRegistryVariable.Get();
InputLibrary::InitNodeRegistry(nodeRegistry);
}
}
void Activate() override
{
// Register asset handlers. Requires "AssetDatabaseService"
AZ_Assert(AZ::Data::AssetManager::IsReady(), "Asset manager isn't ready!");
m_inputEventBindingsAssetHandler = aznew AzFramework::GenericAssetHandler<InputEventBindingsAsset>("Input Bindings", "Other", "inputbindings", AZ::AzTypeInfo<InputConfigurationComponent>::Uuid());
m_inputEventBindingsAssetHandler->Register();
}
void Deactivate() override
{
delete m_inputEventBindingsAssetHandler;
m_inputEventBindingsAssetHandler = nullptr;
}
private:
AzFramework::GenericAssetHandler<InputEventBindingsAsset>* m_inputEventBindingsAssetHandler = nullptr;
};
class StartingPointInputModule
: public AZ::Module
{
public:
AZ_RTTI(StartingPointInputModule, "{B30D421E-127D-4C46-90B1-AC3DDF3EC1D9}", AZ::Module);
StartingPointInputModule()
: AZ::Module()
{
m_descriptors.insert(m_descriptors.end(), {
InputConfigurationComponent::CreateDescriptor(),
StartingPointInputSystemComponent::CreateDescriptor(),
});
AZStd::vector<AZ::ComponentDescriptor*> componentDescriptors(InputLibrary::GetComponentDescriptors());
m_descriptors.insert(m_descriptors.end(), componentDescriptors.begin(), componentDescriptors.end());
}
AZ::ComponentTypeList GetRequiredSystemComponents() const override
{
return AZ::ComponentTypeList({ StartingPointInputSystemComponent::RTTI_Type() });
}
};
}
// DO NOT MODIFY THIS LINE UNLESS YOU RENAME THE GEM
// The first parameter should be GemName_GemIdLower
// The second should be the fully qualified name of the class above
AZ_DECLARE_MODULE_CLASS(Gem_StartingPointInput, StartingPointInput::StartingPointInputModule)