From 05c5293b679fb75c4fd7ba78c20977ba57778497 Mon Sep 17 00:00:00 2001 From: SollyBunny Date: Sat, 23 Nov 2024 23:27:19 +0000 Subject: [PATCH] Rainbow scroll speed + fix pulse --- src/engine/shared/tater_variables.h | 3 +- src/game/client/components/menus_settings.cpp | 5 +- src/game/client/components/rainbow.cpp | 96 ++++++++++--------- src/game/client/components/rainbow.h | 2 +- 4 files changed, 56 insertions(+), 50 deletions(-) diff --git a/src/engine/shared/tater_variables.h b/src/engine/shared/tater_variables.h index d2934c23ba4..41c4840961b 100644 --- a/src/engine/shared/tater_variables.h +++ b/src/engine/shared/tater_variables.h @@ -127,7 +127,8 @@ MACRO_CONFIG_INT(ClAutoVerify, tc_auto_verify, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG // Rainbow MACRO_CONFIG_INT(ClRainbow, tc_rainbow, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Turn on rainbow client side") MACRO_CONFIG_INT(ClRainbowOthers, tc_rainbow_others, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Turn on rainbow client side for others") -MACRO_CONFIG_INT(ClRainbowMode, tc_rainbow_mode, 1, 1, 4, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Rainbow mode (1: rainbow, 2: pulse, 3: darkness)") +MACRO_CONFIG_INT(ClRainbowMode, tc_rainbow_mode, 1, 1, 4, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Rainbow mode (1: rainbow, 2: pulse, 3: darkness, 4: random)") +MACRO_CONFIG_INT(ClRainbowSpeed, tc_rainbow_Speed, 100, 0, 10000, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Rainbow speed as a percentage (50 = half speed, 200 = double speed)") // AAAAAAA MACRO_CONFIG_INT(ClAmIFrozen, EEEfrz, 0, 0, 1, CFGFLAG_CLIENT, "") diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index 6aebbcc14ed..5a89604ed16 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -3608,7 +3608,7 @@ void CMenus::RenderSettingsTClient(CUIRect MainView) Ui()->DoLabel(&Label, Localize("Rainbow"), HeadlineFontSize, TEXTALIGN_ML); Column.HSplitTop(MarginSmall, nullptr, &Column); - static std::vector s_DropDownNames = {Localize("Rainbow"), Localize("Pulse"), Localize("Black")}; + static std::vector s_DropDownNames = {Localize("Rainbow"), Localize("Pulse"), Localize("Black"), Localize("Random")}; static CUi::SDropDownState s_RainbowDropDownState; static CScrollRegion s_RainbowDropDownScrollRegion; s_RainbowDropDownState.m_SelectionPopupContext.m_pScrollRegion = &s_RainbowDropDownScrollRegion; @@ -3625,6 +3625,9 @@ void CMenus::RenderSettingsTClient(CUIRect MainView) dbg_msg("rainbow", "rainbow mode changed to %d", g_Config.m_ClRainbowMode); } Column.HSplitTop(MarginExtraSmall, nullptr, &Column); + Column.HSplitTop(LineSize, &Button, &Column); + Ui()->DoScrollbarOption(&g_Config.m_ClRainbowSpeed, &g_Config.m_ClRainbowSpeed, &Button, Localize("Rainbow speed"), 0, 5000, &CUi::ms_LogarithmicScrollbarScale, 0, "%"); + Column.HSplitTop(MarginExtraSmall, nullptr, &Column); s_SectionBoxes.back().h = Column.y - s_SectionBoxes.back().y; Column.HSplitTop(MarginSmall, nullptr, &Column); diff --git a/src/game/client/components/rainbow.cpp b/src/game/client/components/rainbow.cpp index e231ee288b0..8180ff2094e 100644 --- a/src/game/client/components/rainbow.cpp +++ b/src/game/client/components/rainbow.cpp @@ -10,67 +10,69 @@ #include "rainbow.h" -void CRainbow::TransformColor(unsigned char Mode, int Tick, CTeeRenderInfo *pinfo) +template +T color_lerp(T a, T b, float c) { + T result; + for(size_t i = 0; i < 4; ++i) + result[i] = a[i] + c * (b[i] - a[i]); + return result; +} + +void CRainbow::OnRender() { - if(!Mode) - return; - int DefTick = Tick % 255; + if(!g_Config.m_ClRainbow && !g_Config.m_ClRainbowOthers) + return; + if(g_Config.m_ClRainbowMode == 0) + return; - const ColorHSLA PlayerColBody = ColorHSLA(g_Config.m_ClPlayerColorBody); - const ColorHSLA PlayerColFeet = ColorHSLA(g_Config.m_ClPlayerColorFeet); + static float Time = 0.0f; + Time += Client()->RenderFrameTime() * ((float)g_Config.m_ClRainbowSpeed / 100.0f); + float DefTick = std::fmod(Time, 1.0f); + ColorRGBA Col; - pinfo->m_CustomColoredSkin = true; - if(Mode == COLORMODE_RAINBOW) - { - const ColorRGBA Col = color_cast(ColorHSLA((float)DefTick / 255.0f, 1.0f, 0.5f)); - pinfo->m_ColorBody = Col; - pinfo->m_ColorFeet = Col; - pinfo->m_BloodColor = Col; - } - else if(Mode == COLORMODE_PULSE) - { - pinfo->m_ColorBody.s = 1.0f; - pinfo->m_ColorFeet.s = 1.0f; - pinfo->m_BloodColor.s = 1.0f; - pinfo->m_ColorBody.l = 0.5f + std::fabs(((float)DefTick / 255.0f) - 0.5f); - pinfo->m_ColorFeet.l = 0.5f + std::fabs(((float)DefTick / 255.0f) - 0.5f); - pinfo->m_BloodColor.l = 0.5f + std::fabs(((float)DefTick / 255.0f) - 0.5f); - pinfo->m_ColorBody.h = (float)DefTick / 255.0f; - pinfo->m_ColorFeet.h = (float)DefTick / 255.0f; - pinfo->m_BloodColor.h = (float)DefTick / 255.0f; - } - else if(Mode == COLORMODE_DARKNESS) - { - pinfo->m_ColorBody = ColorRGBA(0.0f, 0.0f, 0.0f); - pinfo->m_ColorFeet = ColorRGBA(0.0f, 0.0f, 0.0f); - pinfo->m_BloodColor = ColorRGBA(0.0f, 0.0f, 0.0f); - } - else + switch(g_Config.m_ClRainbowMode) { - pinfo->m_CustomColoredSkin = true; - pinfo->m_ColorBody = color_cast(PlayerColBody); - pinfo->m_ColorFeet = color_cast(PlayerColFeet); - // pinfo->m_BloodColor = pinfo->m_BloodColor; // TODO reset blood color + case COLORMODE_RAINBOW: + Col = color_cast(ColorHSLA(DefTick, 1.0f, 0.5f)); + break; + case COLORMODE_PULSE: + Col = color_cast(ColorHSLA(std::fmod(std::floor(Time) * 0.1f, 1.0f), 1.0f, 0.5f + std::fabs(DefTick - 0.5f))); + break; + case COLORMODE_DARKNESS: + Col = ColorRGBA(0.0f, 0.0f, 0.0f); + break; + case COLORMODE_RANDOM: + static ColorHSLA Col1 = ColorHSLA(0.0f, 0.0f, 0.0f, 0.0f), Col2 = ColorHSLA(0.0f, 0.0f, 0.0f, 0.0f); + if(Col2.a == 0.0f) // Create first target + Col2 = ColorHSLA((float)rand() / (float)RAND_MAX, 1.0f, (float)rand() / (float)RAND_MAX, 1.0f); + static float LastSwap = -INFINITY; + if(Time - LastSwap > 1.0f) // Shift target to source, create new target + { + LastSwap = Time; + Col1 = Col2; + Col2 = ColorHSLA((float)rand() / (float)RAND_MAX, 1.0f, (float)rand() / (float)RAND_MAX, 1.0f); + } + Col = color_cast(color_lerp(Col1, Col2, DefTick)); + break; } -} -void CRainbow::OnRender() -{ for(int i = 0; i < MAX_CLIENTS; i++) { + if(!m_pClient->m_Snap.m_aCharacters[i].m_Active) + continue; + // check if local player bool Local = m_pClient->m_Snap.m_LocalClientId == i; - CTeeRenderInfo *RenderInfo = &m_pClient->m_aClients[i].m_RenderInfo; + // check if rainbow is enabled - if(g_Config.m_ClRainbow && Local) // rainbow is enabled and is own player - { - TransformColor(g_Config.m_ClRainbowMode, m_pClient->m_GameWorld.m_GameTick, RenderInfo); - } - else if(g_Config.m_ClRainbowOthers && !Local) // rainbow is enabled and is not own player + if(Local ? g_Config.m_ClRainbow : g_Config.m_ClRainbowOthers) { - TransformColor(g_Config.m_ClRainbowMode, m_pClient->m_GameWorld.m_GameTick, RenderInfo); + RenderInfo->m_BloodColor = Col; + RenderInfo->m_ColorBody = Col; + RenderInfo->m_ColorFeet = Col; + RenderInfo->m_CustomColoredSkin = true; } } } diff --git a/src/game/client/components/rainbow.h b/src/game/client/components/rainbow.h index f2c4958c1a3..65409f2eab7 100644 --- a/src/game/client/components/rainbow.h +++ b/src/game/client/components/rainbow.h @@ -9,12 +9,12 @@ class CRainbow : public CComponent virtual int Sizeof() const override { return sizeof(*this); } virtual void OnRender() override; - void TransformColor(unsigned char mode, int tick, CTeeRenderInfo *pinfo); enum COLORMODE { COLORMODE_RAINBOW = 1, COLORMODE_PULSE, COLORMODE_DARKNESS, + COLORMODE_RANDOM }; };