mirror of
https://github.com/sinbad/StevesUEHelpers.git
synced 2025-02-23 17:45:23 +00:00
Add the option to detect last axis move separately to input mode
This commit is contained in:
parent
d6c5ab1f08
commit
44f83c1f18
@ -36,6 +36,7 @@ void UStevesGameSubsystem::CreateInputDetector()
|
|||||||
|
|
||||||
InputDetector->OnInputModeChanged.BindUObject(this, &UStevesGameSubsystem::OnInputDetectorModeChanged);
|
InputDetector->OnInputModeChanged.BindUObject(this, &UStevesGameSubsystem::OnInputDetectorModeChanged);
|
||||||
InputDetector->OnButtonInputModeChanged.BindUObject(this, &UStevesGameSubsystem::OnButtonInputDetectorModeChanged);
|
InputDetector->OnButtonInputModeChanged.BindUObject(this, &UStevesGameSubsystem::OnButtonInputDetectorModeChanged);
|
||||||
|
InputDetector->OnAxisInputModeChanged.BindUObject(this, &UStevesGameSubsystem::OnAxisInputDetectorModeChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -130,6 +131,13 @@ void UStevesGameSubsystem::OnButtonInputDetectorModeChanged(int PlayerIndex, EIn
|
|||||||
OnButtonInputModeChanged.Broadcast(PlayerIndex, NewMode);
|
OnButtonInputModeChanged.Broadcast(PlayerIndex, NewMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UStevesGameSubsystem::OnAxisInputDetectorModeChanged(int PlayerIndex, EInputMode NewMode)
|
||||||
|
{
|
||||||
|
// This is specifically for button changes; if this is a different main input mode it will also be registered in OnInputDetectorModeChanged
|
||||||
|
// Just relay this one
|
||||||
|
OnAxisInputModeChanged.Broadcast(PlayerIndex, NewMode);
|
||||||
|
}
|
||||||
|
|
||||||
FFocusSystem* UStevesGameSubsystem::GetFocusSystem()
|
FFocusSystem* UStevesGameSubsystem::GetFocusSystem()
|
||||||
{
|
{
|
||||||
return &FocusSystem;
|
return &FocusSystem;
|
||||||
@ -295,6 +303,7 @@ UStevesGameSubsystem::FInputModeDetector::FInputModeDetector()
|
|||||||
// 4 local players should be plenty usually (will expand if necessary)
|
// 4 local players should be plenty usually (will expand if necessary)
|
||||||
LastInputModeByPlayer.Init(DefaultInputMode, 4);
|
LastInputModeByPlayer.Init(DefaultInputMode, 4);
|
||||||
LastButtonPressByPlayer.Init(DefaultButtonInputMode, 4);
|
LastButtonPressByPlayer.Init(DefaultButtonInputMode, 4);
|
||||||
|
LastAxisMoveByPlayer.Init(DefaultAxisInputMode, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UStevesGameSubsystem::FInputModeDetector::HandleKeyDownEvent(FSlateApplication& SlateApp, const FKeyEvent& InKeyEvent)
|
bool UStevesGameSubsystem::FInputModeDetector::HandleKeyDownEvent(FSlateApplication& SlateApp, const FKeyEvent& InKeyEvent)
|
||||||
@ -378,6 +387,15 @@ EInputMode UStevesGameSubsystem::FInputModeDetector::GetLastButtonInputMode(int
|
|||||||
return DefaultButtonInputMode;
|
return DefaultButtonInputMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EInputMode UStevesGameSubsystem::FInputModeDetector::GetLastAxisInputMode(int PlayerIndex)
|
||||||
|
{
|
||||||
|
if (PlayerIndex >= 0 && PlayerIndex < LastAxisMoveByPlayer.Num())
|
||||||
|
return LastAxisMoveByPlayer[PlayerIndex];
|
||||||
|
|
||||||
|
// Assume default if never told
|
||||||
|
return DefaultAxisInputMode;
|
||||||
|
}
|
||||||
|
|
||||||
void UStevesGameSubsystem::FInputModeDetector::ProcessKeyOrButton(int PlayerIndex, FKey Key)
|
void UStevesGameSubsystem::FInputModeDetector::ProcessKeyOrButton(int PlayerIndex, FKey Key)
|
||||||
{
|
{
|
||||||
if (Key.IsGamepadKey())
|
if (Key.IsGamepadKey())
|
||||||
@ -420,6 +438,7 @@ bool UStevesGameSubsystem::FInputModeDetector::IsAGamepadButton(const FKey& Key)
|
|||||||
void UStevesGameSubsystem::FInputModeDetector::SetMode(int PlayerIndex, EInputMode NewMode, bool bIsButton)
|
void UStevesGameSubsystem::FInputModeDetector::SetMode(int PlayerIndex, EInputMode NewMode, bool bIsButton)
|
||||||
{
|
{
|
||||||
bool bButtonChanged = false;
|
bool bButtonChanged = false;
|
||||||
|
bool bAxisChanged = false;
|
||||||
bool bMainChanged = false;
|
bool bMainChanged = false;
|
||||||
|
|
||||||
if (bIsButton)
|
if (bIsButton)
|
||||||
@ -434,6 +453,19 @@ void UStevesGameSubsystem::FInputModeDetector::SetMode(int PlayerIndex, EInputMo
|
|||||||
bButtonChanged = true;
|
bButtonChanged = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (NewMode != EInputMode::Unknown && NewMode != GetLastAxisInputMode(PlayerIndex))
|
||||||
|
{
|
||||||
|
if (PlayerIndex >= LastAxisMoveByPlayer.Num())
|
||||||
|
LastAxisMoveByPlayer.SetNum(PlayerIndex + 1);
|
||||||
|
|
||||||
|
LastAxisMoveByPlayer[PlayerIndex] = NewMode;
|
||||||
|
|
||||||
|
bAxisChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
// Whether it's a button or not it can affect the main input mode
|
// Whether it's a button or not it can affect the main input mode
|
||||||
if (NewMode != EInputMode::Unknown && NewMode != GetLastInputMode(PlayerIndex))
|
if (NewMode != EInputMode::Unknown && NewMode != GetLastInputMode(PlayerIndex))
|
||||||
{
|
{
|
||||||
@ -452,6 +484,12 @@ void UStevesGameSubsystem::FInputModeDetector::SetMode(int PlayerIndex, EInputMo
|
|||||||
OnButtonInputModeChanged.ExecuteIfBound(PlayerIndex, NewMode);
|
OnButtonInputModeChanged.ExecuteIfBound(PlayerIndex, NewMode);
|
||||||
//UE_LOG(LogStevesUEHelpers, Display, TEXT("Button mode for player %d changed: %s"), PlayerIndex, *UEnum::GetValueAsString(NewMode));
|
//UE_LOG(LogStevesUEHelpers, Display, TEXT("Button mode for player %d changed: %s"), PlayerIndex, *UEnum::GetValueAsString(NewMode));
|
||||||
}
|
}
|
||||||
|
if (bAxisChanged)
|
||||||
|
{
|
||||||
|
// ReSharper disable once CppExpressionWithoutSideEffects
|
||||||
|
OnAxisInputModeChanged.ExecuteIfBound(PlayerIndex, NewMode);
|
||||||
|
//UE_LOG(LogStevesUEHelpers, Display, TEXT("Axis mode for player %d changed: %s"), PlayerIndex, *UEnum::GetValueAsString(NewMode));
|
||||||
|
}
|
||||||
if (bMainChanged)
|
if (bMainChanged)
|
||||||
{
|
{
|
||||||
// ReSharper disable once CppExpressionWithoutSideEffects
|
// ReSharper disable once CppExpressionWithoutSideEffects
|
||||||
|
@ -65,9 +65,11 @@ protected:
|
|||||||
protected:
|
protected:
|
||||||
TArray<EInputMode> LastInputModeByPlayer;
|
TArray<EInputMode> LastInputModeByPlayer;
|
||||||
TArray<EInputMode> LastButtonPressByPlayer;
|
TArray<EInputMode> LastButtonPressByPlayer;
|
||||||
|
TArray<EInputMode> LastAxisMoveByPlayer;
|
||||||
|
|
||||||
const EInputMode DefaultInputMode = EInputMode::Mouse;
|
const EInputMode DefaultInputMode = EInputMode::Mouse;
|
||||||
const EInputMode DefaultButtonInputMode = EInputMode::Keyboard;
|
const EInputMode DefaultButtonInputMode = EInputMode::Keyboard;
|
||||||
|
const EInputMode DefaultAxisInputMode = EInputMode::Mouse;
|
||||||
const float MouseMoveThreshold = 1;
|
const float MouseMoveThreshold = 1;
|
||||||
const float GamepadAxisThreshold = 0.2;
|
const float GamepadAxisThreshold = 0.2;
|
||||||
|
|
||||||
@ -80,6 +82,8 @@ protected:
|
|||||||
FInternalInputModeChanged OnInputModeChanged;
|
FInternalInputModeChanged OnInputModeChanged;
|
||||||
/// Event raised when button input mode changes only
|
/// Event raised when button input mode changes only
|
||||||
FInternalInputModeChanged OnButtonInputModeChanged;
|
FInternalInputModeChanged OnButtonInputModeChanged;
|
||||||
|
/// Event raised when axis input mode changes only
|
||||||
|
FInternalInputModeChanged OnAxisInputModeChanged;
|
||||||
|
|
||||||
|
|
||||||
FInputModeDetector();
|
FInputModeDetector();
|
||||||
@ -96,6 +100,8 @@ protected:
|
|||||||
EInputMode GetLastInputMode(int PlayerIndex = 0);
|
EInputMode GetLastInputMode(int PlayerIndex = 0);
|
||||||
/// Get the last input mode from button inputs (ignores axis changes, good for detecting if keyboard or mouse buttons are being used)
|
/// Get the last input mode from button inputs (ignores axis changes, good for detecting if keyboard or mouse buttons are being used)
|
||||||
EInputMode GetLastButtonInputMode(int PlayerIndex = 0);
|
EInputMode GetLastButtonInputMode(int PlayerIndex = 0);
|
||||||
|
/// Get the last input mode from axis movement (ignores button presses, good for detecting if keyboard or mouse axes are being used for motion)
|
||||||
|
EInputMode GetLastAxisInputMode(int PlayerIndex = 0);
|
||||||
|
|
||||||
// Needed but unused
|
// Needed but unused
|
||||||
virtual void Tick(const float DeltaTime, FSlateApplication& SlateApp, TSharedRef<ICursor> Cursor) override {}
|
virtual void Tick(const float DeltaTime, FSlateApplication& SlateApp, TSharedRef<ICursor> Cursor) override {}
|
||||||
@ -131,6 +137,7 @@ protected:
|
|||||||
// Called by detector
|
// Called by detector
|
||||||
void OnInputDetectorModeChanged(int PlayerIndex, EInputMode NewMode);
|
void OnInputDetectorModeChanged(int PlayerIndex, EInputMode NewMode);
|
||||||
void OnButtonInputDetectorModeChanged(int PlayerIndex, EInputMode NewMode);
|
void OnButtonInputDetectorModeChanged(int PlayerIndex, EInputMode NewMode);
|
||||||
|
void OnAxisInputDetectorModeChanged(int PlayerIndex, EInputMode NewMode);
|
||||||
|
|
||||||
|
|
||||||
TSoftObjectPtr<UDataTable> GetGamepadImages(int PlayerIndex, const UUiTheme* Theme);
|
TSoftObjectPtr<UDataTable> GetGamepadImages(int PlayerIndex, const UUiTheme* Theme);
|
||||||
@ -148,6 +155,12 @@ public:
|
|||||||
UPROPERTY(BlueprintAssignable)
|
UPROPERTY(BlueprintAssignable)
|
||||||
FOnInputModeChanged OnButtonInputModeChanged;
|
FOnInputModeChanged OnButtonInputModeChanged;
|
||||||
|
|
||||||
|
/// Event raised when the last axis input changed between gamepad / keyboard / mouse
|
||||||
|
/// This can happen at a different time to OnInputModeChanged, e.g. if that was triggered by a button press, but the
|
||||||
|
/// last axis moved was still mouse, you'd get this event later
|
||||||
|
UPROPERTY(BlueprintAssignable)
|
||||||
|
FOnInputModeChanged OnAxisInputModeChanged;
|
||||||
|
|
||||||
/// Event raised when the game window's foreground status changes
|
/// Event raised when the game window's foreground status changes
|
||||||
UPROPERTY(BlueprintAssignable)
|
UPROPERTY(BlueprintAssignable)
|
||||||
FOnWindowForegroundChanged OnWindowForegroundChanged;
|
FOnWindowForegroundChanged OnWindowForegroundChanged;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user