From 66f377f14ee15ccab8cc8e5e0101a68f62574828 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sat, 25 Oct 2025 20:41:39 +0200 Subject: [PATCH] netpackages --- client/CServerHandler.cpp | 7 +++++++ client/CServerHandler.h | 4 ++++ client/LobbyClientNetPackVisitors.h | 1 + client/NetPacksLobbyClient.cpp | 6 ++++++ client/lobby/BattleOnlyMode.cpp | 23 ++++++++++++----------- client/lobby/BattleOnlyMode.h | 17 +++-------------- client/lobby/SelectionTab.cpp | 5 ++--- lib/StartInfo.cpp | 12 ++++++++++++ lib/StartInfo.h | 24 ++++++++++++++++++++++++ lib/networkPacks/NetPackVisitor.h | 1 + lib/networkPacks/NetPacksLib.cpp | 5 +++++ lib/networkPacks/PacksForLobby.h | 12 ++++++++++++ lib/serializer/RegisterTypes.h | 1 + 13 files changed, 90 insertions(+), 28 deletions(-) diff --git a/client/CServerHandler.cpp b/client/CServerHandler.cpp index cb80f843d..0011c22b8 100644 --- a/client/CServerHandler.cpp +++ b/client/CServerHandler.cpp @@ -432,6 +432,13 @@ void CServerHandler::setCampaignBonus(int bonusId) const sendLobbyPack(lscb); } +void CServerHandler::setBattleOnlyModeStartInfo(std::shared_ptr startInfo) const +{ + LobbySetBattleOnlyModeStartInfo lsbomsui; + lsbomsui.startInfo = startInfo; + sendLobbyPack(lsbomsui); +} + void CServerHandler::setMapInfo(std::shared_ptr to, std::shared_ptr mapGenOpts) const { LobbySetMap lsm; diff --git a/client/CServerHandler.h b/client/CServerHandler.h index 4cfdd52a1..db4192d80 100644 --- a/client/CServerHandler.h +++ b/client/CServerHandler.h @@ -15,6 +15,8 @@ #include "../lib/StartInfo.h" #include "../lib/gameState/GameStatistics.h" +#include "lobby/BattleOnlyMode.h" + VCMI_LIB_NAMESPACE_BEGIN class GameConnection; @@ -77,6 +79,7 @@ public: virtual void setCampaignState(std::shared_ptr newCampaign) = 0; virtual void setCampaignMap(CampaignScenarioID mapId) const = 0; virtual void setCampaignBonus(int bonusId) const = 0; + virtual void setBattleOnlyModeStartInfo(std::shared_ptr startInfo) const = 0; virtual void setMapInfo(std::shared_ptr to, std::shared_ptr mapGenOpts = {}) const = 0; virtual void setPlayer(PlayerColor color) const = 0; virtual void setPlayerName(PlayerColor color, const std::string & name) const = 0; @@ -186,6 +189,7 @@ public: void setCampaignState(std::shared_ptr newCampaign) override; void setCampaignMap(CampaignScenarioID mapId) const override; void setCampaignBonus(int bonusId) const override; + void setBattleOnlyModeStartInfo(std::shared_ptr startInfo) const override; void setMapInfo(std::shared_ptr to, std::shared_ptr mapGenOpts = {}) const override; void setPlayer(PlayerColor color) const override; void setPlayerName(PlayerColor color, const std::string & name) const override; diff --git a/client/LobbyClientNetPackVisitors.h b/client/LobbyClientNetPackVisitors.h index b3996cce7..2639b44ca 100644 --- a/client/LobbyClientNetPackVisitors.h +++ b/client/LobbyClientNetPackVisitors.h @@ -59,4 +59,5 @@ public: void visitLobbyLoadProgress(LobbyLoadProgress & pack) override; void visitLobbyUpdateState(LobbyUpdateState & pack) override; void visitLobbyShowMessage(LobbyShowMessage & pack) override; + void visitLobbySetBattleOnlyModeStartInfo(LobbySetBattleOnlyModeStartInfo & pack) override; }; diff --git a/client/NetPacksLobbyClient.cpp b/client/NetPacksLobbyClient.cpp index 7d1a3b135..f286af001 100644 --- a/client/NetPacksLobbyClient.cpp +++ b/client/NetPacksLobbyClient.cpp @@ -239,3 +239,9 @@ void ApplyOnLobbyScreenNetPackVisitor::visitLobbyShowMessage(LobbyShowMessage & lobby->buttonStart->block(false); handler.showServerError(pack.message.toString()); } + +void ApplyOnLobbyScreenNetPackVisitor::visitLobbySetBattleOnlyModeStartInfo(LobbySetBattleOnlyModeStartInfo & pack) +{ + if(auto topWindow = ENGINE->windows().topWindow()) + topWindow->applyStartInfo(pack.startInfo); +} diff --git a/client/lobby/BattleOnlyMode.cpp b/client/lobby/BattleOnlyMode.cpp index 804f30bde..50601766d 100644 --- a/client/lobby/BattleOnlyMode.cpp +++ b/client/lobby/BattleOnlyMode.cpp @@ -62,17 +62,6 @@ void BattleOnlyMode::openBattleWindow() ENGINE->windows().createAndPushWindow(); } -BattleOnlyModeStartInfo::BattleOnlyModeStartInfo() - : selectedTerrain(TerrainId::DIRT) - , selectedTown(FactionID::NONE) -{ - for(auto & element : selectedArmy) - element = std::make_shared(); - for(auto & element : primSkillLevel) - for(size_t i=0; i()) @@ -191,6 +180,18 @@ void BattleOnlyModeWindow::init() map->name = MetaString::createFromTextID("vcmi.lobby.battleOnlyMode"); cb = std::make_unique(map.get()); + + onChange(); +} + +void BattleOnlyModeWindow::onChange() +{ + GAME->server().setBattleOnlyModeStartInfo(startInfo); +} + +void BattleOnlyModeWindow::applyStartInfo(std::shared_ptr si) +{ + } void BattleOnlyModeWindow::setTerrainButtonText() diff --git a/client/lobby/BattleOnlyMode.h b/client/lobby/BattleOnlyMode.h index 27dc84f05..5003ed4c4 100644 --- a/client/lobby/BattleOnlyMode.h +++ b/client/lobby/BattleOnlyMode.h @@ -18,6 +18,7 @@ class CGHeroInstance; class CCreatureSet; class CMap; class EditorCallback; +class BattleOnlyModeStartInfo; VCMI_LIB_NAMESPACE_END class FilledTexturePlayerColored; @@ -36,20 +37,6 @@ public: static void openBattleWindow(); }; -class BattleOnlyModeStartInfo -{ -public: - TerrainId selectedTerrain; - FactionID selectedTown; - - std::array, 2> selectedHero; - std::array, 2> selectedArmy; - - std::array, 2> primSkillLevel; - - BattleOnlyModeStartInfo(); -}; - class BattleOnlyModeHeroSelector : public CIntObject { private: @@ -92,9 +79,11 @@ private: std::shared_ptr heroSelector2; void init(); + void onChange(); void setTerrainButtonText(); void setOkButtonEnabled(); void startBattle(); public: BattleOnlyModeWindow(); + void applyStartInfo(std::shared_ptr si); }; diff --git a/client/lobby/SelectionTab.cpp b/client/lobby/SelectionTab.cpp index bf49be74f..40b53cd6f 100644 --- a/client/lobby/SelectionTab.cpp +++ b/client/lobby/SelectionTab.cpp @@ -242,13 +242,12 @@ SelectionTab::SelectionTab(ESelectionScreen Type) sortByDate->setOverlay(std::make_shared(ImagePath::builtin("lobby/selectionTabSortDate"))); buttonsSortBy.push_back(sortByDate); - bool isMultiplayer = GAME->server().loadMode == ELoadMode::MULTI; - - if(tabType == ESelectionScreen::newGame && !isMultiplayer) + if(tabType == ESelectionScreen::newGame) { buttonBattleOnlyMode = std::make_shared(Point(23, 18), AnimationPath::builtin("lobby/battleButton"), CButton::tooltip("", LIBRARY->generaltexth->translate("vcmi.lobby.battleOnlyMode")), [tabTitle, tabTitleDelete](){ BattleOnlyMode::openBattleWindow(); }); + //buttonBattleOnlyMode->block(GAME->server().isGuest()); } if(tabType == ESelectionScreen::loadGame || tabType == ESelectionScreen::newGame) diff --git a/lib/StartInfo.cpp b/lib/StartInfo.cpp index bcc272dcf..eb2440047 100644 --- a/lib/StartInfo.cpp +++ b/lib/StartInfo.cpp @@ -21,6 +21,7 @@ #include "mapping/CMapHeader.h" #include "mapping/CMapService.h" #include "modding/ModIncompatibility.h" +#include "mapObjects/army/CCreatureSet.h" VCMI_LIB_NAMESPACE_BEGIN @@ -241,4 +242,15 @@ TeamID LobbyInfo::getPlayerTeamId(const PlayerColor & color) return TeamID::NO_TEAM; } +BattleOnlyModeStartInfo::BattleOnlyModeStartInfo() + : selectedTerrain(TerrainId::DIRT) + , selectedTown(FactionID::NONE) +{ + for(auto & element : selectedArmy) + element = std::make_shared(); + for(auto & element : primSkillLevel) + for(size_t i=0; i, 2> selectedHero; + std::array, 2> selectedArmy; + + std::array, 2> primSkillLevel; + + BattleOnlyModeStartInfo(); + + template void serialize(Handler &h) + { + h & selectedTerrain; + h & selectedTown; + h & selectedHero; + h & selectedArmy; + h & primSkillLevel; + } +}; VCMI_LIB_NAMESPACE_END diff --git a/lib/networkPacks/NetPackVisitor.h b/lib/networkPacks/NetPackVisitor.h index eef61f439..3edd0d290 100644 --- a/lib/networkPacks/NetPackVisitor.h +++ b/lib/networkPacks/NetPackVisitor.h @@ -168,6 +168,7 @@ public: virtual void visitLobbySetCampaign(LobbySetCampaign & pack) {} virtual void visitLobbySetCampaignMap(LobbySetCampaignMap & pack) {} virtual void visitLobbySetCampaignBonus(LobbySetCampaignBonus & pack) {} + virtual void visitLobbySetBattleOnlyModeStartInfo(LobbySetBattleOnlyModeStartInfo & pack) {} virtual void visitLobbyChangePlayerOption(LobbyChangePlayerOption & pack) {} virtual void visitLobbySetPlayer(LobbySetPlayer & pack) {} virtual void visitLobbySetPlayerName(LobbySetPlayerName & pack) {} diff --git a/lib/networkPacks/NetPacksLib.cpp b/lib/networkPacks/NetPacksLib.cpp index 5d7c08477..629260eff 100644 --- a/lib/networkPacks/NetPacksLib.cpp +++ b/lib/networkPacks/NetPacksLib.cpp @@ -763,6 +763,11 @@ void LobbySetCampaignBonus::visitTyped(ICPackVisitor & visitor) visitor.visitLobbySetCampaignBonus(*this); } +void LobbySetBattleOnlyModeStartInfo::visitTyped(ICPackVisitor & visitor) +{ + visitor.visitLobbySetBattleOnlyModeStartInfo(*this); +} + void LobbyChangePlayerOption::visitTyped(ICPackVisitor & visitor) { visitor.visitLobbyChangePlayerOption(*this); diff --git a/lib/networkPacks/PacksForLobby.h b/lib/networkPacks/PacksForLobby.h index d0e0bb827..0878ff7d6 100644 --- a/lib/networkPacks/PacksForLobby.h +++ b/lib/networkPacks/PacksForLobby.h @@ -230,6 +230,18 @@ struct DLL_LINKAGE LobbySetCampaignBonus : public CLobbyPackToServer } }; +struct DLL_LINKAGE LobbySetBattleOnlyModeStartInfo : public CLobbyPackToPropagate +{ + std::shared_ptr startInfo; + + void visitTyped(ICPackVisitor & visitor) override; + + template void serialize(Handler &h) + { + h & startInfo; + } +}; + struct DLL_LINKAGE LobbyChangePlayerOption : public CLobbyPackToServer { enum EWhat : ui8 {UNKNOWN, TOWN, HERO, BONUS, TOWN_ID, HERO_ID, BONUS_ID}; diff --git a/lib/serializer/RegisterTypes.h b/lib/serializer/RegisterTypes.h index 22a4c7508..7f02132d8 100644 --- a/lib/serializer/RegisterTypes.h +++ b/lib/serializer/RegisterTypes.h @@ -291,6 +291,7 @@ void registerTypes(Serializer &s) s.template registerType(249); s.template registerType(250); s.template registerType(251); + s.template registerType(252); } VCMI_LIB_NAMESPACE_END