From 164aac4db2f8a679791f190b0f83fd68bc1aa9ed Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Fri, 1 Nov 2024 00:52:19 +0100 Subject: [PATCH] refresh list --- client/NetPacksLobbyClient.cpp | 2 +- client/lobby/SelectionTab.cpp | 12 ++++++++++-- lib/networkPacks/PacksForLobby.h | 3 +++ lib/serializer/ESerializationVersion.h | 3 ++- server/NetPacksLobbyServer.cpp | 9 +++++++-- 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/client/NetPacksLobbyClient.cpp b/client/NetPacksLobbyClient.cpp index 4689d8d57..49c86f11d 100644 --- a/client/NetPacksLobbyClient.cpp +++ b/client/NetPacksLobbyClient.cpp @@ -226,7 +226,7 @@ void ApplyOnLobbyScreenNetPackVisitor::visitLobbyUpdateState(LobbyUpdateState & else lobby->updateAfterStateChange(); - if(pack.hostChanged) + if(pack.hostChanged || pack.refreshList) lobby->toggleMode(handler.isHost()); } diff --git a/client/lobby/SelectionTab.cpp b/client/lobby/SelectionTab.cpp index 646753de2..a8e1a273d 100644 --- a/client/lobby/SelectionTab.cpp +++ b/client/lobby/SelectionTab.cpp @@ -262,10 +262,10 @@ SelectionTab::SelectionTab(ESelectionScreen Type) void SelectionTab::toggleMode() { + allItems.clear(); + curItems.clear(); if(CSH->isGuest()) { - allItems.clear(); - curItems.clear(); if(slider) slider->block(true); } @@ -344,6 +344,14 @@ void SelectionTab::clickReleased(const Point & cursorPosition) } std::cout << (curItems[py]->isFolder ? curItems[py]->folderName : curItems[py]->fullFileURI) << "\n"; + + if(!curItems[py]->isFolder) + CInfoWindow::showYesNoDialog(CGI->generaltexth->translate("vcmi.lobby.deleteFile") + "\n\n" + curItems[py]->fullFileURI, std::vector>(), [this, py](){ + LobbyDelete ld; + ld.type = tabType == ESelectionScreen::newGame ? LobbyDelete::RANDOMMAP : LobbyDelete::SAVEGAME; + ld.name = curItems[py]->fileURI; + CSH->sendLobbyPack(ld); + }, nullptr); } } #ifdef VCMI_MOBILE diff --git a/lib/networkPacks/PacksForLobby.h b/lib/networkPacks/PacksForLobby.h index 7fafbae9d..8f16a80af 100644 --- a/lib/networkPacks/PacksForLobby.h +++ b/lib/networkPacks/PacksForLobby.h @@ -170,12 +170,15 @@ struct DLL_LINKAGE LobbyUpdateState : public CLobbyPackToPropagate { LobbyState state; bool hostChanged = false; // Used on client-side only + bool refreshList = false; void visitTyped(ICPackVisitor & visitor) override; template void serialize(Handler &h) { h & state; + if (h.version >= Handler::Version::LOBBY_DELETE) + h & refreshList; } }; diff --git a/lib/serializer/ESerializationVersion.h b/lib/serializer/ESerializationVersion.h index 7b4270bc9..7ef4a4f39 100644 --- a/lib/serializer/ESerializationVersion.h +++ b/lib/serializer/ESerializationVersion.h @@ -65,6 +65,7 @@ enum class ESerializationVersion : int32_t LOCAL_PLAYER_STATE_DATA, // 866 - player state contains arbitrary client-side data REMOVE_TOWN_PTR, // 867 - removed pointer to CTown from CGTownInstance REMOVE_OBJECT_TYPENAME, // 868 - remove typename from CGObjectInstance + LOBBY_DELETE, // 869 - possibility to delete savegames and random maps - CURRENT = REMOVE_OBJECT_TYPENAME + CURRENT = LOBBY_DELETE }; diff --git a/server/NetPacksLobbyServer.cpp b/server/NetPacksLobbyServer.cpp index 7ed190236..c9458e50e 100644 --- a/server/NetPacksLobbyServer.cpp +++ b/server/NetPacksLobbyServer.cpp @@ -442,10 +442,15 @@ void ClientPermissionsCheckerNetPackVisitor::visitLobbyDelete(LobbyDelete & pack void ApplyOnServerNetPackVisitor::visitLobbyDelete(LobbyDelete & pack) { - if(pack.type == LobbyDelete::SAVEGAME) + if(pack.type == LobbyDelete::SAVEGAME || pack.type == LobbyDelete::RANDOMMAP) { - auto res = ResourcePath(pack.name, EResType::SAVEGAME); + auto res = ResourcePath(pack.name, pack.type == LobbyDelete::SAVEGAME ? EResType::SAVEGAME : EResType::MAP); auto file = boost::filesystem::canonical(*CResourceHandler::get()->getResourceName(res)); boost::filesystem::remove(file); } + + LobbyUpdateState lus; + lus.state = srv; + lus.refreshList = true; + srv.announcePack(lus); }