Skip to content

Commit

Permalink
Auto refresh skins when changing related settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Jupeyy committed Aug 20, 2022
1 parent 6a5d99d commit d1b8d53
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/game/client/components/menus.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ class CMenus : public CComponent

void RenderColorPicker();

void RefreshSkins();

// new gui with gui elements
template<typename T>
int DoButtonMenu(CUIElement &UIElement, const void *pID, T &&GetTextLambda, int Checked, const CUIRect *pRect, bool HintRequiresStringCheck, bool HintCanChangePositionOrSize = false, int Corners = IGraphics::CORNER_ALL, float r = 5.0f, float FontFactor = 0.0f, vec4 ColorHot = vec4(1.0f, 1.0f, 1.0f, 0.75f), vec4 Color = vec4(1, 1, 1, 0.5f), int AlignVertically = 1)
Expand Down
26 changes: 18 additions & 8 deletions src/game/client/components/menus_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,18 @@ struct CUISkin
bool operator==(const char *pOther) const { return !str_comp_nocase(m_pSkin->m_aName, pOther); }
};

void CMenus::RefreshSkins()
{
auto SkinStartLoadTime = time_get_nanoseconds();
m_pClient->m_Skins.Refresh([&](int) {
// if skin refreshing takes to long, swap to a loading screen
if(time_get_nanoseconds() - SkinStartLoadTime > 500ms)
{
RenderLoading(Localize("Loading skin files"), "", 0, false);
}
});
}

void CMenus::RenderSettingsTee(CUIRect MainView)
{
CUIRect Button, Label, Dummy, DummyLabel, SkinList, QuickSearch, QuickSearchClearButton, SkinDB, SkinPrefix, SkinPrefixLabel, DirectoryButton, RefreshButton, Eyes, EyesLabel, EyesTee, EyesRight;
Expand Down Expand Up @@ -470,20 +482,25 @@ void CMenus::RenderSettingsTee(CUIRect MainView)
if(DoButton_CheckBox(&g_Config.m_ClDownloadSkins, Localize("Download skins"), g_Config.m_ClDownloadSkins, &DummyLabel))
{
g_Config.m_ClDownloadSkins ^= 1;
RefreshSkins();
s_InitSkinlist = true;
}

Dummy.HSplitTop(20.0f, &DummyLabel, &Dummy);

if(DoButton_CheckBox(&g_Config.m_ClDownloadCommunitySkins, Localize("Download community skins"), g_Config.m_ClDownloadCommunitySkins, &DummyLabel))
{
g_Config.m_ClDownloadCommunitySkins ^= 1;
RefreshSkins();
s_InitSkinlist = true;
}

Dummy.HSplitTop(20.0f, &DummyLabel, &Dummy);

if(DoButton_CheckBox(&g_Config.m_ClVanillaSkinsOnly, Localize("Vanilla skins only"), g_Config.m_ClVanillaSkinsOnly, &DummyLabel))
{
g_Config.m_ClVanillaSkinsOnly ^= 1;
RefreshSkins();
s_InitSkinlist = true;
}

Expand Down Expand Up @@ -779,14 +796,7 @@ void CMenus::RenderSettingsTee(CUIRect MainView)
// reset render flags for possible loading screen
TextRender()->SetRenderFlags(0);
TextRender()->SetCurFont(NULL);
auto SkinStartLoadTime = time_get_nanoseconds();
m_pClient->m_Skins.Refresh([&](int) {
// if skin refreshing takes to long, swap to a loading screen
if(time_get_nanoseconds() - SkinStartLoadTime > 500ms)
{
RenderLoading(Localize("Loading skin files"), "", 0, false);
}
});
RefreshSkins();
s_InitSkinlist = true;
if(Client()->State() >= IClient::STATE_ONLINE)
{
Expand Down

0 comments on commit d1b8d53

Please sign in to comment.