Skip to content

Commit

Permalink
Improve color config variable handling
Browse files Browse the repository at this point in the history
- Add separate `CFGFLAG_COLLIGHT7` for 0.7 color config variables, which use `61/255` as darkest lighting value. In comparison, `CFGFLAG_COLLIGHT` uses `0.5` darkest lighting, so the color values being shown for 0.7 color variables were incorrect. Closes ddnet#8775.
- Pass darkest lighting as parameter directly instead of using `bool`s to avoid duplicating the logic.
- Add `ColorHSLA::DARKEST_LGT7` constant to replace existing `CTeeInfo::ms_DarkestLGT7` and `CSkins7::DARKEST_COLOR_LGT` constants.
- Round color components before printing them in config variable command handler, as color components are generally also rounded before being packed and before rendering.
- Remove default value of `ColorHSLA::UnclampLighting` function, to avoid incorrect usage.
  • Loading branch information
Robyt3 committed Sep 17, 2024
1 parent 217103a commit aa5a24a
Show file tree
Hide file tree
Showing 19 changed files with 95 additions and 83 deletions.
3 changes: 2 additions & 1 deletion src/base/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,9 @@ class ColorHSLA : public color4_base<ColorHSLA>
ColorHSLA(){};

constexpr static const float DARKEST_LGT = 0.5f;
constexpr static const float DARKEST_LGT7 = 61.0f / 255.0f;

ColorHSLA UnclampLighting(float Darkest = DARKEST_LGT) const
ColorHSLA UnclampLighting(float Darkest) const
{
ColorHSLA col = *this;
col.l = Darkest + col.l * (1.0f - Darkest);
Expand Down
2 changes: 1 addition & 1 deletion src/engine/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class IConsole : public IInterface
virtual int GetInteger(unsigned Index) const = 0;
virtual float GetFloat(unsigned Index) const = 0;
virtual const char *GetString(unsigned Index) const = 0;
virtual std::optional<ColorHSLA> GetColor(unsigned Index, bool Light) const = 0;
virtual std::optional<ColorHSLA> GetColor(unsigned Index, float DarkestLighting) const = 0;

virtual void RemoveArgument(unsigned Index) = 0;

Expand Down
40 changes: 20 additions & 20 deletions src/engine/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,29 +177,29 @@ mod ffi {
/// # unsafe { *user.cast_mut::<bool>() = true; }
/// let result: &IConsole_IResult /* = `command "$f00" $ffa500 $12345 shiny cyan -16777216 $f008 $00ffff80` */;
/// # result = result_param;
/// assert_eq!(result.GetColor(0, false), ColorHSLA { h: 0.0, s: 1.0, l: 0.5, a: 1.0 }); // red
/// assert_eq!(result.GetColor(1, false), ColorHSLA { h: 0.10784314, s: 1.0, l: 0.5, a: 1.0 }); // DDNet logo color
/// assert_eq!(result.GetColor(2, false), ColorHSLA { h: 0.0, s: 0.0, l: 0.0, a: 1.0 }); // cannot be parsed => black
/// assert_eq!(result.GetColor(3, false), ColorHSLA { h: 0.0, s: 0.0, l: 0.0, a: 1.0 }); // unknown color name => black
/// assert_eq!(result.GetColor(4, false), ColorHSLA { h: 0.5, s: 1.0, l: 0.5, a: 1.0 }); // cyan
/// assert_eq!(result.GetColor(5, false), ColorHSLA { h: 0.0, s: 0.0, l: 0.0, a: 1.0 }); // black
/// assert_eq!(result.GetColor(6, false), ColorHSLA { h: 0.0, s: 1.0, l: 0.5, a: 0.53333336 }); // red with alpha specified
/// assert_eq!(result.GetColor(7, false), ColorHSLA { h: 0.5, s: 1.0, l: 0.5, a: 0.5019608 }); // cyan with alpha specified
/// assert_eq!(result.GetColor(8, false), ColorHSLA { h: 0.0, s: 0.0, l: 0.0, a: 1.0 }); // out of range => black
///
/// assert_eq!(result.GetColor(0, true), result.GetColor(0, false));
/// assert_eq!(result.GetColor(1, true), result.GetColor(1, false));
/// assert_eq!(result.GetColor(2, true), result.GetColor(2, false));
/// assert_eq!(result.GetColor(3, true), result.GetColor(3, false));
/// assert_eq!(result.GetColor(4, true), result.GetColor(4, false));
/// assert_eq!(result.GetColor(5, true), ColorHSLA { h: 0.0, s: 0.0, l: 0.5, a: 1.0 }); // black, but has the `Light` parameter set
/// assert_eq!(result.GetColor(6, true), result.GetColor(6, false));
/// assert_eq!(result.GetColor(7, true), result.GetColor(7, false));
/// assert_eq!(result.GetColor(8, true), result.GetColor(8, false));
/// assert_eq!(result.GetColor(0, 0.0), ColorHSLA { h: 0.0, s: 1.0, l: 0.5, a: 1.0 }); // red
/// assert_eq!(result.GetColor(1, 0.0), ColorHSLA { h: 0.10784314, s: 1.0, l: 0.5, a: 1.0 }); // DDNet logo color
/// assert_eq!(result.GetColor(2, 0.0), ColorHSLA { h: 0.0, s: 0.0, l: 0.0, a: 1.0 }); // cannot be parsed => black
/// assert_eq!(result.GetColor(3, 0.0), ColorHSLA { h: 0.0, s: 0.0, l: 0.0, a: 1.0 }); // unknown color name => black
/// assert_eq!(result.GetColor(4, 0.0), ColorHSLA { h: 0.5, s: 1.0, l: 0.5, a: 1.0 }); // cyan
/// assert_eq!(result.GetColor(5, 0.0), ColorHSLA { h: 0.0, s: 0.0, l: 0.0, a: 1.0 }); // black
/// assert_eq!(result.GetColor(6, 0.0), ColorHSLA { h: 0.0, s: 1.0, l: 0.5, a: 0.53333336 }); // red with alpha specified
/// assert_eq!(result.GetColor(7, 0.0), ColorHSLA { h: 0.5, s: 1.0, l: 0.5, a: 0.5019608 }); // cyan with alpha specified
/// assert_eq!(result.GetColor(8, 0.0), ColorHSLA { h: 0.0, s: 0.0, l: 0.0, a: 1.0 }); // out of range => black
///
/// assert_eq!(result.GetColor(0, 0.5), result.GetColor(0, 0.0));
/// assert_eq!(result.GetColor(1, 0.5), result.GetColor(1, 0.0));
/// assert_eq!(result.GetColor(2, 0.5), result.GetColor(2, 0.0));
/// assert_eq!(result.GetColor(3, 0.5), result.GetColor(3, 0.0));
/// assert_eq!(result.GetColor(4, 0.5), result.GetColor(4, 0.0));
/// assert_eq!(result.GetColor(5, 0.5), ColorHSLA { h: 0.0, s: 0.0, l: 0.5, a: 1.0 }); // black, but has the `Light` parameter set
/// assert_eq!(result.GetColor(6, 0.5), result.GetColor(6, 0.0));
/// assert_eq!(result.GetColor(7, 0.5), result.GetColor(7, 0.0));
/// assert_eq!(result.GetColor(8, 0.5), result.GetColor(8, 0.0));
/// # }
/// # assert!(executed);
/// ```
pub fn GetColor(self: &IConsole_IResult, Index: u32, Light: bool) -> ColorHSLA;
pub fn GetColor(self: &IConsole_IResult, Index: u32, DarkestLighting: f32) -> ColorHSLA;

/// Get the number of parameters passed.
///
Expand Down
24 changes: 11 additions & 13 deletions src/engine/shared/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ void SColorConfigVariable::CommandCallback(IConsole::IResult *pResult, void *pUs
if(pData->CheckReadOnly())
return;

const auto Color = pResult->GetColor(0, pData->m_Light);
const auto Color = pResult->GetColor(0, pData->m_DarkestLighting);
if(Color)
{
const unsigned Value = Color->Pack(pData->m_Light ? 0.5f : 0.0f, pData->m_Alpha);
const unsigned Value = Color->Pack(pData->m_DarkestLighting, pData->m_Alpha);

*pData->m_pVariable = Value;
if(pResult->m_ClientId != IConsole::CLIENT_ID_GAME)
Expand All @@ -137,19 +137,17 @@ void SColorConfigVariable::CommandCallback(IConsole::IResult *pResult, void *pUs
str_format(aBuf, sizeof(aBuf), "Value: %u", *pData->m_pVariable);
pData->m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "config", aBuf);

ColorHSLA Hsla = ColorHSLA(*pData->m_pVariable, true);
if(pData->m_Light)
Hsla = Hsla.UnclampLighting();
str_format(aBuf, sizeof(aBuf), "H: %d°, S: %d%%, L: %d%%", round_truncate(Hsla.h * 360), round_truncate(Hsla.s * 100), round_truncate(Hsla.l * 100));
const ColorHSLA Hsla = ColorHSLA(*pData->m_pVariable, true).UnclampLighting(pData->m_DarkestLighting);
str_format(aBuf, sizeof(aBuf), "H: %d°, S: %d%%, L: %d%%", round_to_int(Hsla.h * 360), round_to_int(Hsla.s * 100), round_to_int(Hsla.l * 100));
pData->m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "config", aBuf);

const ColorRGBA Rgba = color_cast<ColorRGBA>(Hsla);
str_format(aBuf, sizeof(aBuf), "R: %d, G: %d, B: %d, #%06X", round_truncate(Rgba.r * 255), round_truncate(Rgba.g * 255), round_truncate(Rgba.b * 255), Rgba.Pack(false));
str_format(aBuf, sizeof(aBuf), "R: %d, G: %d, B: %d, #%06X", round_to_int(Rgba.r * 255), round_to_int(Rgba.g * 255), round_to_int(Rgba.b * 255), Rgba.Pack(false));
pData->m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "config", aBuf);

if(pData->m_Alpha)
{
str_format(aBuf, sizeof(aBuf), "A: %d%%", round_truncate(Hsla.a * 100));
str_format(aBuf, sizeof(aBuf), "A: %d%%", round_to_int(Hsla.a * 100));
pData->m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "config", aBuf);
}
}
Expand Down Expand Up @@ -494,19 +492,19 @@ void CConfigManager::Con_Toggle(IConsole::IResult *pResult, void *pUserData)
if(pVariable->m_Type == SConfigVariable::VAR_INT)
{
SIntConfigVariable *pIntVariable = static_cast<SIntConfigVariable *>(pVariable);
pIntVariable->SetValue(*pIntVariable->m_pVariable == pResult->GetInteger(1) ? pResult->GetInteger(2) : pResult->GetInteger(1));
pIntVariable->SetValue(*pIntVariable->m_pVariable == pResult->GetInteger(pResult->GetInteger(1) ? 2 : 1));
}
else if(pVariable->m_Type == SConfigVariable::VAR_COLOR)
{
SColorConfigVariable *pColorVariable = static_cast<SColorConfigVariable *>(pVariable);
const float Darkest = pColorVariable->m_Light ? 0.5f : 0.0f;
const std::optional<ColorHSLA> Value = *pColorVariable->m_pVariable == pResult->GetColor(1, pColorVariable->m_Light).value_or(ColorHSLA(0, 0, 0)).Pack(Darkest, pColorVariable->m_Alpha) ? pResult->GetColor(2, pColorVariable->m_Light) : pResult->GetColor(1, pColorVariable->m_Light);
pColorVariable->SetValue(Value.value_or(ColorHSLA(0, 0, 0)).Pack(Darkest, pColorVariable->m_Alpha));
const bool EqualToFirst = *pColorVariable->m_pVariable == pResult->GetColor(1, pColorVariable->m_DarkestLighting).value_or(ColorHSLA(0, 0, 0)).Pack(pColorVariable->m_DarkestLighting, pColorVariable->m_Alpha);
const std::optional<ColorHSLA> Value = pResult->GetColor(EqualToFirst ? 2 : 1, pColorVariable->m_DarkestLighting);
pColorVariable->SetValue(Value.value_or(ColorHSLA(0, 0, 0)).Pack(pColorVariable->m_DarkestLighting, pColorVariable->m_Alpha));
}
else if(pVariable->m_Type == SConfigVariable::VAR_STRING)
{
SStringConfigVariable *pStringVariable = static_cast<SStringConfigVariable *>(pVariable);
pStringVariable->SetValue(str_comp(pStringVariable->m_pStr, pResult->GetString(1)) == 0 ? pResult->GetString(2) : pResult->GetString(1));
pStringVariable->SetValue(pResult->GetString(str_comp(pStringVariable->m_pStr, pResult->GetString(1)) == 0 ? 2 : 1));
}
return;
}
Expand Down
22 changes: 17 additions & 5 deletions src/engine/shared/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ enum
CFGFLAG_GAME = 1 << 8,
CFGFLAG_NONTEEHISTORIC = 1 << 9,
CFGFLAG_COLLIGHT = 1 << 10,
CFGFLAG_COLALPHA = 1 << 11,
CFGFLAG_INSENSITIVE = 1 << 12,
CMDFLAG_PRACTICE = 1 << 13,
CFGFLAG_COLLIGHT7 = 1 << 11,
CFGFLAG_COLALPHA = 1 << 12,
CFGFLAG_INSENSITIVE = 1 << 13,
CMDFLAG_PRACTICE = 1 << 14,
};

struct SConfigVariable
Expand Down Expand Up @@ -133,19 +134,30 @@ struct SColorConfigVariable : public SConfigVariable
{
unsigned *m_pVariable;
unsigned m_Default;
bool m_Light;
float m_DarkestLighting;
bool m_Alpha;
unsigned m_OldValue;

SColorConfigVariable(IConsole *pConsole, const char *pScriptName, EVariableType Type, int Flags, const char *pHelp, unsigned *pVariable, unsigned Default) :
SConfigVariable(pConsole, pScriptName, Type, Flags, pHelp),
m_pVariable(pVariable),
m_Default(Default),
m_Light(Flags & CFGFLAG_COLLIGHT),
m_Alpha(Flags & CFGFLAG_COLALPHA),
m_OldValue(Default)
{
*m_pVariable = m_Default;
if(Flags & CFGFLAG_COLLIGHT)
{
m_DarkestLighting = ColorHSLA::DARKEST_LGT;
}
else if(Flags & CFGFLAG_COLLIGHT7)
{
m_DarkestLighting = ColorHSLA::DARKEST_LGT7;
}
else
{
m_DarkestLighting = 0.0f;
}
}

~SColorConfigVariable() override = default;
Expand Down
12 changes: 10 additions & 2 deletions src/engine/shared/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,21 @@ pub const CFGFLAG_NONTEEHISTORIC: i32 = 1 << 9;
/// Has no effect on other commands or config variables.
pub const CFGFLAG_COLLIGHT: i32 = 1 << 10;

/// Color config variable that can only have lightness (61/255) to 1.0.
///
/// This is achieved by dividing the lightness channel by and adding (61/255), i.e.
/// remapping all the colors.
///
/// Has no effect on other commands or config variables.
pub const CFGFLAG_COLLIGHT7: i32 = 1 << 11;

/// Color config variable that includes an alpha (opacity) value.
///
/// Has no effect on other commands or config variables.
pub const CFGFLAG_COLALPHA: i32 = 1 << 11;
pub const CFGFLAG_COLALPHA: i32 = 1 << 12;

/// Config variable with insensitive data that can be included in client
/// integrity checks.
///
/// This should only be set on config variables the server could observe anyway.
pub const CFGFLAG_INSENSITIVE: i32 = 1 << 12;
pub const CFGFLAG_INSENSITIVE: i32 = 1 << 13;
24 changes: 12 additions & 12 deletions src/engine/shared/config_variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ MACRO_CONFIG_INT(ClPlayerDefaultEyes, player_default_eyes, 0, 0, 5, CFGFLAG_CLIE
MACRO_CONFIG_STR(ClSkinPrefix, cl_skin_prefix, 12, "", CFGFLAG_CLIENT | CFGFLAG_SAVE, "Replace the skins by skins with this prefix (e.g. kitty, santa)")
MACRO_CONFIG_INT(ClFatSkins, cl_fat_skins, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Enable fat skins")

MACRO_CONFIG_COL(ClPlayer7ColorBody, player7_color_body, 0x1B6F74, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_COLLIGHT | CFGFLAG_INSENSITIVE, "Player body color")
MACRO_CONFIG_COL(ClPlayer7ColorFeet, player7_color_feet, 0x1C873E, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_COLLIGHT | CFGFLAG_INSENSITIVE, "Player feet color")
MACRO_CONFIG_COL(ClPlayer7ColorBody, player7_color_body, 0x1B6F74, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_COLLIGHT7 | CFGFLAG_INSENSITIVE, "Player body color")
MACRO_CONFIG_COL(ClPlayer7ColorFeet, player7_color_feet, 0x1C873E, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_COLLIGHT7 | CFGFLAG_INSENSITIVE, "Player feet color")

MACRO_CONFIG_COL(ClPlayer7ColorMarking, player7_color_marking, 0xFF0000FF, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_COLLIGHT | CFGFLAG_COLALPHA | CFGFLAG_INSENSITIVE, "Player marking color")
MACRO_CONFIG_COL(ClPlayer7ColorDecoration, player7_color_decoration, 0x1B6F74, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_COLLIGHT | CFGFLAG_INSENSITIVE, "Player decoration color")
MACRO_CONFIG_COL(ClPlayer7ColorHands, player7_color_hands, 0x1B759E, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_COLLIGHT | CFGFLAG_INSENSITIVE, "Player hands color")
MACRO_CONFIG_COL(ClPlayer7ColorEyes, player7_color_eyes, 0x0000FF, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_COLLIGHT | CFGFLAG_INSENSITIVE, "Player eyes color")
MACRO_CONFIG_COL(ClPlayer7ColorMarking, player7_color_marking, 0xFF0000FF, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_COLLIGHT7 | CFGFLAG_COLALPHA | CFGFLAG_INSENSITIVE, "Player marking color")
MACRO_CONFIG_COL(ClPlayer7ColorDecoration, player7_color_decoration, 0x1B6F74, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_COLLIGHT7 | CFGFLAG_INSENSITIVE, "Player decoration color")
MACRO_CONFIG_COL(ClPlayer7ColorHands, player7_color_hands, 0x1B759E, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_COLLIGHT7 | CFGFLAG_INSENSITIVE, "Player hands color")
MACRO_CONFIG_COL(ClPlayer7ColorEyes, player7_color_eyes, 0x0000FF, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_COLLIGHT7 | CFGFLAG_INSENSITIVE, "Player eyes color")
MACRO_CONFIG_INT(ClPlayer7UseCustomColorBody, player7_use_custom_color_body, 1, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_INSENSITIVE, "Toggles usage of custom colors for body")
MACRO_CONFIG_INT(ClPlayer7UseCustomColorMarking, player7_use_custom_color_marking, 1, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_INSENSITIVE, "Toggles usage of custom colors for marking")
MACRO_CONFIG_INT(ClPlayer7UseCustomColorDecoration, player7_use_custom_color_decoration, 1, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_INSENSITIVE, "Toggles usage of custom colors for decoration")
Expand All @@ -159,13 +159,13 @@ MACRO_CONFIG_STR(ClPlayer7SkinHands, player7_skin_hands, protocol7::MAX_SKIN_ARR
MACRO_CONFIG_STR(ClPlayer7SkinFeet, player7_skin_feet, protocol7::MAX_SKIN_ARRAY_SIZE, "standard", CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_INSENSITIVE, "Player skin feet")
MACRO_CONFIG_STR(ClPlayer7SkinEyes, player7_skin_eyes, protocol7::MAX_SKIN_ARRAY_SIZE, "standard", CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_INSENSITIVE, "Player skin eyes")

MACRO_CONFIG_COL(ClDummy7ColorBody, dummy7_color_body, 0x1B6F74, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_COLLIGHT | CFGFLAG_INSENSITIVE, "Dummy body color")
MACRO_CONFIG_COL(ClDummy7ColorFeet, dummy7_color_feet, 0x1C873E, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_COLLIGHT | CFGFLAG_INSENSITIVE, "Dummy feet color")
MACRO_CONFIG_COL(ClDummy7ColorBody, dummy7_color_body, 0x1B6F74, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_COLLIGHT7 | CFGFLAG_INSENSITIVE, "Dummy body color")
MACRO_CONFIG_COL(ClDummy7ColorFeet, dummy7_color_feet, 0x1C873E, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_COLLIGHT7 | CFGFLAG_INSENSITIVE, "Dummy feet color")

MACRO_CONFIG_COL(ClDummy7ColorMarking, dummy7_color_marking, 0xFF0000FF, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_COLLIGHT | CFGFLAG_COLALPHA | CFGFLAG_INSENSITIVE, "Dummy marking color")
MACRO_CONFIG_COL(ClDummy7ColorDecoration, dummy7_color_decoration, 0x1B6F74, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_COLLIGHT | CFGFLAG_INSENSITIVE, "Dummy decoration color")
MACRO_CONFIG_COL(ClDummy7ColorHands, dummy7_color_hands, 0x1B759E, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_COLLIGHT | CFGFLAG_INSENSITIVE, "Dummy hands color")
MACRO_CONFIG_COL(ClDummy7ColorEyes, dummy7_color_eyes, 0x0000FF, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_COLLIGHT | CFGFLAG_INSENSITIVE, "Dummy eyes color")
MACRO_CONFIG_COL(ClDummy7ColorMarking, dummy7_color_marking, 0xFF0000FF, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_COLLIGHT7 | CFGFLAG_COLALPHA | CFGFLAG_INSENSITIVE, "Dummy marking color")
MACRO_CONFIG_COL(ClDummy7ColorDecoration, dummy7_color_decoration, 0x1B6F74, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_COLLIGHT7 | CFGFLAG_INSENSITIVE, "Dummy decoration color")
MACRO_CONFIG_COL(ClDummy7ColorHands, dummy7_color_hands, 0x1B759E, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_COLLIGHT7 | CFGFLAG_INSENSITIVE, "Dummy hands color")
MACRO_CONFIG_COL(ClDummy7ColorEyes, dummy7_color_eyes, 0x0000FF, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_COLLIGHT7 | CFGFLAG_INSENSITIVE, "Dummy eyes color")
MACRO_CONFIG_INT(ClDummy7UseCustomColorBody, dummy7_use_custom_color_body, 1, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_INSENSITIVE, "Toggles usage of custom colors for body")
MACRO_CONFIG_INT(ClDummy7UseCustomColorMarking, dummy7_use_custom_color_marking, 1, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_INSENSITIVE, "Toggles usage of custom colors for marking")
MACRO_CONFIG_INT(ClDummy7UseCustomColorDecoration, dummy7_use_custom_color_decoration, 1, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_INSENSITIVE, "Toggles usage of custom colors for decoration")
Expand Down
7 changes: 2 additions & 5 deletions src/engine/shared/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ float CConsole::CResult::GetFloat(unsigned Index) const
return str_tofloat(m_apArgs[Index]);
}

std::optional<ColorHSLA> CConsole::CResult::GetColor(unsigned Index, bool Light) const
std::optional<ColorHSLA> CConsole::CResult::GetColor(unsigned Index, float DarkestLighting) const
{
if(Index >= m_NumArgs)
return std::nullopt;
Expand All @@ -51,10 +51,7 @@ std::optional<ColorHSLA> CConsole::CResult::GetColor(unsigned Index, bool Light)
unsigned long Value = str_toulong_base(pStr, 10);
if(Value == std::numeric_limits<unsigned long>::max())
return std::nullopt;
const ColorHSLA Hsla = ColorHSLA(Value, true);
if(Light)
return Hsla.UnclampLighting();
return Hsla;
return ColorHSLA(Value, true).UnclampLighting(DarkestLighting);
}
else if(*pStr == '$') // Hex RGB/RGBA
{
Expand Down
2 changes: 1 addition & 1 deletion src/engine/shared/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class CConsole : public IConsole
const char *GetString(unsigned Index) const override;
int GetInteger(unsigned Index) const override;
float GetFloat(unsigned Index) const override;
std::optional<ColorHSLA> GetColor(unsigned Index, bool Light) const override;
std::optional<ColorHSLA> GetColor(unsigned Index, float DarkestLighting) const override;

void RemoveArgument(unsigned Index) override
{
Expand Down
4 changes: 2 additions & 2 deletions src/game/client/components/ghost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,8 @@ void CGhost::InitRenderInfos(CGhostItem *pGhost)
pRenderInfo->m_CustomColoredSkin = pGhost->m_Skin.m_UseCustomColor;
if(pGhost->m_Skin.m_UseCustomColor)
{
pRenderInfo->m_ColorBody = color_cast<ColorRGBA>(ColorHSLA(pGhost->m_Skin.m_ColorBody).UnclampLighting());
pRenderInfo->m_ColorFeet = color_cast<ColorRGBA>(ColorHSLA(pGhost->m_Skin.m_ColorFeet).UnclampLighting());
pRenderInfo->m_ColorBody = color_cast<ColorRGBA>(ColorHSLA(pGhost->m_Skin.m_ColorBody).UnclampLighting(ColorHSLA::DARKEST_LGT));
pRenderInfo->m_ColorFeet = color_cast<ColorRGBA>(ColorHSLA(pGhost->m_Skin.m_ColorFeet).UnclampLighting(ColorHSLA::DARKEST_LGT));
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/game/client/components/menus_browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1828,8 +1828,8 @@ CTeeRenderInfo CMenus::GetTeeRenderInfo(vec2 Size, const char *pSkinName, bool C
TeeInfo.m_CustomColoredSkin = CustomSkinColors;
if(CustomSkinColors)
{
TeeInfo.m_ColorBody = color_cast<ColorRGBA>(ColorHSLA(CustomSkinColorBody).UnclampLighting());
TeeInfo.m_ColorFeet = color_cast<ColorRGBA>(ColorHSLA(CustomSkinColorFeet).UnclampLighting());
TeeInfo.m_ColorBody = color_cast<ColorRGBA>(ColorHSLA(CustomSkinColorBody).UnclampLighting(ColorHSLA::DARKEST_LGT));
TeeInfo.m_ColorFeet = color_cast<ColorRGBA>(ColorHSLA(CustomSkinColorFeet).UnclampLighting(ColorHSLA::DARKEST_LGT));
}
else
{
Expand Down
Loading

0 comments on commit aa5a24a

Please sign in to comment.