/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #include "VirtualGamepad_precompiled.h" #include "VirtualGamepadButtonComponent.h" #include #include #include #include #include //////////////////////////////////////////////////////////////////////////////////////////////////// namespace VirtualGamepad { //////////////////////////////////////////////////////////////////////////////////////////////// void VirtualGamepadButtonComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided) { provided.push_back(AZ_CRC("VirtualGamepadButtonService")); } //////////////////////////////////////////////////////////////////////////////////////////////// void VirtualGamepadButtonComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible) { incompatible.push_back(AZ_CRC("VirtualGamepadButtonService")); } //////////////////////////////////////////////////////////////////////////////////////////////// void VirtualGamepadButtonComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required) { required.push_back(AZ_CRC("UiInteractableService", 0x1d474c98)); } //////////////////////////////////////////////////////////////////////////////////////////////// void VirtualGamepadButtonComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent) { AZ_UNUSED(dependent); } //////////////////////////////////////////////////////////////////////////////////////////////// void VirtualGamepadButtonComponent::Reflect(AZ::ReflectContext* context) { if (AZ::SerializeContext* serialize = azrtti_cast(context)) { serialize->Class() ->Version(0) ->Field("AssignedInputChannelName", &VirtualGamepadButtonComponent::m_assignedInputChannelName) ; if (AZ::EditContext* ec = serialize->GetEditContext()) { ec->Class("VirtualGamepadButton", "A component that designates this entity as a virtual gamepad button") ->ClassElement(AZ::Edit::ClassElements::EditorData, "") ->Attribute(AZ::Edit::Attributes::Icon, "Editor/Icons/Components/UiVirtualButton.png") ->Attribute(AZ::Edit::Attributes::ViewportIcon, "Editor/Icons/Components/Viewport/UiVirtualButton.png") ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("UI", 0x27ff46b0)) ->Attribute(AZ::Edit::Attributes::AutoExpand, true) ->DataElement(AZ::Edit::UIHandlers::ComboBox, &VirtualGamepadButtonComponent::m_assignedInputChannelName, "Input Channel", "The input channel that will be updated when the user interacts with this virtual control") ->Attribute(AZ::Edit::Attributes::StringList, &VirtualGamepadButtonComponent::GetAssignableInputChannelNames) ; } } } //////////////////////////////////////////////////////////////////////////////////////////////// void VirtualGamepadButtonComponent::Init() { } //////////////////////////////////////////////////////////////////////////////////////////////// void VirtualGamepadButtonComponent::Activate() { VirtualGamepadButtonRequestBus::Handler::BusConnect(m_assignedInputChannelName); } //////////////////////////////////////////////////////////////////////////////////////////////// void VirtualGamepadButtonComponent::Deactivate() { VirtualGamepadButtonRequestBus::Handler::BusDisconnect(m_assignedInputChannelName); } //////////////////////////////////////////////////////////////////////////////////////////////// bool VirtualGamepadButtonComponent::IsPressed() const { bool isPressed = false; UiInteractableBus::EventResult(isPressed, GetEntityId(), &UiInteractableInterface::IsPressed); return isPressed; } //////////////////////////////////////////////////////////////////////////////////////////////// AZStd::vector VirtualGamepadButtonComponent::GetAssignableInputChannelNames() const { AZStd::unordered_set buttonNames; VirtualGamepadRequestBus::BroadcastResult(buttonNames, &VirtualGamepadRequests::GetButtonNames); AZStd::vector assignableInputChannelNames; for (const AZStd::string& buttonName : buttonNames) { assignableInputChannelNames.push_back(buttonName); } AZStd::sort(assignableInputChannelNames.begin(), assignableInputChannelNames.end()); return assignableInputChannelNames; } } // namespace VirtualGamepad