Remember whether a color is lit or not

This commit is contained in:
Learath 2019-05-01 23:35:29 +03:00
parent ca888c56a2
commit b86c457c91
3 changed files with 30 additions and 13 deletions

View file

@ -102,22 +102,40 @@ public:
class ColorHSLA : public color4_base
{
public:
bool m_Lit = false;
using color4_base::color4_base;
ColorHSLA() {};
ColorHSLA(color4_base b): color4_base(b) {};
ColorHSLA Lighten()
{
if(m_Lit)
return *this;
ColorHSLA col = *this;
col.l = 0.5f + l * 0.5f;
col.m_Lit = true;
return col;
};
int PackLegacy()
ColorHSLA Darken()
{
ColorHSLA t = *this;
t.l = (t.l - 0.5f) * 2;
return t.Pack();
if(!m_Lit)
return *this;
ColorHSLA col = *this;
col.l = (l - 0.5f) * 2;
col.m_Lit = false;
return col;
}
int Pack()
{
if(m_Lit)
return Darken().color4_base::Pack();
else
return color4_base::Pack();
}
};

View file

@ -46,7 +46,6 @@ ColorHSLA CConsole::CResult::GetColor(unsigned Index, bool Light)
const char *pStr = m_apArgs[Index];
if(str_isallnum(pStr) || ((pStr[0] == '-' || pStr[0] == '+') && str_isallnum(pStr+1))) // Teeworlds Color (Packed HSL)
{
dbg_msg("DEBUG", "HERE %s %d", pStr, str_toint(pStr));
hsl = ColorHSLA(str_toint(pStr), true);
}
else if(*pStr == '$') // Hex RGB

View file

@ -1685,8 +1685,8 @@ void CGameClient::SendInfo(bool Start)
Msg.m_Country = g_Config.m_PlayerCountry;
Msg.m_pSkin = g_Config.m_ClPlayerSkin;
Msg.m_UseCustomColor = g_Config.m_ClPlayerUseCustomColor;
Msg.m_ColorBody = ColorHSLA(g_Config.m_ClPlayerColorBody).PackLegacy();
Msg.m_ColorFeet = ColorHSLA(g_Config.m_ClPlayerColorFeet).PackLegacy();
Msg.m_ColorBody = g_Config.m_ClPlayerColorBody;
Msg.m_ColorFeet = g_Config.m_ClPlayerColorFeet;
CMsgPacker Packer(Msg.MsgID());
Msg.Pack(&Packer);
Client()->SendMsgExY(&Packer, MSGFLAG_VITAL, false, 0);
@ -1700,8 +1700,8 @@ void CGameClient::SendInfo(bool Start)
Msg.m_Country = g_Config.m_PlayerCountry;
Msg.m_pSkin = g_Config.m_ClPlayerSkin;
Msg.m_UseCustomColor = g_Config.m_ClPlayerUseCustomColor;
Msg.m_ColorBody = ColorHSLA(g_Config.m_ClPlayerColorBody).PackLegacy();
Msg.m_ColorFeet = ColorHSLA(g_Config.m_ClPlayerColorFeet).PackLegacy();
Msg.m_ColorBody = g_Config.m_ClPlayerColorBody;
Msg.m_ColorFeet = g_Config.m_ClPlayerColorFeet;
CMsgPacker Packer(Msg.MsgID());
Msg.Pack(&Packer);
Client()->SendMsgExY(&Packer, MSGFLAG_VITAL, false, 0);
@ -1719,8 +1719,8 @@ void CGameClient::SendDummyInfo(bool Start)
Msg.m_Country = g_Config.m_ClDummyCountry;
Msg.m_pSkin = g_Config.m_ClDummySkin;
Msg.m_UseCustomColor = g_Config.m_ClDummyUseCustomColor;
Msg.m_ColorBody = ColorHSLA(g_Config.m_ClDummyColorBody).PackLegacy();
Msg.m_ColorFeet = ColorHSLA(g_Config.m_ClDummyColorFeet).PackLegacy();
Msg.m_ColorBody = g_Config.m_ClDummyColorBody;
Msg.m_ColorFeet = g_Config.m_ClDummyColorFeet;
CMsgPacker Packer(Msg.MsgID());
Msg.Pack(&Packer);
Client()->SendMsgExY(&Packer, MSGFLAG_VITAL, false, 1);
@ -1734,8 +1734,8 @@ void CGameClient::SendDummyInfo(bool Start)
Msg.m_Country = g_Config.m_ClDummyCountry;
Msg.m_pSkin = g_Config.m_ClDummySkin;
Msg.m_UseCustomColor = g_Config.m_ClDummyUseCustomColor;
Msg.m_ColorBody = ColorHSLA(g_Config.m_ClDummyColorBody).PackLegacy();
Msg.m_ColorFeet = ColorHSLA(g_Config.m_ClDummyColorFeet).PackLegacy();
Msg.m_ColorBody = g_Config.m_ClDummyColorBody;
Msg.m_ColorFeet = g_Config.m_ClDummyColorFeet;
CMsgPacker Packer(Msg.MsgID());
Msg.Pack(&Packer);
Client()->SendMsgExY(&Packer, MSGFLAG_VITAL,false, 1);