From 6cf4ec357bdc5477b7f88456ab900de4d5c8e247 Mon Sep 17 00:00:00 2001 From: Pheazant Date: Wed, 27 Dec 2023 23:46:42 -0500 Subject: [PATCH] Added basic controller LED (e.g. Dualshock 4) support --- src/common/gfx.cpp | 7 +++++++ src/common/gfx.h | 2 ++ src/smw/ui/MI_TeamSelect.cpp | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/src/common/gfx.cpp b/src/common/gfx.cpp index 9c0a86d64..8a0cd6b83 100644 --- a/src/common/gfx.cpp +++ b/src/common/gfx.cpp @@ -637,3 +637,10 @@ bool gfx_loadimage(gfxSprite * gSprite, const std::string& f, Uint8 r, Uint8 g, return fRet; } + +void gfx_setjoystickteamcolor(SDL_Joystick * joystick, unsigned short team, Uint8 brightness) +{ + uint8_t r = 0, g = 0, b = 0; + gfx.getPalette().copyColorSchemeTo(team, 0, 5, r, g, b); + SDL_JoystickSetLED(joystick, ((short)brightness + 1) * r >> 8, ((short)brightness + 1) * g >> 8, ((short)brightness + 1) * b >> 8); +} diff --git a/src/common/gfx.h b/src/common/gfx.h index 22be33e5e..dd8332883 100644 --- a/src/common/gfx.h +++ b/src/common/gfx.h @@ -60,4 +60,6 @@ bool gfx_loadimage(gfxSprite * gSprite, const std::string& f, bool fWrap = true, bool gfx_loadimage(gfxSprite * gSprite, const std::string& f, Uint8 alpha, bool fWrap = true, bool fUseAccel = true); bool gfx_loadimage(gfxSprite * gSprite, const std::string& f, Uint8 r, Uint8 g, Uint8 b, bool fWrap = true, bool fUseAccel = true); +void gfx_setjoystickteamcolor(SDL_Joystick * joystick, unsigned short team, Uint8 brightness); + #endif // GFX_H diff --git a/src/smw/ui/MI_TeamSelect.cpp b/src/smw/ui/MI_TeamSelect.cpp index 8bf0708d9..1d3d8cd24 100644 --- a/src/smw/ui/MI_TeamSelect.cpp +++ b/src/smw/ui/MI_TeamSelect.cpp @@ -1,5 +1,6 @@ #include "MI_TeamSelect.h" +#include "gfx.h" #include "Game.h" #include "GameValues.h" #include "ResourceManager.h" @@ -223,6 +224,10 @@ MenuCodeEnum MI_TeamSelect::SendInput(CPlayerInput * playerInput) } } } + if (DEVICE_KEYBOARD != playerInput->inputControls[iPlayer]->iDevice) { + short team = GetTeam(iPlayer); + gfx_setjoystickteamcolor(SDL_JoystickFromPlayerIndex(playerInput->inputControls[iPlayer]->iDevice), team, fReady[iPlayer] ? 200 : 100); + } } return MENU_CODE_NONE;