diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 8e95087f8c8..e5d75ef52d4 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -1815,7 +1815,7 @@ void CMenus::RenderPopupFullscreen(CUIRect Screen) if(m_pClient->m_Skins7.SaveSkinfile(m_SkinNameInput.GetString(), m_Dummy)) { m_Popup = POPUP_NONE; - m_SkinListNeedsUpdate = true; + m_SkinList7LastRefreshTime = std::nullopt; } else PopupMessage(Localize("Error"), Localize("Unable to save the skin"), Localize("Ok"), POPUP_SAVE_SKIN); diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index f8e4afccdc8..5b505864b0b 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -94,8 +95,10 @@ class CMenus : public CComponent void DoJoystickAxisPicker(CUIRect View); void DoJoystickBar(const CUIRect *pRect, float Current, float Tolerance, bool Active); - bool m_SkinListNeedsUpdate = false; + std::optional m_SkinListLastRefreshTime; bool m_SkinListScrollToSelected = false; + std::optional m_SkinList7LastRefreshTime; + std::optional m_SkinPartsList7LastRefreshTime; int m_DirectionQuadContainerIndex; @@ -668,7 +671,6 @@ class CMenus : public CComponent virtual void OnStateChange(int NewState, int OldState) override; virtual void OnWindowResize() override; - virtual void OnRefreshSkins() override; virtual void OnReset() override; virtual void OnRender() override; virtual bool OnInput(const IInput::CEvent &Event) override; diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index 13273bf6e9a..c5addbefdb6 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -401,11 +401,6 @@ struct CUISkin bool operator==(const char *pOther) const { return !str_comp_nocase(m_pSkin->GetName(), pOther); } }; -void CMenus::OnRefreshSkins() -{ - m_SkinListNeedsUpdate = true; -} - void CMenus::Con_AddFavoriteSkin(IConsole::IResult *pResult, void *pUserData) { auto *pSelf = (CMenus *)pUserData; @@ -713,10 +708,9 @@ void CMenus::RenderSettingsTee(CUIRect MainView) static CListBox s_ListBox; // be nice to the CPU - static std::chrono::nanoseconds s_SkinLastRefreshTime = m_pClient->m_Skins.LastRefreshTime(); - if(m_SkinListNeedsUpdate || m_SkinFavoritesChanged || s_SkinLastRefreshTime != m_pClient->m_Skins.LastRefreshTime()) + if(m_SkinFavoritesChanged || !m_SkinListLastRefreshTime.has_value() || m_SkinListLastRefreshTime.value() != m_pClient->m_Skins.LastRefreshTime()) { - s_SkinLastRefreshTime = m_pClient->m_Skins.LastRefreshTime(); + m_SkinListLastRefreshTime = m_pClient->m_Skins.LastRefreshTime(); s_vSkinList.clear(); s_vSkinListHelper.clear(); s_vFavoriteSkinListHelper.clear(); @@ -756,7 +750,6 @@ void CMenus::RenderSettingsTee(CUIRect MainView) std::sort(s_vFavoriteSkinListHelper.begin(), s_vFavoriteSkinListHelper.end()); s_vSkinList = s_vFavoriteSkinListHelper; s_vSkinList.insert(s_vSkinList.end(), s_vSkinListHelper.begin(), s_vSkinListHelper.end()); - m_SkinListNeedsUpdate = false; } int OldSelected = -1; @@ -820,7 +813,7 @@ void CMenus::RenderSettingsTee(CUIRect MainView) { m_SkinFavorites.emplace(pSkinToBeDraw->GetName()); } - m_SkinListNeedsUpdate = true; + m_SkinListLastRefreshTime = std::nullopt; } } } @@ -835,7 +828,7 @@ void CMenus::RenderSettingsTee(CUIRect MainView) static CLineInput s_SkinFilterInput(g_Config.m_ClSkinFilterString, sizeof(g_Config.m_ClSkinFilterString)); if(Ui()->DoEditBox_Search(&s_SkinFilterInput, &QuickSearch, 14.0f, !Ui()->IsPopupOpen() && m_pClient->m_GameConsole.IsClosed())) { - m_SkinListNeedsUpdate = true; + m_SkinListLastRefreshTime = std::nullopt; } static CButtonContainer s_SkinDatabaseButton; diff --git a/src/game/client/components/menus_settings7.cpp b/src/game/client/components/menus_settings7.cpp index 13c804d3669..9c5cf8751cd 100644 --- a/src/game/client/components/menus_settings7.cpp +++ b/src/game/client/components/menus_settings7.cpp @@ -207,8 +207,8 @@ void CMenus::RenderSettingsTee7(CUIRect MainView) static CLineInput s_SkinFilterInput(g_Config.m_ClSkinFilterString, sizeof(g_Config.m_ClSkinFilterString)); if(Ui()->DoEditBox_Search(&s_SkinFilterInput, &QuickSearch, 14.0f, !Ui()->IsPopupOpen() && m_pClient->m_GameConsole.IsClosed())) { - m_SkinListNeedsUpdate = true; - m_SkinPartListNeedsUpdate = true; + m_SkinList7LastRefreshTime = std::nullopt; + m_SkinPartsList7LastRefreshTime = std::nullopt; } static CButtonContainer s_DirectoryButton; @@ -317,14 +317,11 @@ void CMenus::RenderSkinSelection7(CUIRect MainView) static float s_LastSelectionTime = -10.0f; static std::vector s_vpSkinList; static CListBox s_ListBox; - static size_t s_SkinCount = 0; - const std::vector &vCurrentSkins = GameClient()->m_Skins7.GetSkins(); - if(m_SkinListNeedsUpdate || vCurrentSkins.size() != s_SkinCount) + if(!m_SkinList7LastRefreshTime.has_value() || m_SkinList7LastRefreshTime.value() != m_SkinList7LastRefreshTime) { s_vpSkinList.clear(); - s_SkinCount = vCurrentSkins.size(); - for(const CSkins7::CSkin &Skin : vCurrentSkins) + for(const CSkins7::CSkin &Skin : GameClient()->m_Skins7.GetSkins()) { if((Skin.m_Flags & CSkins7::SKINFLAG_SPECIAL) != 0) continue; @@ -333,7 +330,6 @@ void CMenus::RenderSkinSelection7(CUIRect MainView) s_vpSkinList.emplace_back(&Skin); } - m_SkinListNeedsUpdate = false; } m_pSelectedSkin = nullptr; @@ -405,15 +401,12 @@ void CMenus::RenderSkinPartSelection7(CUIRect MainView) { static std::vector s_paList[protocol7::NUM_SKINPARTS]; static CListBox s_ListBox; - static size_t s_aSkinPartCount[protocol7::NUM_SKINPARTS] = {0}; for(int Part = 0; Part < protocol7::NUM_SKINPARTS; Part++) { - const std::vector &vCurrentSkinParts = GameClient()->m_Skins7.GetSkinParts(Part); - if(m_SkinPartListNeedsUpdate || vCurrentSkinParts.size() != s_aSkinPartCount[Part]) + if(!m_SkinList7LastRefreshTime.has_value() || m_SkinList7LastRefreshTime.value() != GameClient()->m_Skins7.LastRefreshTime()) { s_paList[Part].clear(); - s_aSkinPartCount[Part] = vCurrentSkinParts.size(); - for(const CSkins7::CSkinPart &SkinPart : vCurrentSkinParts) + for(const CSkins7::CSkinPart &SkinPart : GameClient()->m_Skins7.GetSkinParts(Part)) { if((SkinPart.m_Flags & CSkins7::SKINFLAG_SPECIAL) != 0) continue; @@ -425,7 +418,6 @@ void CMenus::RenderSkinPartSelection7(CUIRect MainView) } } } - m_SkinPartListNeedsUpdate = false; static int s_OldSelected = -1; s_ListBox.DoBegin(&MainView); diff --git a/src/game/client/components/skins7.cpp b/src/game/client/components/skins7.cpp index 9287180f346..494c0f02ceb 100644 --- a/src/game/client/components/skins7.cpp +++ b/src/game/client/components/skins7.cpp @@ -307,6 +307,8 @@ void CSkins7::OnInit() LoadXmasHat(); LoadBotDecoration(); GameClient()->m_Menus.RenderLoading(Localize("Loading DDNet Client"), Localize("Loading skin files"), 0); + + m_LastRefreshTime = time_get_nanoseconds(); } void CSkins7::InitPlaceholderSkinParts() diff --git a/src/game/client/components/skins7.h b/src/game/client/components/skins7.h index 4f37630ea4a..54e3b3dcdda 100644 --- a/src/game/client/components/skins7.h +++ b/src/game/client/components/skins7.h @@ -13,6 +13,7 @@ #include #include +#include #include class CSkins7 : public CComponent @@ -66,6 +67,8 @@ class CSkins7 : public CComponent int Sizeof() const override { return sizeof(*this); } void OnInit() override; + std::chrono::nanoseconds LastRefreshTime() const { return m_LastRefreshTime; } + const std::vector &GetSkins() const; const std::vector &GetSkinParts(int Part) const; const CSkinPart *FindSkinPartOrNullptr(int Part, const char *pName, bool AllowSpecialPart) const; @@ -87,6 +90,7 @@ class CSkins7 : public CComponent private: int m_ScanningPart; + std::chrono::nanoseconds m_LastRefreshTime; std::vector m_avSkinParts[protocol7::NUM_SKINPARTS]; CSkinPart m_aPlaceholderSkinParts[protocol7::NUM_SKINPARTS];