Final design of 'If Key is Reserved' routine
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -133,21 +133,11 @@ public:
|
||||
UFUNCTION(BlueprintPure, Category="Widget")
|
||||
static void GetPositionOfGridPanelMiddleCell(UGridPanel *GridPanel, FVector2D &UpperLeftXY, FVector2D &LowerRightXY);
|
||||
|
||||
// Check if a given key is used by the mapping context.
|
||||
// Check if a given key is used by the specified mapping context.
|
||||
//
|
||||
// This is true if the key is mapped to anything at all within
|
||||
// the specified mapping context.
|
||||
//
|
||||
UFUNCTION(BlueprintCallable, Category = "Input", meta = (ExpandEnumAsExecs="ReturnValue"))
|
||||
static ElxUsedOrNotUsed IsKeyUsedByMappingContext(const FKeyEvent &KeyEvent, const UInputMappingContext *MappingContext);
|
||||
|
||||
// Check if a given key is used by the player controller.
|
||||
//
|
||||
// If you pass in a null pointer for the player controller, then this
|
||||
// function will use the first player controller by default.
|
||||
//
|
||||
// If 'Include Escape and FKeys' is checked, then the escape key
|
||||
// and the function keys are also considered to be 'used' by the
|
||||
// player controller. It is generally a good idea to treat these
|
||||
// keys as reserved for play-in-editor.
|
||||
//
|
||||
UFUNCTION(BlueprintCallable, Category = "Input", meta = (WorldContext="Context", ExpandEnumAsExecs="ReturnValue", IncludeEscapeAndFkeys="true"))
|
||||
static ElxUsedOrNotUsed IsKeyUsedByPlayerController(const FKeyEvent &KeyEvent, bool IncludeEscapeAndFkeys, const APlayerController *PlayerController, const UObject *Context);
|
||||
static ElxUsedOrNotUsed IsKeyUsedByMappingContext(const FKey &Key, const UInputMappingContext *MappingContext);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user