Implement color_to_rgb

This commit is contained in:
def 2019-04-10 22:43:57 +02:00
parent 11127f9344
commit 2eab795c9e
2 changed files with 30 additions and 0 deletions

View file

@ -219,6 +219,7 @@ void CGameClient::OnConsoleInit()
Console()->Register("team", "i[team-id]", CFGFLAG_CLIENT, ConTeam, this, "Switch team"); Console()->Register("team", "i[team-id]", CFGFLAG_CLIENT, ConTeam, this, "Switch team");
Console()->Register("kill", "", CFGFLAG_CLIENT, ConKill, this, "Kill yourself"); Console()->Register("kill", "", CFGFLAG_CLIENT, ConKill, this, "Kill yourself");
Console()->Register("color_from_rgb", "s[color]", CFGFLAG_CLIENT, ConColorFromRgb, this, "Convert HEX RGB color (3 or 6 digits) to TW formats"); Console()->Register("color_from_rgb", "s[color]", CFGFLAG_CLIENT, ConColorFromRgb, this, "Convert HEX RGB color (3 or 6 digits) to TW formats");
Console()->Register("color_to_rgb", "i[color] ?i[color] ?i[color]", CFGFLAG_CLIENT, ConColorToRgb, this, "Convert TW colors to HEX RGB color format");
// register server dummy commands for tab completion // register server dummy commands for tab completion
Console()->Register("tune", "s[tuning] i[value]", CFGFLAG_SERVER, 0, 0, "Tune variable to value"); Console()->Register("tune", "s[tuning] i[value]", CFGFLAG_SERVER, 0, 0, "Tune variable to value");
@ -1997,6 +1998,34 @@ void CGameClient::ConColorFromRgb(IConsole::IResult *pResult, void *pUserData)
pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "color", aBuf); pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "color", aBuf);
} }
void CGameClient::ConColorToRgb(IConsole::IResult *pResult, void *pUserData)
{
CGameClient *pThis = (CGameClient*)pUserData;
vec3 Rgb;
if(pResult->NumArguments() == 1)
{
const int v = pResult->GetInteger(0);
Rgb = HslToRgb(vec3(((v>>16)&0xff)/255.0f, ((v>>8)&0xff)/255.0f, 0.5f+(v&0xff)/255.0f*0.5f));
}
else if(pResult->NumArguments() == 3)
{
const int Hue = pResult->GetInteger(0);
const int Sat = pResult->GetInteger(1);
const int Lht = pResult->GetInteger(2);
Rgb = HslToRgb(vec3(Hue / 255.0f, Sat / 255.0f, Lht / 255.0f));
}
else
{
pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "color", "Pass 1 integer in player_color format or 3 ints as hue sat lht");
return;
}
char aBuf[32];
str_format(aBuf, sizeof(aBuf), "%06X", ((int)(Rgb.r * 255) << 16) + ((int)(Rgb.g * 255) << 8) + (int)(Rgb.b * 255));
pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "color", aBuf);
}
void CGameClient::ConchainSpecialInfoupdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData) void CGameClient::ConchainSpecialInfoupdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
{ {
pfnCallback(pResult, pCallbackUserData); pfnCallback(pResult, pCallbackUserData);

View file

@ -119,6 +119,7 @@ class CGameClient : public IGameClient
static void ConTeam(IConsole::IResult *pResult, void *pUserData); static void ConTeam(IConsole::IResult *pResult, void *pUserData);
static void ConKill(IConsole::IResult *pResult, void *pUserData); static void ConKill(IConsole::IResult *pResult, void *pUserData);
static void ConColorFromRgb(IConsole::IResult *pResult, void *pUserData); static void ConColorFromRgb(IConsole::IResult *pResult, void *pUserData);
static void ConColorToRgb(IConsole::IResult *pResult, void *pUserData);
static void ConchainSpecialInfoupdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData); static void ConchainSpecialInfoupdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
static void ConchainSpecialDummyInfoupdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData); static void ConchainSpecialDummyInfoupdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);