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:
return GetInputImageSpriteFromAxis(ActionOrAxis, PlayerIdx, Theme);
case EInputBindingType::Key:
return GetInputImageSpriteFromKey(Key, Theme);
return GetInputImageSpriteFromKey(Key, PlayerIdx, Theme);
default:
return nullptr;
}
@ -158,13 +158,13 @@ UPaperSprite* UStevesGameSubsystem::GetInputImageSpriteFromAction(const FName& N
{
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 (GS_TempActionMap.Num())
{
return GetInputImageSpriteFromKey(GS_TempActionMap[0].Key, Theme);
return GetInputImageSpriteFromKey(GS_TempActionMap[0].Key, PlayerIdx, Theme);
}
return nullptr;
}
@ -180,18 +180,24 @@ UPaperSprite* UStevesGameSubsystem::GetInputImageSpriteFromAxis(const FName& Nam
{
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 (GS_TempAxisMap.Num())
{
return GetInputImageSpriteFromKey(GS_TempAxisMap[0].Key, Theme);
return GetInputImageSpriteFromKey(GS_TempAxisMap[0].Key, PlayerIdx, Theme);
}
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))
Theme = GetDefaultUiTheme();
@ -199,7 +205,7 @@ UPaperSprite* UStevesGameSubsystem::GetInputImageSpriteFromKey(const FKey& InKey
if (Theme)
{
if (InKey.IsGamepadKey())
return GetImageSpriteFromTable(InKey, Theme->XboxControllerImages);
return GetImageSpriteFromTable(InKey, GetGamepadImages(PlayerIndex, Theme));
else
return GetImageSpriteFromTable(InKey, Theme->KeyboardMouseImages);
}

View File

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