Final design of 'If Key is Reserved' routine

This commit is contained in:
2025-05-27 17:49:18 -04:00
parent 23194ac0e5
commit c4479b4d59
6 changed files with 18 additions and 81 deletions

View File

@@ -212,10 +212,8 @@ void UlxUtilityLibrary::GetPositionOfGridPanelMiddleCell(UGridPanel *GridPanel,
}
}
ElxUsedOrNotUsed UlxUtilityLibrary::IsKeyUsedByMappingContext(const FKeyEvent &KeyEvent, const UInputMappingContext *MappingContext)
ElxUsedOrNotUsed UlxUtilityLibrary::IsKeyUsedByMappingContext(const FKey &Key, const UInputMappingContext *MappingContext)
{
FKey Key = KeyEvent.GetKey();
if (!MappingContext)
{
return ElxUsedOrNotUsed::NotUsed;
@@ -223,69 +221,9 @@ ElxUsedOrNotUsed UlxUtilityLibrary::IsKeyUsedByMappingContext(const FKeyEvent &K
for (const FEnhancedActionKeyMapping& Mapping : MappingContext->GetMappings())
{
if (Mapping.Key == Key)
{
return ElxUsedOrNotUsed::Used;
}
if (Mapping.Key == 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;
}