From d6c5ab1f08f477961964da57816f7d8ea1585915 Mon Sep 17 00:00:00 2001 From: Steve Streeting Date: Tue, 1 Feb 2022 15:04:40 +0000 Subject: [PATCH] Expose device preference for input bindings in rich text decorator --- .../RichTextBlockInputImageDecorator.cpp | 30 +++++++++++++++++-- doc/RichTextInputDecorator.md | 15 ++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/Source/StevesUEHelpers/Private/StevesUI/RichTextBlockInputImageDecorator.cpp b/Source/StevesUEHelpers/Private/StevesUI/RichTextBlockInputImageDecorator.cpp index e7f9c29..153a4ea 100644 --- a/Source/StevesUEHelpers/Private/StevesUI/RichTextBlockInputImageDecorator.cpp +++ b/Source/StevesUEHelpers/Private/StevesUI/RichTextBlockInputImageDecorator.cpp @@ -20,6 +20,9 @@ struct FRichTextInputImageParams FKey Key; /// Player index, if binding type is action or axis int PlayerIndex; + /// Where there are multiple mappings, which to prefer + EInputImageDevicePreference DevicePreference = EInputImageDevicePreference::Auto; + /// Initial Sprite to use UPaperSprite* InitialSprite; /// Parent decorator, for looking up things later @@ -37,6 +40,8 @@ protected: FKey Key; /// Player index, if binding type is action or axis int PlayerIndex = 0; + /// Where there are multiple mappings, which to prefer + EInputImageDevicePreference DevicePreference = EInputImageDevicePreference::Auto; /// Parent decorator, for looking up things later URichTextBlockInputImageDecorator* Decorator = nullptr; @@ -59,6 +64,7 @@ public: { BindingType = InParams.BindingType; ActionOrAxisName = InParams.ActionOrAxisName; + DevicePreference = InParams.DevicePreference; Key = InParams.Key; PlayerIndex = InParams.PlayerIndex; Decorator = InParams.Decorator; @@ -122,7 +128,7 @@ public: if (GS) { // Can only support default theme, no way to edit theme in decorator config - auto Sprite = GS->GetInputImageSprite(BindingType, ActionOrAxisName, Key, EInputImageDevicePreference::Auto, PlayerIndex); + auto Sprite = GS->GetInputImageSprite(BindingType, ActionOrAxisName, Key, DevicePreference, PlayerIndex); if (Sprite && Brush.GetResourceObject() != Sprite) { UStevesGameSubsystem::SetBrushFromAtlas(&Brush, Sprite, true); @@ -207,6 +213,26 @@ protected: Params.ActionOrAxisName = **AxisStr; } + if (const FString* PreferStr = RunInfo.MetaData.Find(TEXT("prefer"))) + { + if (PreferStr->Equals("auto", ESearchCase::IgnoreCase)) + { + Params.DevicePreference = EInputImageDevicePreference::Auto; + } + else if (PreferStr->Equals("gkm", ESearchCase::IgnoreCase)) + { + Params.DevicePreference = EInputImageDevicePreference::Gamepad_Keyboard_Mouse; + } + else if (PreferStr->Equals("gmk", ESearchCase::IgnoreCase)) + { + Params.DevicePreference = EInputImageDevicePreference::Gamepad_Mouse_Keyboard; + } + else if (PreferStr->Equals("gmkbutton", ESearchCase::IgnoreCase)) + { + Params.DevicePreference = EInputImageDevicePreference::Gamepad_Keyboard_Mouse_Button; + } + } + // Look up the initial sprite here // The Slate widget can't do it in Construct because World pointer doesn't work (thread issues?) // Also annoying: can't keep Brush on this class because this method is const. UGH @@ -214,7 +240,7 @@ protected: if (GS) { // Can only support default theme, no way to edit theme in decorator config - Params.InitialSprite = GS->GetInputImageSprite(Params.BindingType, Params.ActionOrAxisName, Params.Key, EInputImageDevicePreference::Auto, Params.PlayerIndex); + Params.InitialSprite = GS->GetInputImageSprite(Params.BindingType, Params.ActionOrAxisName, Params.Key, Params.DevicePreference, Params.PlayerIndex); } else { diff --git a/doc/RichTextInputDecorator.md b/doc/RichTextInputDecorator.md index ca085e7..2ba1629 100644 --- a/doc/RichTextInputDecorator.md +++ b/doc/RichTextInputDecorator.md @@ -81,6 +81,21 @@ derive the width from that based on the aspect ratio. It's generally best just to set the height and not the width as well, since setting both can cause the image to be distorted if it's not the same aspect ratio. +### Device Preference + +For the `action` and `axis` types, which device to prefer to show the image for +can be specified with the `prefer="x"` attribute. The default is `prefer="auto"`, which means: + +1. Gamepad, if the last used device was gamepad +2. If an Action (button/key), prefer Keyboard over Mouse buttons +3. If an Axis, prefer Mouse over Keyboard + +Alternatives are: + +* `prefer="gkm"`: prefer Gamepad, then Keyboard, then Mouse +* `prefer="gmk"`: prefer Gamepad, then Mouse, then Keyboard +* `prefer="gmkbutton"`: prefer Gamepad, then whichever of Mouse ot Keyboard last had a button pressed + ## See Also * [Input Image](InputImage.md) \ No newline at end of file