Skip to content

Commit

Permalink
Merge pull request #28 from SollyBunny/tater_rainbow
Browse files Browse the repository at this point in the history
Fix / cleanup rainbow
  • Loading branch information
sjrc6 authored Nov 24, 2024
2 parents 6f86450 + 05c5293 commit 3a22a78
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 50 deletions.
3 changes: 2 additions & 1 deletion src/engine/shared/tater_variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,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, "")
5 changes: 4 additions & 1 deletion src/game/client/components/menus_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3652,7 +3652,7 @@ void CMenus::RenderSettingsTClient(CUIRect MainView)
Ui()->DoLabel(&Label, Localize("Rainbow"), HeadlineFontSize, TEXTALIGN_ML);
Column.HSplitTop(MarginSmall, nullptr, &Column);

static std::vector<const char *> s_DropDownNames = {Localize("Rainbow"), Localize("Pulse"), Localize("Black")};
static std::vector<const char *> 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;
Expand All @@ -3670,6 +3670,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);
Expand Down
96 changes: 49 additions & 47 deletions src/game/client/components/rainbow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,67 +10,69 @@

#include "rainbow.h"

void CRainbow::TransformColor(unsigned char Mode, int Tick, CTeeRenderInfo *pinfo)
template <typename T>
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<ColorRGBA>(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<ColorRGBA>(PlayerColBody);
pinfo->m_ColorFeet = color_cast<ColorRGBA>(PlayerColFeet);
// pinfo->m_BloodColor = pinfo->m_BloodColor; // TODO reset blood color
case COLORMODE_RAINBOW:
Col = color_cast<ColorRGBA>(ColorHSLA(DefTick, 1.0f, 0.5f));
break;
case COLORMODE_PULSE:
Col = color_cast<ColorRGBA>(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<ColorRGBA>(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;
}
}
}
2 changes: 1 addition & 1 deletion src/game/client/components/rainbow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
};

Expand Down

0 comments on commit 3a22a78

Please sign in to comment.