Skip to content

Commit

Permalink
Merge pull request ddnet#9495 from Robyt3/Client-Skins7-Various-Refac…
Browse files Browse the repository at this point in the history
…toring

Fix incorrect default 0.7 skin parts being used, various minor refactoring
  • Loading branch information
def- authored Jan 8, 2025
2 parents 694b1d8 + f4d0758 commit 0ad732f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 22 deletions.
3 changes: 1 addition & 2 deletions src/game/client/components/scoreboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,7 @@ void CScoreboard::RenderScoreboard(CUIRect Scoreboard, int Team, int CountStart,
Graphics()->QuadsBegin();
if(m_pClient->m_Snap.m_pGameInfoObj->m_GameFlags & GAMEFLAG_TEAMS)
{
ColorRGBA Color = m_pClient->m_Skins7.GetTeamColor(true, 0, m_pClient->m_aClients[pInfo->m_ClientId].m_Team, protocol7::SKINPART_BODY);
Graphics()->SetColor(Color.r, Color.g, Color.b, Color.a);
Graphics()->SetColor(m_pClient->m_Skins7.GetTeamColor(true, 0, m_pClient->m_aClients[pInfo->m_ClientId].m_Team, protocol7::SKINPART_BODY));
}
CTeeRenderInfo TeeInfo = m_pClient->m_aClients[pInfo->m_ClientId].m_RenderInfo;
TeeInfo.m_Size *= TeeSizeMod;
Expand Down
14 changes: 9 additions & 5 deletions src/game/client/components/skins7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ int unsigned *CSkins7::ms_apColorVariables[NUM_DUMMIES][protocol7::NUM_SKINPARTS
// TODO: uncomment
// const float MIN_EYE_BODY_COLOR_DIST = 80.f; // between body and eyes (LAB color space)

bool CSkins7::IsSpecialSkin(const char *pName)
{
return str_startswith(pName, "x_") != nullptr;
}

int CSkins7::SkinPartScan(const char *pName, int IsDir, int DirType, void *pUser)
{
CSkins7 *pSelf = (CSkins7 *)pUser;
Expand Down Expand Up @@ -96,7 +101,7 @@ int CSkins7::SkinPartScan(const char *pName, int IsDir, int DirType, void *pUser

// set skin part data
Part.m_Flags = 0;
if(pName[0] == 'x' && pName[1] == '_')
if(IsSpecialSkin(pName))
Part.m_Flags |= SKINFLAG_SPECIAL;
if(DirType != IStorage::TYPE_SAVE)
Part.m_Flags |= SKINFLAG_STANDARD;
Expand Down Expand Up @@ -130,7 +135,7 @@ int CSkins7::SkinScan(const char *pName, int IsDir, int DirType, void *pUser)
// init
CSkin Skin;
str_copy(Skin.m_aName, pName, 1 + str_length(pName) - str_length(".json"));
const bool SpecialSkin = pName[0] == 'x' && pName[1] == '_';
const bool SpecialSkin = IsSpecialSkin(pName);
Skin.m_Flags = SpecialSkin ? SKINFLAG_SPECIAL : 0;
if(DirType != IStorage::TYPE_SAVE)
Skin.m_Flags |= SKINFLAG_STANDARD;
Expand Down Expand Up @@ -430,7 +435,7 @@ const CSkins7::CSkinPart *CSkins7::FindSkinPartOrNullptr(int Part, const char *p

const CSkins7::CSkinPart *CSkins7::FindDefaultSkinPart(int Part) const
{
const char *pDefaultPartName = Part == protocol7::SKINPART_MARKING || Part == protocol7::SKINPART_DECORATION ? "" : "default";
const char *pDefaultPartName = Part == protocol7::SKINPART_MARKING || Part == protocol7::SKINPART_DECORATION ? "" : "standard";
const CSkinPart *pDefault = FindSkinPartOrNullptr(Part, pDefaultPartName, false);
if(pDefault != nullptr)
{
Expand Down Expand Up @@ -538,8 +543,7 @@ bool CSkins7::ValidateSkinParts(char *apPartNames[protocol7::NUM_SKINPARTS], int

bool CSkins7::SaveSkinfile(const char *pName, int Dummy)
{
const bool SpecialSkin = pName[0] == 'x' && pName[1] == '_';
dbg_assert(!SpecialSkin, "Cannot save special skins");
dbg_assert(!IsSpecialSkin(pName), "Cannot save special skins");

char aBuf[IO_MAX_PATH_LENGTH];
str_format(aBuf, sizeof(aBuf), SKINS_DIR "/%s.json", pName);
Expand Down
2 changes: 2 additions & 0 deletions src/game/client/components/skins7.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class CSkins7 : public CComponent
IGraphics::CTextureHandle XmasHatTexture() const { return m_XmasHatTexture; }
IGraphics::CTextureHandle BotDecorationTexture() const { return m_BotTexture; }

static bool IsSpecialSkin(const char *pName);

private:
int m_ScanningPart;
std::chrono::nanoseconds m_LastRefreshTime;
Expand Down
20 changes: 5 additions & 15 deletions src/game/client/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,7 @@ void CRenderTools::RenderTee7(const CAnimState *pAnim, const CTeeRenderInfo *pIn
SelectSprite7(client_data7::SPRITE_TEE_BOT_FOREGROUND);
Item = BotItem;
Graphics()->QuadsDraw(&Item, 1);
ColorRGBA Color = pInfo->m_aSixup[g_Config.m_ClDummy].m_BotColor;
Color.a = Alpha;
Graphics()->SetColor(Color);
Graphics()->SetColor(pInfo->m_aSixup[g_Config.m_ClDummy].m_BotColor.WithAlpha(Alpha));
SelectSprite7(client_data7::SPRITE_TEE_BOT_GLOW);
Item = BotItem;
Graphics()->QuadsDraw(&Item, 1);
Expand All @@ -338,9 +336,7 @@ void CRenderTools::RenderTee7(const CAnimState *pAnim, const CTeeRenderInfo *pIn
Graphics()->TextureSet(pInfo->m_aSixup[g_Config.m_ClDummy].m_aTextures[protocol7::SKINPART_DECORATION]);
Graphics()->QuadsBegin();
Graphics()->QuadsSetRotation(pAnim->GetBody()->m_Angle * pi * 2);
ColorRGBA Color = pInfo->m_aSixup[g_Config.m_ClDummy].m_aColors[protocol7::SKINPART_DECORATION];
Color.a = Alpha;
Graphics()->SetColor(Color);
Graphics()->SetColor(pInfo->m_aSixup[g_Config.m_ClDummy].m_aColors[protocol7::SKINPART_DECORATION].WithAlpha(Alpha));
SelectSprite7(OutLine ? client_data7::SPRITE_TEE_DECORATION_OUTLINE : client_data7::SPRITE_TEE_DECORATION);
Item = BodyItem;
Graphics()->QuadsDraw(&Item, 1);
Expand All @@ -358,9 +354,7 @@ void CRenderTools::RenderTee7(const CAnimState *pAnim, const CTeeRenderInfo *pIn
}
else
{
ColorRGBA Color = pInfo->m_aSixup[g_Config.m_ClDummy].m_aColors[protocol7::SKINPART_BODY];
Color.a = Alpha;
Graphics()->SetColor(Color);
Graphics()->SetColor(pInfo->m_aSixup[g_Config.m_ClDummy].m_aColors[protocol7::SKINPART_BODY].WithAlpha(Alpha));
SelectSprite7(client_data7::SPRITE_TEE_BODY);
}
Item = BodyItem;
Expand Down Expand Up @@ -403,16 +397,12 @@ void CRenderTools::RenderTee7(const CAnimState *pAnim, const CTeeRenderInfo *pIn
Graphics()->QuadsSetRotation(pAnim->GetBody()->m_Angle * pi * 2);
if(IsBot)
{
ColorRGBA Color = pInfo->m_aSixup[g_Config.m_ClDummy].m_BotColor;
Color.a = Alpha;
Graphics()->SetColor(Color);
Graphics()->SetColor(pInfo->m_aSixup[g_Config.m_ClDummy].m_BotColor.WithAlpha(Alpha));
Emote = EMOTE_SURPRISE;
}
else
{
ColorRGBA Color = pInfo->m_aSixup[g_Config.m_ClDummy].m_aColors[protocol7::SKINPART_EYES];
Color.a = Alpha;
Graphics()->SetColor(Color);
Graphics()->SetColor(pInfo->m_aSixup[g_Config.m_ClDummy].m_aColors[protocol7::SKINPART_EYES].WithAlpha(Alpha));
}
if(Pass == 1)
{
Expand Down

0 comments on commit 0ad732f

Please sign in to comment.