Implement 0.7 delete skin button

See #8750
This commit is contained in:
ChillerDragon 2024-08-18 10:11:53 +08:00
parent f057898ce0
commit 8d7c99fb96
4 changed files with 26 additions and 5 deletions

View file

@ -251,6 +251,7 @@ protected:
int m_TeePartSelected = protocol7::SKINPART_BODY;
const CSkins7::CSkin *m_pSelectedSkin = nullptr;
CLineInputBuffered<protocol7::MAX_SKIN_ARRAY_SIZE, protocol7::MAX_SKIN_LENGTH> m_SkinNameInput;
void PopupConfirmDeleteSkin7();
// for map download popup
int64_t m_DownloadLastCheckTime;

View file

@ -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 ^^

View file

@ -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()

View file

@ -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);