Preparing the ground for non-XBox controller images

In practice I think I'm going to need SDL input for this
This commit is contained in:
Steve Streeting 2021-04-29 14:54:42 +01:00
parent 510423abfe
commit 4422e6f6f7
2 changed files with 17 additions and 8 deletions

View File

@ -136,7 +136,7 @@ UPaperSprite* UStevesGameSubsystem::GetInputImageSprite(EInputBindingType Bindin
case EInputBindingType::Axis: case EInputBindingType::Axis:
return GetInputImageSpriteFromAxis(ActionOrAxis, PlayerIdx, Theme); return GetInputImageSpriteFromAxis(ActionOrAxis, PlayerIdx, Theme);
case EInputBindingType::Key: case EInputBindingType::Key:
return GetInputImageSpriteFromKey(Key, Theme); return GetInputImageSpriteFromKey(Key, PlayerIdx, Theme);
default: default:
return nullptr; return nullptr;
} }
@ -158,13 +158,13 @@ UPaperSprite* UStevesGameSubsystem::GetInputImageSpriteFromAction(const FName& N
{ {
if (ActionMap.Key.IsGamepadKey() == WantGamepad) if (ActionMap.Key.IsGamepadKey() == WantGamepad)
{ {
return GetInputImageSpriteFromKey(ActionMap.Key, Theme); return GetInputImageSpriteFromKey(ActionMap.Key, PlayerIdx, Theme);
} }
} }
// if we fell through, didn't find a mapping which matched our gamepad preference // if we fell through, didn't find a mapping which matched our gamepad preference
if (GS_TempActionMap.Num()) if (GS_TempActionMap.Num())
{ {
return GetInputImageSpriteFromKey(GS_TempActionMap[0].Key, Theme); return GetInputImageSpriteFromKey(GS_TempActionMap[0].Key, PlayerIdx, Theme);
} }
return nullptr; return nullptr;
} }
@ -180,18 +180,24 @@ UPaperSprite* UStevesGameSubsystem::GetInputImageSpriteFromAxis(const FName& Nam
{ {
if (AxisMap.Key.IsGamepadKey() == WantGamepad) if (AxisMap.Key.IsGamepadKey() == WantGamepad)
{ {
return GetInputImageSpriteFromKey(AxisMap.Key, Theme); return GetInputImageSpriteFromKey(AxisMap.Key, PlayerIdx, Theme);
} }
} }
// if we fell through, didn't find a mapping which matched our gamepad preference // if we fell through, didn't find a mapping which matched our gamepad preference
if (GS_TempAxisMap.Num()) if (GS_TempAxisMap.Num())
{ {
return GetInputImageSpriteFromKey(GS_TempAxisMap[0].Key, Theme); return GetInputImageSpriteFromKey(GS_TempAxisMap[0].Key, PlayerIdx, Theme);
} }
return nullptr; return nullptr;
} }
UPaperSprite* UStevesGameSubsystem::GetInputImageSpriteFromKey(const FKey& InKey, const UUiTheme* Theme) TSoftObjectPtr<UDataTable> UStevesGameSubsystem::GetGamepadImages(int PlayerIndex, const UUiTheme* Theme)
{
// TODO: determine type of controller
return Theme->XboxControllerImages;
}
UPaperSprite* UStevesGameSubsystem::GetInputImageSpriteFromKey(const FKey& InKey, int PlayerIndex, const UUiTheme* Theme)
{ {
if (!IsValid(Theme)) if (!IsValid(Theme))
Theme = GetDefaultUiTheme(); Theme = GetDefaultUiTheme();
@ -199,7 +205,7 @@ UPaperSprite* UStevesGameSubsystem::GetInputImageSpriteFromKey(const FKey& InKey
if (Theme) if (Theme)
{ {
if (InKey.IsGamepadKey()) if (InKey.IsGamepadKey())
return GetImageSpriteFromTable(InKey, Theme->XboxControllerImages); return GetImageSpriteFromTable(InKey, GetGamepadImages(PlayerIndex, Theme));
else else
return GetImageSpriteFromTable(InKey, Theme->KeyboardMouseImages); return GetImageSpriteFromTable(InKey, Theme->KeyboardMouseImages);
} }

View File

@ -119,6 +119,8 @@ protected:
// Called by detector // Called by detector
void OnInputDetectorModeChanged(int PlayerIndex, EInputMode NewMode); void OnInputDetectorModeChanged(int PlayerIndex, EInputMode NewMode);
TSoftObjectPtr<UDataTable> GetGamepadImages(int PlayerIndex, const UUiTheme* Theme);
UPaperSprite* GetImageSpriteFromTable(const FKey& Key, const TSoftObjectPtr<UDataTable>& Asset); UPaperSprite* GetImageSpriteFromTable(const FKey& Key, const TSoftObjectPtr<UDataTable>& Asset);
public: public:
@ -178,13 +180,14 @@ public:
* @return * @return
*/ */
UPaperSprite* GetInputImageSpriteFromAxis(const FName& Name, int PlayerIndex = 0, const UUiTheme* Theme = nullptr); UPaperSprite* GetInputImageSpriteFromAxis(const FName& Name, int PlayerIndex = 0, const UUiTheme* Theme = nullptr);
/** /**
* @brief Get an input image for a specific key * @brief Get an input image for a specific key
* @param Key The key to look up * @param Key The key to look up
* @param Theme Optional explicit theme, if blank use the default theme * @param Theme Optional explicit theme, if blank use the default theme
* @return * @return
*/ */
UPaperSprite* GetInputImageSpriteFromKey(const FKey& Key, const UUiTheme* Theme = nullptr); UPaperSprite* GetInputImageSpriteFromKey(const FKey& Key, int PlayerIndex = 0, const UUiTheme* Theme = nullptr);
/** /**
* @brief Set the content of a slate brush from an atlas (e.g. sprite) * @brief Set the content of a slate brush from an atlas (e.g. sprite)