mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-18 14:08:19 +00:00
Merge pull request #8987 from Robyt3/Client-Skins-Randomize-Function
Move `CMenus::RandomSkin` function to `CSkins::RandomizeSkin`
This commit is contained in:
commit
5407db0236
|
@ -95,7 +95,6 @@ class CMenus : public CComponent
|
|||
void DoJoystickBar(const CUIRect *pRect, float Current, float Tolerance, bool Active);
|
||||
|
||||
bool m_SkinListNeedsUpdate = false;
|
||||
void RandomSkin();
|
||||
|
||||
// menus_settings_assets.cpp
|
||||
public:
|
||||
|
|
|
@ -406,50 +406,6 @@ void CMenus::OnRefreshSkins()
|
|||
m_SkinListNeedsUpdate = true;
|
||||
}
|
||||
|
||||
void CMenus::RandomSkin()
|
||||
{
|
||||
static const float s_aSchemes[] = {1.0f / 2.0f, 1.0f / 3.0f, 1.0f / -3.0f, 1.0f / 12.0f, 1.0f / -12.0f}; // complementary, triadic, analogous
|
||||
const bool UseCustomColor = !m_Dummy ? g_Config.m_ClPlayerUseCustomColor : g_Config.m_ClDummyUseCustomColor;
|
||||
if(UseCustomColor)
|
||||
{
|
||||
float GoalSat = random_float(0.3f, 1.0f);
|
||||
float MaxBodyLht = 1.0f - GoalSat * GoalSat; // max allowed lightness before we start losing saturation
|
||||
|
||||
ColorHSLA Body;
|
||||
Body.h = random_float();
|
||||
Body.l = random_float(0.0f, MaxBodyLht);
|
||||
Body.s = clamp(GoalSat * GoalSat / (1.0f - Body.l), 0.0f, 1.0f);
|
||||
|
||||
ColorHSLA Feet;
|
||||
Feet.h = std::fmod(Body.h + s_aSchemes[rand() % std::size(s_aSchemes)], 1.0f);
|
||||
Feet.l = random_float();
|
||||
Feet.s = clamp(GoalSat * GoalSat / (1.0f - Feet.l), 0.0f, 1.0f);
|
||||
|
||||
unsigned *pColorBody = !m_Dummy ? &g_Config.m_ClPlayerColorBody : &g_Config.m_ClDummyColorBody;
|
||||
unsigned *pColorFeet = !m_Dummy ? &g_Config.m_ClPlayerColorFeet : &g_Config.m_ClDummyColorFeet;
|
||||
|
||||
*pColorBody = Body.Pack(false);
|
||||
*pColorFeet = Feet.Pack(false);
|
||||
}
|
||||
|
||||
const size_t SkinNameSize = !m_Dummy ? sizeof(g_Config.m_ClPlayerSkin) : sizeof(g_Config.m_ClDummySkin);
|
||||
char aRandomSkinName[24];
|
||||
str_copy(aRandomSkinName, "default", SkinNameSize);
|
||||
if(!m_pClient->m_Skins.GetSkinsUnsafe().empty())
|
||||
{
|
||||
do
|
||||
{
|
||||
auto it = m_pClient->m_Skins.GetSkinsUnsafe().begin();
|
||||
std::advance(it, rand() % m_pClient->m_Skins.GetSkinsUnsafe().size());
|
||||
str_copy(aRandomSkinName, (*it).second->GetName(), SkinNameSize);
|
||||
} while(!str_comp(aRandomSkinName, "x_ninja") || !str_comp(aRandomSkinName, "x_spec"));
|
||||
}
|
||||
char *pSkinName = !m_Dummy ? g_Config.m_ClPlayerSkin : g_Config.m_ClDummySkin;
|
||||
str_copy(pSkinName, aRandomSkinName, SkinNameSize);
|
||||
|
||||
SetNeedSendInfo();
|
||||
}
|
||||
|
||||
void CMenus::Con_AddFavoriteSkin(IConsole::IResult *pResult, void *pUserData)
|
||||
{
|
||||
auto *pSelf = (CMenus *)pUserData;
|
||||
|
@ -675,7 +631,8 @@ void CMenus::RenderSettingsTee(CUIRect MainView)
|
|||
TextRender()->SetRenderFlags(ETextRenderFlags::TEXT_RENDER_FLAG_ONLY_ADVANCE_WIDTH | ETextRenderFlags::TEXT_RENDER_FLAG_NO_X_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_Y_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_PIXEL_ALIGMENT | ETextRenderFlags::TEXT_RENDER_FLAG_NO_OVERSIZE);
|
||||
if(DoButton_Menu(&s_RandomSkinButton, s_apDice[s_CurrentDie], 0, &RandomSkinButton, nullptr, IGraphics::CORNER_ALL, 5.0f, -0.2f))
|
||||
{
|
||||
RandomSkin();
|
||||
GameClient()->m_Skins.RandomizeSkin(m_Dummy);
|
||||
SetNeedSendInfo();
|
||||
s_CurrentDie = rand() % std::size(s_apDice);
|
||||
}
|
||||
TextRender()->SetRenderFlags(0);
|
||||
|
|
|
@ -433,3 +433,45 @@ const CSkin *CSkins::FindImpl(const char *pName)
|
|||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void CSkins::RandomizeSkin(int Dummy)
|
||||
{
|
||||
static const float s_aSchemes[] = {1.0f / 2.0f, 1.0f / 3.0f, 1.0f / -3.0f, 1.0f / 12.0f, 1.0f / -12.0f}; // complementary, triadic, analogous
|
||||
const bool UseCustomColor = Dummy ? g_Config.m_ClDummyUseCustomColor : g_Config.m_ClPlayerUseCustomColor;
|
||||
if(UseCustomColor)
|
||||
{
|
||||
float GoalSat = random_float(0.3f, 1.0f);
|
||||
float MaxBodyLht = 1.0f - GoalSat * GoalSat; // max allowed lightness before we start losing saturation
|
||||
|
||||
ColorHSLA Body;
|
||||
Body.h = random_float();
|
||||
Body.l = random_float(0.0f, MaxBodyLht);
|
||||
Body.s = clamp(GoalSat * GoalSat / (1.0f - Body.l), 0.0f, 1.0f);
|
||||
|
||||
ColorHSLA Feet;
|
||||
Feet.h = std::fmod(Body.h + s_aSchemes[rand() % std::size(s_aSchemes)], 1.0f);
|
||||
Feet.l = random_float();
|
||||
Feet.s = clamp(GoalSat * GoalSat / (1.0f - Feet.l), 0.0f, 1.0f);
|
||||
|
||||
unsigned *pColorBody = Dummy ? &g_Config.m_ClDummyColorBody : &g_Config.m_ClPlayerColorBody;
|
||||
unsigned *pColorFeet = Dummy ? &g_Config.m_ClDummyColorFeet : &g_Config.m_ClPlayerColorFeet;
|
||||
|
||||
*pColorBody = Body.Pack(false);
|
||||
*pColorFeet = Feet.Pack(false);
|
||||
}
|
||||
|
||||
const size_t SkinNameSize = Dummy ? sizeof(g_Config.m_ClDummySkin) : sizeof(g_Config.m_ClPlayerSkin);
|
||||
char aRandomSkinName[24];
|
||||
str_copy(aRandomSkinName, "default", SkinNameSize);
|
||||
if(!m_pClient->m_Skins.GetSkinsUnsafe().empty())
|
||||
{
|
||||
do
|
||||
{
|
||||
auto it = m_pClient->m_Skins.GetSkinsUnsafe().begin();
|
||||
std::advance(it, rand() % m_pClient->m_Skins.GetSkinsUnsafe().size());
|
||||
str_copy(aRandomSkinName, (*it).second->GetName(), SkinNameSize);
|
||||
} while(!str_comp(aRandomSkinName, "x_ninja") || !str_comp(aRandomSkinName, "x_spec"));
|
||||
}
|
||||
char *pSkinName = Dummy ? g_Config.m_ClDummySkin : g_Config.m_ClPlayerSkin;
|
||||
str_copy(pSkinName, aRandomSkinName, SkinNameSize);
|
||||
}
|
||||
|
|
|
@ -66,6 +66,7 @@ public:
|
|||
std::unordered_map<std::string_view, std::unique_ptr<CSkin>> &GetSkinsUnsafe() { return m_Skins; }
|
||||
const CSkin *FindOrNullptr(const char *pName, bool IgnorePrefix = false);
|
||||
const CSkin *Find(const char *pName);
|
||||
void RandomizeSkin(int Dummy);
|
||||
|
||||
bool IsDownloadingSkins() { return m_DownloadingSkins; }
|
||||
|
||||
|
|
Loading…
Reference in a new issue