Skip to content

Commit

Permalink
Added basic controller LED (e.g. Dualshock 4) support
Browse files Browse the repository at this point in the history
  • Loading branch information
Pheazant committed Dec 28, 2023
1 parent 9860315 commit 6cf4ec3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/common/gfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 2 additions & 0 deletions src/common/gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions src/smw/ui/MI_TeamSelect.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "MI_TeamSelect.h"

#include "gfx.h"
#include "Game.h"
#include "GameValues.h"
#include "ResourceManager.h"
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6cf4ec3

Please sign in to comment.