mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Remove ugly hack
This commit is contained in:
parent
417554e0f4
commit
d200ef0bb0
|
@ -102,39 +102,27 @@ public:
|
|||
class ColorHSLA : public color4_base<ColorHSLA>
|
||||
{
|
||||
public:
|
||||
bool m_Lit = false;
|
||||
|
||||
using color4_base::color4_base;
|
||||
ColorHSLA() {};
|
||||
|
||||
ColorHSLA Lighten()
|
||||
ColorHSLA UnclampLighting(float Darkest)
|
||||
{
|
||||
if(m_Lit)
|
||||
return *this;
|
||||
|
||||
ColorHSLA col = *this;
|
||||
col.l = 0.5f + l * 0.5f;
|
||||
col.m_Lit = true;
|
||||
return col;
|
||||
};
|
||||
|
||||
ColorHSLA Darken()
|
||||
{
|
||||
if(!m_Lit)
|
||||
return *this;
|
||||
|
||||
ColorHSLA col = *this;
|
||||
col.l = (l - 0.5f) * 2;
|
||||
col.m_Lit = false;
|
||||
col.l = Darkest + col.l * (1.0f - Darkest);
|
||||
return col;
|
||||
}
|
||||
|
||||
unsigned Pack(bool Alpha = true)
|
||||
{
|
||||
if(m_Lit)
|
||||
return Darken().color4_base::Pack(Alpha);
|
||||
else
|
||||
return color4_base::Pack(Alpha);
|
||||
return color4_base::Pack(Alpha);
|
||||
}
|
||||
|
||||
unsigned Pack(float Darkest, bool Alpha = false)
|
||||
{
|
||||
ColorHSLA col = *this;
|
||||
col.l = (l - Darkest)/(1 - Darkest);
|
||||
col.l = clamp(col.l, 0.0f, 1.0f);
|
||||
return col.Pack(Alpha);
|
||||
}
|
||||
|
||||
unsigned Pack7()
|
||||
|
|
|
@ -39,7 +39,7 @@ float CConsole::CResult::GetFloat(unsigned Index)
|
|||
|
||||
ColorHSLA CConsole::CResult::GetColor(unsigned Index, bool Light)
|
||||
{
|
||||
ColorHSLA hsl = ColorHSLA(0, 0, 0).Lighten();
|
||||
ColorHSLA hsl = ColorHSLA(0, 0, 0);
|
||||
if(Index >= m_NumArgs)
|
||||
return hsl;
|
||||
|
||||
|
@ -47,6 +47,8 @@ ColorHSLA CConsole::CResult::GetColor(unsigned Index, bool Light)
|
|||
if(str_isallnum(pStr) || ((pStr[0] == '-' || pStr[0] == '+') && str_isallnum(pStr+1))) // Teeworlds Color (Packed HSL)
|
||||
{
|
||||
hsl = ColorHSLA(str_toulong_base(pStr, 10), true);
|
||||
if(Light)
|
||||
hsl = hsl.UnclampLighting(0.5f);
|
||||
}
|
||||
else if(*pStr == '$') // Hex RGB
|
||||
{
|
||||
|
@ -92,7 +94,7 @@ ColorHSLA CConsole::CResult::GetColor(unsigned Index, bool Light)
|
|||
else if(!str_comp_nocase(pStr, "black"))
|
||||
hsl = ColorHSLA(0, 0, 0);
|
||||
|
||||
return Light ? hsl.Lighten() : hsl;
|
||||
return hsl;
|
||||
}
|
||||
|
||||
const IConsole::CCommandInfo *CConsole::CCommand::NextCommandInfo(int AccessLevel, int FlagMask) const
|
||||
|
@ -763,7 +765,8 @@ static void ColVariableCommand(IConsole::IResult *pResult, void *pUserData)
|
|||
|
||||
if(pResult->NumArguments())
|
||||
{
|
||||
int Val = pResult->GetColor(0, pData->m_Light).Pack(pData->m_Alpha);
|
||||
ColorHSLA Col = pResult->GetColor(0, pData->m_Light);
|
||||
int Val = Col.Pack(pData->m_Light ? 0.5f : 0.0f, pData->m_Alpha);
|
||||
|
||||
*(pData->m_pVariable) = Val;
|
||||
if(pResult->m_ClientID != IConsole::CLIENT_ID_GAME)
|
||||
|
@ -776,6 +779,8 @@ static void ColVariableCommand(IConsole::IResult *pResult, void *pUserData)
|
|||
pData->m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "console", aBuf);
|
||||
|
||||
ColorHSLA hsl(*(pData->m_pVariable), true);
|
||||
if(pData->m_Light)
|
||||
hsl = hsl.UnclampLighting(0.5f);
|
||||
str_format(aBuf, sizeof(aBuf), "H: %d°, S: %d%%, L: %d%%", round_truncate(hsl.h * 360), round_truncate(hsl.s * 100), round_truncate(hsl.l * 100));
|
||||
pData->m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "console", aBuf);
|
||||
|
||||
|
@ -872,11 +877,11 @@ void CConsole::ConToggle(IConsole::IResult *pResult, void *pUser)
|
|||
{
|
||||
CColVariableData *pData = static_cast<CColVariableData *>(pUserData);
|
||||
bool Light = pData->m_Light;
|
||||
float Darkest = Light ? 0.5f : 0.0f;
|
||||
bool Alpha = pData->m_Alpha;
|
||||
unsigned Cur = *pData->m_pVariable;
|
||||
ColorHSLA Val = Cur == pResult->GetColor(1, Light).Pack(Alpha) ? pResult->GetColor(2, Light) : pResult->GetColor(1, Light);
|
||||
if(Light)
|
||||
Val = Val.Lighten();
|
||||
ColorHSLA Val = Cur == pResult->GetColor(1, Light).Pack(Darkest, Alpha) ? pResult->GetColor(2, Light) : pResult->GetColor(1, Light);
|
||||
Cur = Val.Pack(Darkest, Alpha);
|
||||
|
||||
str_format(aBuf, sizeof(aBuf), "%s %u", pResult->GetString(0), Val.Pack(Alpha));
|
||||
pConsole->ExecuteLine(aBuf);
|
||||
|
|
|
@ -119,7 +119,7 @@ class CConsole : public IConsole
|
|||
virtual const char *GetString(unsigned Index);
|
||||
virtual int GetInteger(unsigned Index);
|
||||
virtual float GetFloat(unsigned Index);
|
||||
virtual ColorHSLA GetColor(unsigned Index, bool Light = false);
|
||||
virtual ColorHSLA GetColor(unsigned Index, bool Light);
|
||||
|
||||
// DDRace
|
||||
|
||||
|
|
|
@ -169,7 +169,7 @@ void CEffects::PlayerDeath(vec2 Pos, int ClientID)
|
|||
if(ClientID >= 0)
|
||||
{
|
||||
if(m_pClient->m_aClients[ClientID].m_UseCustomColor)
|
||||
BloodColor = color_cast<ColorRGBA>(ColorHSLA(m_pClient->m_aClients[ClientID].m_ColorBody).Lighten());
|
||||
BloodColor = color_cast<ColorRGBA>(ColorHSLA(m_pClient->m_aClients[ClientID].m_ColorBody).UnclampLighting(0.5f));
|
||||
else
|
||||
{
|
||||
const CSkins::CSkin *s = m_pClient->m_pSkins->Get(m_pClient->m_aClients[ClientID].m_SkinID);
|
||||
|
|
|
@ -414,8 +414,8 @@ void CMenus::RenderSettingsTee(CUIRect MainView)
|
|||
if(*UseCustomColor)
|
||||
{
|
||||
OwnSkinInfo.m_Texture = pOwnSkin->m_ColorTexture;
|
||||
OwnSkinInfo.m_ColorBody = color_cast<ColorRGBA>(ColorHSLA(*ColorBody).Lighten());
|
||||
OwnSkinInfo.m_ColorFeet = color_cast<ColorRGBA>(ColorHSLA(*ColorFeet).Lighten());
|
||||
OwnSkinInfo.m_ColorBody = color_cast<ColorRGBA>(ColorHSLA(*ColorBody).UnclampLighting(CSkins::DARKEST_LGT));
|
||||
OwnSkinInfo.m_ColorFeet = color_cast<ColorRGBA>(ColorHSLA(*ColorFeet).UnclampLighting(CSkins::DARKEST_LGT));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
class CSkins : public CComponent
|
||||
{
|
||||
public:
|
||||
constexpr static const float DARKEST_LGT = 0.5f;
|
||||
// do this better and nicer
|
||||
struct CSkin
|
||||
{
|
||||
|
|
|
@ -1162,8 +1162,8 @@ void CGameClient::OnNewSnapshot()
|
|||
if(m_aClients[ClientID].m_aSkinName[0] == 'x' || m_aClients[ClientID].m_aSkinName[1] == '_')
|
||||
str_copy(m_aClients[ClientID].m_aSkinName, "default", 64);
|
||||
|
||||
m_aClients[ClientID].m_SkinInfo.m_ColorBody = color_cast<ColorRGBA>(ColorHSLA(m_aClients[ClientID].m_ColorBody).Lighten());
|
||||
m_aClients[ClientID].m_SkinInfo.m_ColorFeet = color_cast<ColorRGBA>(ColorHSLA(m_aClients[ClientID].m_ColorFeet).Lighten());
|
||||
m_aClients[ClientID].m_SkinInfo.m_ColorBody = color_cast<ColorRGBA>(ColorHSLA(m_aClients[ClientID].m_ColorBody).UnclampLighting(CSkins::DARKEST_LGT));
|
||||
m_aClients[ClientID].m_SkinInfo.m_ColorFeet = color_cast<ColorRGBA>(ColorHSLA(m_aClients[ClientID].m_ColorFeet).UnclampLighting(CSkins::DARKEST_LGT));
|
||||
m_aClients[ClientID].m_SkinInfo.m_Size = 64;
|
||||
|
||||
// find new skin
|
||||
|
|
Loading…
Reference in a new issue