42 lines
1.5 KiB
C++
42 lines
1.5 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "LyraActionWidget.h"
|
|
|
|
#include "CommonInputBaseTypes.h"
|
|
#include "CommonInputSubsystem.h"
|
|
#include "Engine/LocalPlayer.h"
|
|
#include "EnhancedInputSubsystems.h"
|
|
|
|
FSlateBrush ULyraActionWidget::GetIcon() const
|
|
{
|
|
// If there is an Enhanced Input action associated with this widget, then search for any
|
|
// keys bound to that action and display those instead of the default data table settings.
|
|
// This covers the case of when a player has rebound a key to something else
|
|
if (AssociatedInputAction)
|
|
{
|
|
if (const UEnhancedInputLocalPlayerSubsystem* EnhancedInputSubsystem = GetEnhancedInputSubsystem())
|
|
{
|
|
TArray<FKey> BoundKeys = EnhancedInputSubsystem->QueryKeysMappedToAction(AssociatedInputAction);
|
|
FSlateBrush SlateBrush;
|
|
|
|
const UCommonInputSubsystem* CommonInputSubsystem = GetInputSubsystem();
|
|
if (!BoundKeys.IsEmpty() && CommonInputSubsystem && UCommonInputPlatformSettings::Get()->TryGetInputBrush(SlateBrush, BoundKeys[0], CommonInputSubsystem->GetCurrentInputType(), CommonInputSubsystem->GetCurrentGamepadName()))
|
|
{
|
|
return SlateBrush;
|
|
}
|
|
}
|
|
}
|
|
|
|
return Super::GetIcon();
|
|
}
|
|
|
|
UEnhancedInputLocalPlayerSubsystem* ULyraActionWidget::GetEnhancedInputSubsystem() const
|
|
{
|
|
const UWidget* BoundWidget = DisplayedBindingHandle.GetBoundWidget();
|
|
if (const ULocalPlayer* BindingOwner = BoundWidget ? BoundWidget->GetOwningLocalPlayer() : GetOwningLocalPlayer())
|
|
{
|
|
return BindingOwner->GetSubsystem<UEnhancedInputLocalPlayerSubsystem>();
|
|
}
|
|
return nullptr;
|
|
}
|