From e637064a683bb3830da262aade88720fc96c33ef Mon Sep 17 00:00:00 2001 From: Learath Date: Thu, 25 Apr 2019 19:49:27 +0300 Subject: [PATCH] Don't store HSL separately --- src/base/color.h | 14 -- src/engine/shared/config_variables.h | 38 +---- src/engine/shared/console.cpp | 4 + src/game/client/components/chat.cpp | 18 +-- src/game/client/components/console.cpp | 2 +- src/game/client/components/items.cpp | 8 +- src/game/client/components/menus_settings.cpp | 141 ++++++++++-------- src/game/client/gameclient.cpp | 4 +- src/game/client/gameclient.h | 2 +- 9 files changed, 109 insertions(+), 122 deletions(-) diff --git a/src/base/color.h b/src/base/color.h index 79985c594..15e1cb3a0 100644 --- a/src/base/color.h +++ b/src/base/color.h @@ -10,20 +10,6 @@ Title: Color handling */ -/* - Function: HueToRgb - Converts Hue to RGB -*/ -inline float HueToRgb(float v1, float v2, float h) -{ - if(h < 0.0f) h += 1; - if(h > 1.0f) h -= 1; - if((6.0f * h) < 1.0f) return v1 + (v2 - v1) * 6.0f * h; - if((2.0f * h) < 1.0f) return v2; - if((3.0f * h) < 2.0f) return v1 + (v2 - v1) * ((2.0f/3.0f) - h) * 6.0f; - return v1; -} - inline float RgbToHue(vec3 rgb) { float h_min = min(rgb.r, rgb.g, rgb.b); diff --git a/src/engine/shared/config_variables.h b/src/engine/shared/config_variables.h index b7293b68f..db8ef3513 100644 --- a/src/engine/shared/config_variables.h +++ b/src/engine/shared/config_variables.h @@ -247,38 +247,16 @@ MACRO_CONFIG_INT(SvRejoinTeam0, sv_rejoin_team_0, 1, 0, 1, CFGFLAG_SERVER, "Make MACRO_CONFIG_INT(ClReconnectTimeout, cl_reconnect_timeout, 120, 0, 600, CFGFLAG_CLIENT | CFGFLAG_SAVE, "How many seconds to wait before reconnecting (after timeout, 0 for off)") MACRO_CONFIG_INT(ClReconnectFull, cl_reconnect_full, 5, 0, 600, CFGFLAG_CLIENT | CFGFLAG_SAVE, "How many seconds to wait before reconnecting (when server is full, 0 for off)") -MACRO_CONFIG_INT(ClMessageSystemHue, cl_message_system_hue, 42, 0, 255, CFGFLAG_CLIENT | CFGFLAG_SAVE, "System message color hue") -MACRO_CONFIG_INT(ClMessageSystemSat, cl_message_system_sat, 255, 0, 255, CFGFLAG_CLIENT | CFGFLAG_SAVE, "System message color saturation") -MACRO_CONFIG_INT(ClMessageSystemLht, cl_message_system_lht, 192, 0, 255, CFGFLAG_CLIENT | CFGFLAG_SAVE, "System message color lightness") - -MACRO_CONFIG_INT(ClMessageClientHue, cl_message_client_hue, 147, 0, 255, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Client message color hue") -MACRO_CONFIG_INT(ClMessageClientSat, cl_message_client_sat, 255, 0, 255, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Client message color saturation") -MACRO_CONFIG_INT(ClMessageClientLht, cl_message_client_lht, 192, 0, 255, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Client message color lightness") - -MACRO_CONFIG_INT(ClMessageHighlightHue, cl_message_highlight_hue, 0, 0, 255, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Highlighted message color hue") -MACRO_CONFIG_INT(ClMessageHighlightSat, cl_message_highlight_sat, 255, 0, 255, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Highlighted message color saturation") -MACRO_CONFIG_INT(ClMessageHighlightLht, cl_message_highlight_lht, 192, 0, 255, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Highlighted message color lightness") +MACRO_CONFIG_COL(ClMessageSystemCol, cl_message_system_col, 2817983, 0, 0xFFFFFF, CFGFLAG_CLIENT | CFGFLAG_SAVE, "System message color") +MACRO_CONFIG_COL(ClMessageClientCol, cl_message_client_col, 65472, 0, 0xFFFFFF, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Client message color") +MACRO_CONFIG_COL(ClMessageHighlightCol, cl_message_highlight_col, 65471, 0, 0xFFFFFF, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Highlighted message color") +MACRO_CONFIG_COL(ClMessageTeamCol, cl_message_team_col, 5636050, 0, 0xFFFFFF, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Team message color") +MACRO_CONFIG_COL(ClMessageCol, cl_message_col, 255, 0, 0xFFFFFF, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Message color") +MACRO_CONFIG_COL(ClLaserInnerCol, cl_laser_inner_col, 11206591, 0, 0xFFFFFF, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Laser inner color") +MACRO_CONFIG_COL(ClLaserOutlineCol, cl_laser_outline_col, 11176233, 0, 0xFFFFFF, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Laser outline color") MACRO_CONFIG_INT(ClMessageFriend, cl_message_friend, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Enable coloring and the heart for friends") -MACRO_CONFIG_INT(ClMessageFriendHue, cl_message_friend_hue, 0, 0, 255, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Friend message color hue") -MACRO_CONFIG_INT(ClMessageFriendSat, cl_message_friend_sat, 255, 0, 255, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Friend message color saturation") -MACRO_CONFIG_INT(ClMessageFriendLht, cl_message_friend_lht, 145, 0, 255, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Friend message color lightness") - -MACRO_CONFIG_INT(ClMessageTeamHue, cl_message_team_hue, 85, 0, 255, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Team message color hue") -MACRO_CONFIG_INT(ClMessageTeamSat, cl_message_team_sat, 255, 0, 255, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Team message color saturation") -MACRO_CONFIG_INT(ClMessageTeamLht, cl_message_team_lht, 212, 0, 255, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Team message color lightness") - -MACRO_CONFIG_INT(ClMessageHue, cl_message_hue, 0, 0, 255, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Message color hue") -MACRO_CONFIG_INT(ClMessageSat, cl_message_sat, 0, 0, 255, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Message color saturation") -MACRO_CONFIG_INT(ClMessageLht, cl_message_lht, 255, 0, 255, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Message color lightness") - -MACRO_CONFIG_INT(ClLaserInnerHue, cl_laser_inner_hue, 170, 0, 255, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Laser inner color hue") -MACRO_CONFIG_INT(ClLaserInnerSat, cl_laser_inner_sat, 255, 0, 255, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Laser inner color saturation") -MACRO_CONFIG_INT(ClLaserInnerLht, cl_laser_inner_lht, 191, 0, 255, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Laser inner color lightness") - -MACRO_CONFIG_INT(ClLaserOutlineHue, cl_laser_outline_hue, 170, 0, 255, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Laser outline color hue") -MACRO_CONFIG_INT(ClLaserOutlineSat, cl_laser_outline_sat, 137, 0, 255, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Laser outline color saturation") -MACRO_CONFIG_INT(ClLaserOutlineLht, cl_laser_outline_lht, 41, 0, 255, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Laser outline color lightness") +MACRO_CONFIG_COL(ClMessageFriendCol, cl_message_friend_col, 65425, 0, 0xFFFFFF, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Friend message color") MACRO_CONFIG_INT(ConnTimeout, conn_timeout, 100, 5, 1000, CFGFLAG_SAVE|CFGFLAG_CLIENT|CFGFLAG_SERVER, "Network timeout") MACRO_CONFIG_INT(ConnTimeoutProtection, conn_timeout_protection, 1000, 5, 10000, CFGFLAG_SERVER, "Network timeout protection") diff --git a/src/engine/shared/console.cpp b/src/engine/shared/console.cpp index dea92bc60..b716facd4 100644 --- a/src/engine/shared/console.cpp +++ b/src/engine/shared/console.cpp @@ -771,6 +771,10 @@ static void ColVariableCommand(IConsole::IResult *pResult, void *pUserData) ColorHSLA hsl(*(pData->m_pVariable)); str_format(aBuf, sizeof(aBuf), "H: %d deg, 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); + + ColorRGBA rgb = color_cast(hsl); + str_format(aBuf, sizeof(aBuf), "R: %d, G: %d, B: %d", round_truncate(rgb.r * 255), round_truncate(rgb.g * 255), round_truncate(rgb.b * 255)); + pData->m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "console", aBuf); } } diff --git a/src/game/client/components/chat.cpp b/src/game/client/components/chat.cpp index 3f6029dae..036508c3b 100644 --- a/src/game/client/components/chat.cpp +++ b/src/game/client/components/chat.cpp @@ -804,7 +804,7 @@ void CChat::OnPrepareLines() if(g_Config.m_ClMessageFriend) { - vec3 rgb = HslToRgb(vec3(g_Config.m_ClMessageFriendHue / 255.0f, g_Config.m_ClMessageFriendSat / 255.0f, g_Config.m_ClMessageFriendLht / 255.0f)); + ColorRGBA rgb = color_cast(ColorHSLA(g_Config.m_ClMessageFriendCol)); TextRender()->TextColor(rgb.r, rgb.g, rgb.b, m_aLines[r].m_Friend ? 1.f : 0.f); //Less ugly hack to align messages m_aLines[r].m_TextContainerIndex = TextRender()->CreateTextContainer(&Cursor, "♥ "); } @@ -812,17 +812,17 @@ void CChat::OnPrepareLines() // render name if(m_aLines[r].m_ClientID == -1) // system { - vec3 rgb = HslToRgb(vec3(g_Config.m_ClMessageSystemHue / 255.0f, g_Config.m_ClMessageSystemSat / 255.0f, g_Config.m_ClMessageSystemLht / 255.0f)); + ColorRGBA rgb = color_cast(ColorHSLA(g_Config.m_ClMessageSystemCol)); TextRender()->TextColor(rgb.r, rgb.g, rgb.b, 1.f); } else if(m_aLines[r].m_ClientID == -2) // client { - vec3 rgb = HslToRgb(vec3(g_Config.m_ClMessageClientHue / 255.0f, g_Config.m_ClMessageClientSat / 255.0f, g_Config.m_ClMessageClientLht / 255.0f)); + ColorRGBA rgb = color_cast(ColorHSLA(g_Config.m_ClMessageClientCol)); TextRender()->TextColor(rgb.r, rgb.g, rgb.b, 1.f); } else if(m_aLines[r].m_Team) { - vec3 rgb = CalculateNameColor(vec3(g_Config.m_ClMessageTeamHue / 255.0f, g_Config.m_ClMessageTeamSat / 255.0f, g_Config.m_ClMessageTeamLht / 255.0f)); + ColorRGBA rgb = CalculateNameColor(ColorHSLA(g_Config.m_ClMessageTeamCol)); TextRender()->TextColor(rgb.r, rgb.g, rgb.b, 1.f); // team message } else if(m_aLines[r].m_NameColor == TEAM_RED) @@ -847,27 +847,27 @@ void CChat::OnPrepareLines() // render line if(m_aLines[r].m_ClientID == -1) // system { - vec3 rgb = HslToRgb(vec3(g_Config.m_ClMessageSystemHue / 255.0f, g_Config.m_ClMessageSystemSat / 255.0f, g_Config.m_ClMessageSystemLht / 255.0f)); + ColorRGBA rgb = color_cast(ColorHSLA(g_Config.m_ClMessageSystemCol)); TextRender()->TextColor(rgb.r, rgb.g, rgb.b, 1.f); } else if(m_aLines[r].m_ClientID == -2) // client { - vec3 rgb = HslToRgb(vec3(g_Config.m_ClMessageClientHue / 255.0f, g_Config.m_ClMessageClientSat / 255.0f, g_Config.m_ClMessageClientLht / 255.0f)); + ColorRGBA rgb = color_cast(ColorHSLA(g_Config.m_ClMessageClientCol)); TextRender()->TextColor(rgb.r, rgb.g, rgb.b, 1.f); } else if(m_aLines[r].m_Highlighted) // highlighted { - vec3 rgb = HslToRgb(vec3(g_Config.m_ClMessageHighlightHue / 255.0f, g_Config.m_ClMessageHighlightSat / 255.0f, g_Config.m_ClMessageHighlightLht / 255.0f)); + ColorRGBA rgb = color_cast(ColorHSLA(g_Config.m_ClMessageHighlightCol)); TextRender()->TextColor(rgb.r, rgb.g, rgb.b, 1.f); } else if(m_aLines[r].m_Team) // team message { - vec3 rgb = HslToRgb(vec3(g_Config.m_ClMessageTeamHue / 255.0f, g_Config.m_ClMessageTeamSat / 255.0f, g_Config.m_ClMessageTeamLht / 255.0f)); + ColorRGBA rgb = color_cast(ColorHSLA(g_Config.m_ClMessageTeamCol)); TextRender()->TextColor(rgb.r, rgb.g, rgb.b, 1.f); } else // regular message { - vec3 rgb = HslToRgb(vec3(g_Config.m_ClMessageHue / 255.0f, g_Config.m_ClMessageSat / 255.0f, g_Config.m_ClMessageLht / 255.0f)); + ColorRGBA rgb = color_cast(ColorHSLA(g_Config.m_ClMessageCol)); TextRender()->TextColor(rgb.r, rgb.g, rgb.b, 1.f); } diff --git a/src/game/client/components/console.cpp b/src/game/client/components/console.cpp index 8076bb9ab..a19c55e87 100644 --- a/src/game/client/components/console.cpp +++ b/src/game/client/components/console.cpp @@ -588,7 +588,7 @@ void CGameConsole::OnRender() } } - vec3 rgb = HslToRgb(vec3(g_Config.m_ClMessageHighlightHue / 255.0f, g_Config.m_ClMessageHighlightSat / 255.0f, g_Config.m_ClMessageHighlightLht / 255.0f)); + ColorRGBA rgb = color_cast(ColorHSLA(g_Config.m_ClMessageHighlightCol)); // render log (actual page, wrap lines) CInstance::CBacklogEntry *pEntry = pConsole->m_Backlog.Last(); diff --git a/src/game/client/components/items.cpp b/src/game/client/components/items.cpp index 3a0afd3d8..2fcef071d 100644 --- a/src/game/client/components/items.cpp +++ b/src/game/client/components/items.cpp @@ -204,7 +204,7 @@ void CItems::RenderFlag(const CNetObj_Flag *pPrev, const CNetObj_Flag *pCurrent, void CItems::RenderLaser(const struct CNetObj_Laser *pCurrent, bool IsPredicted) { - vec3 RGB; + ColorRGBA RGB; vec2 Pos = vec2(pCurrent->m_X, pCurrent->m_Y); vec2 From = vec2(pCurrent->m_FromX, pCurrent->m_FromY); vec2 Dir = normalize(Pos-From); @@ -223,9 +223,9 @@ void CItems::RenderLaser(const struct CNetObj_Laser *pCurrent, bool IsPredicted) Graphics()->TextureSet(-1); Graphics()->QuadsBegin(); - + // do outline - RGB = HslToRgb(vec3(g_Config.m_ClLaserOutlineHue / 255.0f, g_Config.m_ClLaserOutlineSat / 255.0f, g_Config.m_ClLaserOutlineLht / 255.0f)); + RGB = color_cast(ColorHSLA(g_Config.m_ClLaserOutlineCol)); vec4 OuterColor(RGB.r, RGB.g, RGB.b, 1.0f); Graphics()->SetColor(OuterColor.r, OuterColor.g, OuterColor.b, 1.0f); Out = vec2(Dir.y, -Dir.x) * (7.0f*Ia); @@ -238,7 +238,7 @@ void CItems::RenderLaser(const struct CNetObj_Laser *pCurrent, bool IsPredicted) Graphics()->QuadsDrawFreeform(&Freeform, 1); // do inner - RGB = HslToRgb(vec3(g_Config.m_ClLaserInnerHue / 255.0f, g_Config.m_ClLaserInnerSat / 255.0f, g_Config.m_ClLaserInnerLht / 255.0f)); + RGB = color_cast(ColorHSLA(g_Config.m_ClLaserInnerCol)); vec4 InnerColor(RGB.r, RGB.g, RGB.b, 1.0f); Out = vec2(Dir.y, -Dir.x) * (5.0f*Ia); Graphics()->SetColor(InnerColor.r, InnerColor.g, InnerColor.b, 1.0f); // center diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index 1f801a507..d0ba087a1 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -1513,34 +1513,39 @@ void CMenus::RenderSettingsHUD(CUIRect MainView) static int s_DefaultButton = 0; if(DoButton_Menu(&s_DefaultButton, Localize("Reset"), 0, &Button)) { - vec3 HSL = RgbToHsl(vec3(1.0f, 1.0f, 0.5f)) * 255.0f; // default values - g_Config.m_ClMessageSystemHue = HSL.h; - g_Config.m_ClMessageSystemSat = HSL.s; - g_Config.m_ClMessageSystemLht = HSL.l; + ColorHSLA HSL = color_cast(ColorRGBA(1.0f, 1.0f, 0.5f)); + g_Config.m_ClMessageSystemCol = HSL.Pack() & 0xFFFFFF; } } + + ColorHSLA SMColor(g_Config.m_ClMessageSystemCol); + Left.HSplitTop(20.0f, &Button, &Left); Button.VSplitLeft(15.0f, 0, &Button); Button.VSplitLeft(100.0f, &Label, &Button); Button.HMargin(2.0f, &Button); UI()->DoLabelScaled(&Label, Localize("Hue"), 14.0f, -1); - g_Config.m_ClMessageSystemHue = (int)(DoScrollbarH(&g_Config.m_ClMessageSystemHue, &Button, g_Config.m_ClMessageSystemHue / 255.0f)*255.0f); + SMColor.h = DoScrollbarH(&SMColor.h, &Button, SMColor.h); + Left.HSplitTop(20.0f, &Button, &Left); Button.VSplitLeft(15.0f, 0, &Button); Button.VSplitLeft(100.0f, &Label, &Button); Button.HMargin(2.0f, &Button); UI()->DoLabelScaled(&Label, Localize("Sat."), 14.0f, -1); - g_Config.m_ClMessageSystemSat = (int)(DoScrollbarH(&g_Config.m_ClMessageSystemSat, &Button, g_Config.m_ClMessageSystemSat / 255.0f)*255.0f); + SMColor.s = DoScrollbarH(&SMColor.s, &Button, SMColor.s); + Left.HSplitTop(20.0f, &Button, &Left); Button.VSplitLeft(15.0f, 0, &Button); Button.VSplitLeft(100.0f, &Label, &Button); Button.HMargin(2.0f, &Button); UI()->DoLabelScaled(&Label, Localize("Lht."), 14.0f, -1); - g_Config.m_ClMessageSystemLht = (int)(DoScrollbarH(&g_Config.m_ClMessageSystemLht, &Button, g_Config.m_ClMessageSystemLht / 255.0f)*255.0f); + SMColor.l = DoScrollbarH(&SMColor.l, &Button, SMColor.l); + + g_Config.m_ClMessageSystemCol = SMColor.Pack() & 0xFFFFFF; Left.HSplitTop(10.0f, &Label, &Left); - vec3 rgb = HslToRgb(vec3(g_Config.m_ClMessageSystemHue / 255.0f, g_Config.m_ClMessageSystemSat / 255.0f, g_Config.m_ClMessageSystemLht / 255.0f)); + ColorRGBA rgb = color_cast(SMColor); TextRender()->TextColor(rgb.r, rgb.g, rgb.b, 1.0f); @@ -1565,33 +1570,35 @@ void CMenus::RenderSettingsHUD(CUIRect MainView) static int s_DefaultButton = 0; if(DoButton_Menu(&s_DefaultButton, Localize("Reset"), 0, &Button)) { - vec3 HSL = RgbToHsl(vec3(1.0f, 0.5f, 0.5f)) * 255.0f; // default values - g_Config.m_ClMessageHighlightHue = HSL.h; - g_Config.m_ClMessageHighlightSat = HSL.s; - g_Config.m_ClMessageHighlightLht = HSL.l; + ColorHSLA HSL = color_cast(ColorRGBA(1.0f, 0.5f, 0.5f)); + g_Config.m_ClMessageHighlightCol = HSL.Pack() & 0xFFFFFF; } } + + ColorHSLA HMColor(g_Config.m_ClMessageHighlightCol); + Right.HSplitTop(20.0f, &Button, &Right); Button.VSplitLeft(15.0f, 0, &Button); Button.VSplitLeft(100.0f, &Label, &Button); Button.HMargin(2.0f, &Button); UI()->DoLabelScaled(&Label, Localize("Hue"), 14.0f, -1); - g_Config.m_ClMessageHighlightHue = (int)(DoScrollbarH(&g_Config.m_ClMessageHighlightHue, &Button, g_Config.m_ClMessageHighlightHue / 255.0f)*255.0f); + HMColor.h = DoScrollbarH(&HMColor.h, &Button, HMColor.h); Right.HSplitTop(20.0f, &Button, &Right); Button.VSplitLeft(15.0f, 0, &Button); Button.VSplitLeft(100.0f, &Label, &Button); Button.HMargin(2.0f, &Button); UI()->DoLabelScaled(&Label, Localize("Sat."), 14.0f, -1); - g_Config.m_ClMessageHighlightSat = (int)(DoScrollbarH(&g_Config.m_ClMessageHighlightSat, &Button, g_Config.m_ClMessageHighlightSat / 255.0f)*255.0f); + HMColor.s = DoScrollbarH(&HMColor.s, &Button, HMColor.s); Right.HSplitTop(20.0f, &Button, &Right); Button.VSplitLeft(15.0f, 0, &Button); Button.VSplitLeft(100.0f, &Label, &Button); Button.HMargin(2.0f, &Button); UI()->DoLabelScaled(&Label, Localize("Lht."), 14.0f, -1); - g_Config.m_ClMessageHighlightLht = (int)(DoScrollbarH(&g_Config.m_ClMessageHighlightLht, &Button, g_Config.m_ClMessageHighlightLht / 255.0f)*255.0f); + HMColor.l = DoScrollbarH(&HMColor.l, &Button, HMColor.l); + g_Config.m_ClMessageHighlightCol = HMColor.Pack() & 0xFFFFFF; Right.HSplitTop(10.0f, &Label, &Right); TextRender()->TextColor(0.75f, 0.5f, 0.75f, 1.0f); @@ -1599,7 +1606,7 @@ void CMenus::RenderSettingsHUD(CUIRect MainView) Label.VSplitLeft(tw, &Label, &Button); UI()->DoLabelScaled(&Label, Localize("Spectator"), 12.0f, -1); - vec3 rgb = HslToRgb(vec3(g_Config.m_ClMessageHighlightHue / 255.0f, g_Config.m_ClMessageHighlightSat / 255.0f, g_Config.m_ClMessageHighlightLht / 255.0f)); + ColorRGBA rgb = color_cast(HMColor); TextRender()->TextColor(rgb.r, rgb.g, rgb.b, 1.0f); char name[16]; str_copy(name, g_Config.m_PlayerName, sizeof(name)); @@ -1623,40 +1630,44 @@ void CMenus::RenderSettingsHUD(CUIRect MainView) static int s_DefaultButton = 0; if(DoButton_Menu(&s_DefaultButton, Localize("Reset"), 0, &Button)) { - vec3 HSL = RgbToHsl(vec3(0.65f, 1.0f, 0.65f)) * 255.0f; // default values - g_Config.m_ClMessageTeamHue = HSL.h; - g_Config.m_ClMessageTeamSat = HSL.s; - g_Config.m_ClMessageTeamLht = HSL.l; + ColorHSLA HSL = color_cast(ColorRGBA(0.65f, 1.0f, 0.65f)); + g_Config.m_ClMessageTeamCol = HSL.Pack() & 0xFFFFFF; } } + + ColorHSLA TMColor(g_Config.m_ClMessageTeamCol); + Left.HSplitTop(20.0f, &Button, &Left); Button.VSplitLeft(15.0f, 0, &Button); Button.VSplitLeft(100.0f, &Label, &Button); Button.HMargin(2.0f, &Button); UI()->DoLabelScaled(&Label, Localize("Hue"), 14.0f, -1); - g_Config.m_ClMessageTeamHue = (int)(DoScrollbarH(&g_Config.m_ClMessageTeamHue, &Button, g_Config.m_ClMessageTeamHue / 255.0f)*255.0f); + TMColor.h = DoScrollbarH(&TMColor.h, &Button, TMColor.h); + Left.HSplitTop(20.0f, &Button, &Left); Button.VSplitLeft(15.0f, 0, &Button); Button.VSplitLeft(100.0f, &Label, &Button); Button.HMargin(2.0f, &Button); UI()->DoLabelScaled(&Label, Localize("Sat."), 14.0f, -1); - g_Config.m_ClMessageTeamSat = (int)(DoScrollbarH(&g_Config.m_ClMessageTeamSat, &Button, g_Config.m_ClMessageTeamSat / 255.0f)*255.0f); + TMColor.s = DoScrollbarH(&TMColor.s, &Button, TMColor.s); + Left.HSplitTop(20.0f, &Button, &Left); Button.VSplitLeft(15.0f, 0, &Button); Button.VSplitLeft(100.0f, &Label, &Button); Button.HMargin(2.0f, &Button); UI()->DoLabelScaled(&Label, Localize("Lht."), 14.0f, -1); - g_Config.m_ClMessageTeamLht = (int)(DoScrollbarH(&g_Config.m_ClMessageTeamLht, &Button, g_Config.m_ClMessageTeamLht / 255.0f)*255.0f); + TMColor.l = DoScrollbarH(&TMColor.l, &Button, TMColor.l); + g_Config.m_ClMessageTeamCol = TMColor.Pack() & 0xFFFFFF; Left.HSplitTop(10.0f, &Label, &Left); - vec3 rgbn = CalculateNameColor(vec3(g_Config.m_ClMessageTeamHue / 255.0f, g_Config.m_ClMessageTeamSat / 255.0f, g_Config.m_ClMessageTeamLht / 255.0f)); + ColorRGBA rgbn = CalculateNameColor(TMColor); TextRender()->TextColor(rgbn.r, rgbn.g, rgbn.b, 1.0f); float tw = TextRender()->TextWidth(0, 12.0f, Localize("Player"), -1); Label.VSplitLeft(tw, &Label, &Button); UI()->DoLabelScaled(&Label, Localize("Player"), 12.0f, -1); - vec3 rgb = HslToRgb(vec3(g_Config.m_ClMessageTeamHue / 255.0f, g_Config.m_ClMessageTeamSat / 255.0f, g_Config.m_ClMessageTeamLht / 255.0f)); + ColorRGBA rgb = color_cast(TMColor); TextRender()->TextColor(rgb.r, rgb.g, rgb.b, 1.0f); str_format(aBuf, sizeof(aBuf), ": %s!", Localize("We will win")); UI()->DoLabelScaled(&Button, aBuf, 12.0f, -1); @@ -1675,11 +1686,7 @@ void CMenus::RenderSettingsHUD(CUIRect MainView) { static int s_DefaultButton = 0; if(DoButton_Menu(&s_DefaultButton, Localize("Reset"), 0, &Button)) - { - g_Config.m_ClMessageFriendHue = 0; - g_Config.m_ClMessageFriendSat = 255; - g_Config.m_ClMessageFriendLht = 145; - } + g_Config.m_ClMessageFriendCol = ColorHSLA(0, 1, 145/255.0f).Pack() & 0xFFFFFF; } if(DoButton_CheckBox(&g_Config.m_ClMessageFriend, "", g_Config.m_ClMessageFriend, &Enable)) @@ -1687,30 +1694,33 @@ void CMenus::RenderSettingsHUD(CUIRect MainView) g_Config.m_ClMessageFriend ^= 1; } + ColorHSLA FMColor(g_Config.m_ClMessageFriendCol); + Right.HSplitTop(20.0f, &Button, &Right); Button.VSplitLeft(15.0f, 0, &Button); Button.VSplitLeft(100.0f, &Label, &Button); Button.HMargin(2.0f, &Button); UI()->DoLabelScaled(&Label, Localize("Hue"), 14.0f, -1); - g_Config.m_ClMessageFriendHue = (int)(DoScrollbarH(&g_Config.m_ClMessageFriendHue, &Button, g_Config.m_ClMessageFriendHue / 255.0f)*255.0f); + FMColor.h = DoScrollbarH(&FMColor.h, &Button, FMColor.h); Right.HSplitTop(20.0f, &Button, &Right); Button.VSplitLeft(15.0f, 0, &Button); Button.VSplitLeft(100.0f, &Label, &Button); Button.HMargin(2.0f, &Button); UI()->DoLabelScaled(&Label, Localize("Sat."), 14.0f, -1); - g_Config.m_ClMessageFriendSat = (int)(DoScrollbarH(&g_Config.m_ClMessageFriendSat, &Button, g_Config.m_ClMessageFriendSat / 255.0f)*255.0f); + FMColor.s = DoScrollbarH(&FMColor.s, &Button, FMColor.s); Right.HSplitTop(20.0f, &Button, &Right); Button.VSplitLeft(15.0f, 0, &Button); Button.VSplitLeft(100.0f, &Label, &Button); Button.HMargin(2.0f, &Button); UI()->DoLabelScaled(&Label, Localize("Lht."), 14.0f, -1); - g_Config.m_ClMessageFriendLht = (int)(DoScrollbarH(&g_Config.m_ClMessageFriendLht, &Button, g_Config.m_ClMessageFriendLht / 255.0f)*255.0f); + FMColor.l = DoScrollbarH(&FMColor.l, &Button, FMColor.l); + g_Config.m_ClMessageFriendCol = FMColor.Pack() & 0xFFFFFF; Right.HSplitTop(10.0f, &Label, &Right); - vec3 rgbf = HslToRgb(vec3(g_Config.m_ClMessageFriendHue / 255.0f, g_Config.m_ClMessageFriendSat / 255.0f, g_Config.m_ClMessageFriendLht / 255.0f)); + ColorRGBA rgbf = color_cast(FMColor); TextRender()->TextColor(rgbf.r, rgbf.g, rgbf.b, 1.0f); float hw = TextRender()->TextWidth(0, 12.0f, "♥ ", -1); Label.VSplitLeft(hw, &Heart, &Label); @@ -1721,7 +1731,7 @@ void CMenus::RenderSettingsHUD(CUIRect MainView) Label.VSplitLeft(tw, &Label, &Button); UI()->DoLabelScaled(&Label, Localize("Friend"), 12.0f, -1); - vec3 rgb = HslToRgb(vec3(g_Config.m_ClMessageHue / 255.0f, g_Config.m_ClMessageSat / 255.0f, g_Config.m_ClMessageLht / 255.0f)); + ColorRGBA rgb = color_cast(ColorHSLA(g_Config.m_ClMessageCol)); TextRender()->TextColor(rgb.r, rgb.g, rgb.b, 1.0f); str_format(aBuf, sizeof(aBuf), ": %s", Localize("Hi o/")); UI()->DoLabelScaled(&Button, aBuf, 12.0f, -1); @@ -1738,31 +1748,35 @@ void CMenus::RenderSettingsHUD(CUIRect MainView) static int s_DefaultButton = 0; if(DoButton_Menu(&s_DefaultButton, Localize("Reset"), 0, &Button)) { - vec3 HSL = RgbToHsl(vec3(1.0f, 1.0f, 1.0f)) * 255.0f; // default values - g_Config.m_ClMessageHue = HSL.h; - g_Config.m_ClMessageSat = HSL.s; - g_Config.m_ClMessageLht = HSL.l; + ColorHSLA HSL = color_cast(ColorRGBA(1.0f, 1.0f, 1.0f)); + g_Config.m_ClMessageCol = HSL.Pack() & 0xFFFFFF; } } + + ColorHSLA MColor(g_Config.m_ClMessageCol); + Left.HSplitTop(20.0f, &Button, &Left); Button.VSplitLeft(15.0f, 0, &Button); Button.VSplitLeft(100.0f, &Label, &Button); Button.HMargin(2.0f, &Button); UI()->DoLabelScaled(&Label, Localize("Hue"), 14.0f, -1); - g_Config.m_ClMessageHue = (int)(DoScrollbarH(&g_Config.m_ClMessageHue, &Button, g_Config.m_ClMessageHue / 255.0f)*255.0f); + MColor.h = DoScrollbarH(&MColor.h, &Button, MColor.h); + Left.HSplitTop(20.0f, &Button, &Left); Button.VSplitLeft(15.0f, 0, &Button); Button.VSplitLeft(100.0f, &Label, &Button); Button.HMargin(2.0f, &Button); UI()->DoLabelScaled(&Label, Localize("Sat."), 14.0f, -1); - g_Config.m_ClMessageSat = (int)(DoScrollbarH(&g_Config.m_ClMessageSat, &Button, g_Config.m_ClMessageSat / 255.0f)*255.0f); + MColor.s = DoScrollbarH(&MColor.s, &Button, MColor.s); + Left.HSplitTop(20.0f, &Button, &Left); Button.VSplitLeft(15.0f, 0, &Button); Button.VSplitLeft(100.0f, &Label, &Button); Button.HMargin(2.0f, &Button); UI()->DoLabelScaled(&Label, Localize("Lht."), 14.0f, -1); - g_Config.m_ClMessageLht = (int)(DoScrollbarH(&g_Config.m_ClMessageLht, &Button, g_Config.m_ClMessageLht / 255.0f)*255.0f); + MColor.l = DoScrollbarH(&MColor.l, &Button, MColor.l); + g_Config.m_ClMessageCol = MColor.Pack() & 0xFFFFFF; Left.HSplitTop(10.0f, &Label, &Left); TextRender()->TextColor(0.8f, 0.8f, 0.8f, 1.0f); @@ -1770,7 +1784,7 @@ void CMenus::RenderSettingsHUD(CUIRect MainView) Label.VSplitLeft(tw, &Label, &Button); UI()->DoLabelScaled(&Label, Localize("Player"), 12.0f, -1); - vec3 rgb = HslToRgb(vec3(g_Config.m_ClMessageHue / 255.0f, g_Config.m_ClMessageSat / 255.0f, g_Config.m_ClMessageLht / 255.0f)); + ColorRGBA rgb = color_cast(MColor); TextRender()->TextColor(rgb.r, rgb.g, rgb.b, 1.0f); str_format(aBuf, sizeof(aBuf), ": %s :D", Localize("Hello and welcome")); UI()->DoLabelScaled(&Button, aBuf, 12.0f, -1); @@ -1795,32 +1809,35 @@ void CMenus::RenderSettingsHUD(CUIRect MainView) static int s_DefaultButton = 0; if(DoButton_Menu(&s_DefaultButton, Localize("Reset"), 0, &Button)) { - vec3 HSL = RgbToHsl(vec3(0.5f, 0.5f, 1.0f)) * 255.0f; // default values - g_Config.m_ClLaserInnerHue = HSL.h; - g_Config.m_ClLaserInnerSat = HSL.s; - g_Config.m_ClLaserInnerLht = HSL.l; + ColorHSLA HSL = color_cast(ColorRGBA(0.5f, 0.5f, 1.0f)); + g_Config.m_ClLaserInnerCol = HSL.Pack() & 0xFFFFFF; } } + ColorHSLA LIColor(g_Config.m_ClLaserInnerCol); + Laser.HSplitTop(20.0f, &Button, &Laser); Button.VSplitLeft(20.0f, 0, &Button); Button.VSplitLeft(100.0f, &Label, &Button); Button.HMargin(2.0f, &Button); UI()->DoLabelScaled(&Label, Localize("Hue"), 12.0f, -1); - g_Config.m_ClLaserInnerHue = (int)(DoScrollbarH(&g_Config.m_ClLaserInnerHue, &Button, g_Config.m_ClLaserInnerHue / 255.0f)*255.0f); + LIColor.h = DoScrollbarH(&LIColor.h, &Button, LIColor.h); + Laser.HSplitTop(20.0f, &Button, &Laser); Button.VSplitLeft(20.0f, 0, &Button); Button.VSplitLeft(100.0f, &Label, &Button); Button.HMargin(2.0f, &Button); UI()->DoLabelScaled(&Label, Localize("Sat."), 12.0f, -1); - g_Config.m_ClLaserInnerSat = (int)(DoScrollbarH(&g_Config.m_ClLaserInnerSat, &Button, g_Config.m_ClLaserInnerSat / 255.0f)*255.0f); + LIColor.s = DoScrollbarH(&LIColor.s, &Button, LIColor.s); + Laser.HSplitTop(20.0f, &Button, &Laser); Button.VSplitLeft(20.0f, 0, &Button); Button.VSplitLeft(100.0f, &Label, &Button); Button.HMargin(2.0f, &Button); UI()->DoLabelScaled(&Label, Localize("Lht."), 12.0f, -1); - g_Config.m_ClLaserInnerLht = (int)(DoScrollbarH(&g_Config.m_ClLaserInnerLht, &Button, g_Config.m_ClLaserInnerLht / 255.0f)*255.0f); + LIColor.l = DoScrollbarH(&LIColor.l, &Button, LIColor.l); + g_Config.m_ClLaserInnerCol = LIColor.Pack() & 0xFFFFFF; Laser.HSplitTop(10.0f, 0, &Laser); Laser.HSplitTop(20.0f, &Label, &Laser); @@ -1831,37 +1848,39 @@ void CMenus::RenderSettingsHUD(CUIRect MainView) static int s_DefaultButton = 0; if(DoButton_Menu(&s_DefaultButton, Localize("Reset"), 0, &Button)) { - vec3 HSL = RgbToHsl(vec3(0.075f, 0.075f, 0.25f)) * 255.0f; // default values - g_Config.m_ClLaserOutlineHue = HSL.h; - g_Config.m_ClLaserOutlineSat = HSL.s; - g_Config.m_ClLaserOutlineLht = HSL.l; + ColorHSLA HSL = color_cast(ColorRGBA(0.075f, 0.075f, 0.25f)); + g_Config.m_ClLaserOutlineCol = HSL.Pack() & 0xFFFFFF; } } + ColorRGBA LOColor(g_Config.m_ClLaserOutlineCol); + Laser.HSplitTop(20.0f, &Button, &Laser); Button.VSplitLeft(15.0f, 0, &Button); Button.VSplitLeft(100.0f, &Label, &Button); Button.HMargin(2.0f, &Button); UI()->DoLabelScaled(&Label, Localize("Hue"), 12.0f, -1); - g_Config.m_ClLaserOutlineHue = (int)(DoScrollbarH(&g_Config.m_ClLaserOutlineHue, &Button, g_Config.m_ClLaserOutlineHue / 255.0f)*255.0f); + LOColor.h = DoScrollbarH(&LOColor.h, &Button, LOColor.h); + Laser.HSplitTop(20.0f, &Button, &Laser); Button.VSplitLeft(15.0f, 0, &Button); Button.VSplitLeft(100.0f, &Label, &Button); Button.HMargin(2.0f, &Button); UI()->DoLabelScaled(&Label, Localize("Sat."), 12.0f, -1); - g_Config.m_ClLaserOutlineSat = (int)(DoScrollbarH(&g_Config.m_ClLaserOutlineSat, &Button, g_Config.m_ClLaserOutlineSat / 255.0f)*255.0f); + LOColor.s = DoScrollbarH(&LOColor.s, &Button, LOColor.s); + Laser.HSplitTop(20.0f, &Button, &Laser); Button.VSplitLeft(15.0f, 0, &Button); Button.VSplitLeft(100.0f, &Label, &Button); Button.HMargin(2.0f, &Button); UI()->DoLabelScaled(&Label, Localize("Lht."), 12.0f, -1); - g_Config.m_ClLaserOutlineLht = (int)(DoScrollbarH(&g_Config.m_ClLaserOutlineLht, &Button, g_Config.m_ClLaserOutlineLht / 255.0f)*255.0f); - + LOColor.l = DoScrollbarH(&LOColor.l, &Button, LOColor.l); + g_Config.m_ClLaserOutlineCol = LOColor.Pack() & 0xFFFFFF; //Laser.HSplitTop(8.0f, &Weapon, &Laser); Weapon.VSplitLeft(30.0f, 0, &Weapon); - vec3 RGB; + ColorRGBA RGB; vec2 From = vec2(Weapon.x, Weapon.y + Weapon.h / 2.0f); vec2 Pos = vec2(Weapon.x + Weapon.w - 10.0f, Weapon.y + Weapon.h / 2.0f); @@ -1872,7 +1891,7 @@ void CMenus::RenderSettingsHUD(CUIRect MainView) Graphics()->QuadsBegin(); // do outline - RGB = HslToRgb(vec3(g_Config.m_ClLaserOutlineHue / 255.0f, g_Config.m_ClLaserOutlineSat / 255.0f, g_Config.m_ClLaserOutlineLht / 255.0f)); + RGB = color_cast(ColorHSLA(g_Config.m_ClLaserOutlineCol)); vec4 OuterColor(RGB.r, RGB.g, RGB.b, 1.0f); Graphics()->SetColor(RGB.r, RGB.g, RGB.b, 1.0f); // outline Out = vec2(0.0f, -1.0f) * (3.15f); @@ -1885,7 +1904,7 @@ void CMenus::RenderSettingsHUD(CUIRect MainView) Graphics()->QuadsDrawFreeform(&Freeform, 1); // do inner - RGB = HslToRgb(vec3(g_Config.m_ClLaserInnerHue / 255.0f, g_Config.m_ClLaserInnerSat / 255.0f, g_Config.m_ClLaserInnerLht / 255.0f)); + RGB = color_cast(ColorHSLA(g_Config.m_ClLaserInnerCol)); vec4 InnerColor(RGB.r, RGB.g, RGB.b, 1.0f); Out = vec2(0.0f, -1.0f) * (2.25f); Graphics()->SetColor(InnerColor.r, InnerColor.g, InnerColor.b, 1.0f); // center diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 39c3cf043..a776b4f5c 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -1829,9 +1829,9 @@ int CGameClient::IntersectCharacter(vec2 HookPos, vec2 NewPos, vec2& NewPos2, in return ClosestID; } -vec3 CalculateNameColor(vec3 TextColorHSL) +ColorRGBA CalculateNameColor(ColorHSLA TextColorHSL) { - return HslToRgb(vec3(TextColorHSL.h, TextColorHSL.s * 0.68f, TextColorHSL.l * 0.81f)); + return color_cast(ColorHSLA(TextColorHSL.h, TextColorHSL.s * 0.68f, TextColorHSL.l * 0.81f)); } void CGameClient::UpdatePrediction() diff --git a/src/game/client/gameclient.h b/src/game/client/gameclient.h index 2c3c1f65d..aea18ce70 100644 --- a/src/game/client/gameclient.h +++ b/src/game/client/gameclient.h @@ -431,6 +431,6 @@ private: class CTeamsCore m_TeamsPredicted; }; -vec3 CalculateNameColor(vec3 TextColorHSL); +ColorRGBA CalculateNameColor(ColorHSLA TextColorHSL); #endif