mirror of
https://github.com/sinbad/StevesUEHelpers.git
synced 2025-02-23 17:45:23 +00:00
InputImage now prefers the latest button input device for actions, this better differentiates between prompting for mouse button and keyboard
This commit is contained in:
parent
ecf1ea309b
commit
8926bf356c
@ -10,12 +10,13 @@ TSharedRef<SWidget> UInputImage::RebuildWidget()
|
||||
auto Ret = Super::RebuildWidget();
|
||||
|
||||
auto GS = GetStevesGameSubsystem(GetWorld());
|
||||
if (GS)
|
||||
if (GS && !bSubbedToInputEvents)
|
||||
{
|
||||
bSubbedToInputEvents = true;
|
||||
GS->OnInputModeChanged.AddUniqueDynamic(this, &UInputImage::OnInputModeChanged);
|
||||
CurrentInputMode = GS->GetLastInputModeUsed(PlayerIndex);
|
||||
UpdateImage();
|
||||
GS->OnButtonInputModeChanged.AddUniqueDynamic(this, &UInputImage::OnInputModeChanged);
|
||||
}
|
||||
UpdateImage();
|
||||
|
||||
return Ret;
|
||||
}
|
||||
@ -24,7 +25,10 @@ void UInputImage::OnInputModeChanged(int ChangedPlayerIdx, EInputMode InputMode)
|
||||
{
|
||||
if (ChangedPlayerIdx == PlayerIndex)
|
||||
{
|
||||
CurrentInputMode = InputMode;
|
||||
// auto GS = GetStevesGameSubsystem(GetWorld());
|
||||
// UE_LOG(LogTemp, Warning, TEXT("Updating image for input mode change: %s Button device: %s"),
|
||||
// *UEnum::GetValueAsString(InputMode),
|
||||
// *UEnum::GetValueAsString(GS->GetLastInputButtonPressed(ChangedPlayerIdx)));
|
||||
UpdateImage();
|
||||
}
|
||||
}
|
||||
@ -43,9 +47,29 @@ void UInputImage::BeginDestroy()
|
||||
if (GS)
|
||||
{
|
||||
GS->OnInputModeChanged.RemoveAll(this);
|
||||
GS->OnButtonInputModeChanged.RemoveAll(this);
|
||||
}
|
||||
}
|
||||
|
||||
void UInputImage::SetVisibility(ESlateVisibility InVisibility)
|
||||
{
|
||||
Super::SetVisibility(InVisibility);
|
||||
|
||||
switch(InVisibility)
|
||||
{
|
||||
case ESlateVisibility::Collapsed:
|
||||
case ESlateVisibility::Hidden:
|
||||
break;
|
||||
default:
|
||||
case ESlateVisibility::Visible:
|
||||
case ESlateVisibility::HitTestInvisible:
|
||||
case ESlateVisibility::SelfHitTestInvisible:
|
||||
// Make sure we update when our visibility is changed
|
||||
UpdateImage();
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
void UInputImage::SetFromAction(FName Name)
|
||||
{
|
||||
BindingType = EInputBindingType::Action;
|
||||
|
@ -29,7 +29,8 @@ void SetWidgetFocusProperly(UWidget* Widget);
|
||||
template <typename T>
|
||||
const T* GetPreferedActionOrAxisMapping(const TArray<T>& AllMappings, const FName& Name,
|
||||
EInputImageDevicePreference DevicePreference,
|
||||
bool bLastInputWasGamepad)
|
||||
EInputMode LastInputDevice,
|
||||
EInputMode LastButtonInputDevice)
|
||||
{
|
||||
const T* MouseMapping = nullptr;
|
||||
const T* KeyboardMapping = nullptr;
|
||||
@ -53,8 +54,9 @@ const T* GetPreferedActionOrAxisMapping(const TArray<T>& AllMappings, const FNam
|
||||
}
|
||||
|
||||
const T* Preferred = nullptr;
|
||||
if (GamepadMapping && bLastInputWasGamepad)
|
||||
if (GamepadMapping && LastInputDevice == EInputMode::Gamepad)
|
||||
{
|
||||
// Always prefer gamepad if used last
|
||||
Preferred = GamepadMapping;
|
||||
}
|
||||
else
|
||||
@ -71,6 +73,11 @@ const T* GetPreferedActionOrAxisMapping(const TArray<T>& AllMappings, const FNam
|
||||
case EInputImageDevicePreference::Gamepad_Mouse_Keyboard:
|
||||
Preferred = MouseMapping ? MouseMapping : KeyboardMapping;
|
||||
break;
|
||||
|
||||
case EInputImageDevicePreference::Gamepad_Keyboard_Mouse_Button:
|
||||
// Use the latest button press
|
||||
Preferred = (MouseMapping && LastButtonInputDevice == EInputMode::Mouse) ? MouseMapping : KeyboardMapping;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -53,11 +53,13 @@ enum class EInputBindingType : uint8
|
||||
UENUM(BlueprintType)
|
||||
enum class EInputImageDevicePreference : uint8
|
||||
{
|
||||
/// For actions, use Gamepad_Keyboard_Mouse, for axes, use Gamepad_Mouse_Keyboard
|
||||
/// For actions, use Gamepad_Keyboard_Mouse_Button, for axes, use Gamepad_Mouse_Keyboard
|
||||
Auto,
|
||||
/// Gamepad first, then keyboard, then mouse - this is usually best for actions (buttons)
|
||||
Gamepad_Keyboard_Mouse UMETA(DisplayName="Prefer Gamepad (if active), then keyboard, then mouse"),
|
||||
/// Gamepad first, then keyboard, then mouse
|
||||
Gamepad_Keyboard_Mouse UMETA(DisplayName="Gamepad, Keyboard, Mouse"),
|
||||
/// Gamepad first, then mouse, then keyboard - this is usually best for axes
|
||||
Gamepad_Mouse_Keyboard UMETA(DisplayName="Prefer Gamepad (if active), then mouse, then keyboard")
|
||||
Gamepad_Mouse_Keyboard UMETA(DisplayName="Gamepad, Mouse, Keyboard"),
|
||||
/// Gamepad first, then whichever of mouse or keyboard last had a BUTTON pressed (ignore axes) - this is usually best for actions (buttons)
|
||||
Gamepad_Keyboard_Mouse_Button UMETA(DisplayName="Gamepad, Most Recent Button Keyboard/Mouse")
|
||||
};
|
||||
|
||||
|
@ -38,9 +38,8 @@ protected:
|
||||
/// Custom theme to use for this input image set; if not supplied will use UStevesGameSubsystem::DefaultUiTheme
|
||||
UPROPERTY(EditAnywhere)
|
||||
UUiTheme* CustomTheme;
|
||||
|
||||
EInputMode CurrentInputMode;
|
||||
|
||||
bool bSubbedToInputEvents = false;
|
||||
public:
|
||||
|
||||
/// Tell this image to display the bound action for the current input method
|
||||
@ -73,6 +72,9 @@ public:
|
||||
virtual void SetCustomTheme(UUiTheme* Theme);
|
||||
|
||||
virtual void BeginDestroy() override;
|
||||
|
||||
virtual void SetVisibility(ESlateVisibility InVisibility) override;
|
||||
|
||||
protected:
|
||||
|
||||
virtual TSharedRef<SWidget> RebuildWidget() override;
|
||||
|
Loading…
x
Reference in New Issue
Block a user