Finish implementing IsKeyUsedByPlayerController
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
#include "Blueprint/UserWidget.h"
|
||||
#include "Components/GridPanel.h"
|
||||
#include "InputMappingContext.h"
|
||||
|
||||
#include "EnhancedInputComponent.h"
|
||||
|
||||
|
||||
#define LOCTEXT_NAMESPACE "Luprex Utility"
|
||||
@@ -212,20 +212,80 @@ void UlxUtilityLibrary::GetPositionOfGridPanelMiddleCell(UGridPanel *GridPanel,
|
||||
}
|
||||
}
|
||||
|
||||
void UlxUtilityLibrary::MapAllKeyboardKeysToOneInputAction(UInputMappingContext *IMC, UInputAction *Action)
|
||||
ElxUsedOrNotUsed UlxUtilityLibrary::IsKeyUsedByMappingContext(const FKeyEvent &KeyEvent, const UInputMappingContext *MappingContext)
|
||||
{
|
||||
TArray<FKey> AllKeys;
|
||||
EKeys::GetAllKeys(AllKeys);
|
||||
|
||||
// Map every keyboard key to the provided LuaAction
|
||||
for (const FKey& Key : AllKeys)
|
||||
FKey Key = KeyEvent.GetKey();
|
||||
|
||||
if (!MappingContext)
|
||||
{
|
||||
if ((Key.IsValid()) &&
|
||||
(Key.IsBindableInBlueprints()) &&
|
||||
(Key.GetMenuCategory() == EKeys::NAME_KeyboardCategory) &&
|
||||
(!Key.IsModifierKey()))
|
||||
return ElxUsedOrNotUsed::NotUsed;
|
||||
}
|
||||
|
||||
for (const FEnhancedActionKeyMapping& Mapping : MappingContext->GetMappings())
|
||||
{
|
||||
if (Mapping.Key == Key)
|
||||
{
|
||||
IMC->MapKey(Action, Key);
|
||||
return ElxUsedOrNotUsed::Used;
|
||||
}
|
||||
}
|
||||
|
||||
return ElxUsedOrNotUsed::NotUsed;
|
||||
}
|
||||
|
||||
class UEnhancedPlayerInputExposed : public UEnhancedPlayerInput
|
||||
{
|
||||
public:
|
||||
const TArray<FEnhancedActionKeyMapping>& GetEnhancedActionMappings() const { return UEnhancedPlayerInput::GetEnhancedActionMappings(); }
|
||||
};
|
||||
|
||||
ElxUsedOrNotUsed UlxUtilityLibrary::IsKeyUsedByPlayerController(const FKeyEvent &KeyEvent, bool IncludeEscapeAndFkeys, const APlayerController *PlayerController, const UObject *Context)
|
||||
{
|
||||
if (PlayerController == nullptr) PlayerController = Context->GetWorld()->GetFirstPlayerController();
|
||||
|
||||
FKey Key = KeyEvent.GetKey();
|
||||
|
||||
UEnhancedPlayerInput *PlayerInput = Cast<UEnhancedPlayerInput>(PlayerController->PlayerInput);
|
||||
if (PlayerInput == nullptr)
|
||||
{
|
||||
return ElxUsedOrNotUsed::NotUsed;
|
||||
}
|
||||
UEnhancedPlayerInputExposed *Exposed = static_cast<UEnhancedPlayerInputExposed *>(PlayerInput);
|
||||
|
||||
for (const FInputActionKeyMapping& ActionMapping : Exposed->ActionMappings)
|
||||
{
|
||||
if (ActionMapping.Key == Key)
|
||||
{
|
||||
return ElxUsedOrNotUsed::Used; // Found a match in legacy Action Mappings.
|
||||
}
|
||||
}
|
||||
|
||||
for (const FInputAxisKeyMapping& AxisMapping : Exposed->AxisMappings)
|
||||
{
|
||||
if (AxisMapping.Key == Key)
|
||||
{
|
||||
return ElxUsedOrNotUsed::Used; // Found a match in legacy Axis Mappings.
|
||||
}
|
||||
}
|
||||
|
||||
for (const FEnhancedActionKeyMapping& Mapping : Exposed->GetEnhancedActionMappings())
|
||||
{
|
||||
if (Mapping.Key == Key)
|
||||
{
|
||||
return ElxUsedOrNotUsed::Used; // Found a match in the active, flattened mappings.
|
||||
}
|
||||
}
|
||||
|
||||
if (IncludeEscapeAndFkeys)
|
||||
{
|
||||
if (Key == EKeys::Escape ||
|
||||
Key == EKeys::F1 || Key == EKeys::F2 || Key == EKeys::F3 ||
|
||||
Key == EKeys::F4 || Key == EKeys::F5 || Key == EKeys::F6 ||
|
||||
Key == EKeys::F7 || Key == EKeys::F8 || Key == EKeys::F9 ||
|
||||
Key == EKeys::F10 || Key == EKeys::F11 || Key == EKeys::F12)
|
||||
{
|
||||
return ElxUsedOrNotUsed::Used;
|
||||
}
|
||||
}
|
||||
|
||||
return ElxUsedOrNotUsed::NotUsed;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user