diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index 1064aca7c..1a16bfa56 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -251,6 +251,7 @@ protected: int m_TeePartSelected = protocol7::SKINPART_BODY; const CSkins7::CSkin *m_pSelectedSkin = nullptr; CLineInputBuffered m_SkinNameInput; + void PopupConfirmDeleteSkin7(); // for map download popup int64_t m_DownloadLastCheckTime; diff --git a/src/game/client/components/menus_settings7.cpp b/src/game/client/components/menus_settings7.cpp index d077e3aff..aedeeb0aa 100644 --- a/src/game/client/components/menus_settings7.cpp +++ b/src/game/client/components/menus_settings7.cpp @@ -249,9 +249,9 @@ void CMenus::RenderSettingsTee7(CUIRect MainView) static CButtonContainer s_CustomSkinDeleteButton; if(DoButton_Menu(&s_CustomSkinDeleteButton, Localize("Delete"), 0, &ButtonMiddle)) { - // char aBuf[128]; - // str_format(aBuf, sizeof(aBuf), Localize("Are you sure that you want to delete the skin '%s'?"), m_pSelectedSkin->m_aName); - // PopupConfirm(Localize("Delete skin"), aBuf, Localize("Yes"), Localize("No"), &CMenus::PopupConfirmDeleteSkin); + char aBuf[128]; + str_format(aBuf, sizeof(aBuf), Localize("Are you sure that you want to delete the skin '%s'?"), m_pSelectedSkin->m_aName); + PopupConfirm(Localize("Delete skin"), aBuf, Localize("Yes"), Localize("No"), &CMenus::PopupConfirmDeleteSkin7); } } @@ -292,6 +292,18 @@ void CMenus::RenderSettingsTee7(CUIRect MainView) } } +void CMenus::PopupConfirmDeleteSkin7() +{ + dbg_assert(m_pSelectedSkin, "no skin selected for deletion"); + + if(!m_pClient->m_Skins7.RemoveSkin(m_pSelectedSkin)) + { + PopupMessage(Localize("Error"), Localize("Unable to delete the skin"), Localize("Ok")); + return; + } + m_pSelectedSkin = nullptr; +} + void CMenus::RenderSettingsTeeBasic7(CUIRect MainView) { RenderSkinSelection7(MainView); // yes thats all here ^^ diff --git a/src/game/client/components/skins7.cpp b/src/game/client/components/skins7.cpp index a1cae75fb..06c12c964 100644 --- a/src/game/client/components/skins7.cpp +++ b/src/game/client/components/skins7.cpp @@ -395,10 +395,18 @@ void CSkins7::AddSkin(const char *pSkinName, int Dummy) m_vSkins.emplace_back(Skin); } -void CSkins7::RemoveSkin(const CSkin *pSkin) +bool CSkins7::RemoveSkin(const CSkin *pSkin) { + char aBuf[IO_MAX_PATH_LENGTH]; + str_format(aBuf, sizeof(aBuf), SKINS_DIR "/%s.json", pSkin->m_aName); + if(!Storage()->RemoveFile(aBuf, IStorage::TYPE_SAVE)) + { + return false; + } + auto Position = std::find(m_vSkins.begin(), m_vSkins.end(), *pSkin); m_vSkins.erase(Position); + return true; } int CSkins7::Num() diff --git a/src/game/client/components/skins7.h b/src/game/client/components/skins7.h index 49c06ad82..569c36602 100644 --- a/src/game/client/components/skins7.h +++ b/src/game/client/components/skins7.h @@ -64,7 +64,7 @@ public: void OnInit() override; void AddSkin(const char *pSkinName, int Dummy); - void RemoveSkin(const CSkin *pSkin); + bool RemoveSkin(const CSkin *pSkin); int Num(); int NumSkinPart(int Part);