Browse Source

netpackages

Laserlicht 1 month ago
parent
commit
66f377f14e

+ 7 - 0
client/CServerHandler.cpp

@@ -432,6 +432,13 @@ void CServerHandler::setCampaignBonus(int bonusId) const
 	sendLobbyPack(lscb);
 }
 
+void CServerHandler::setBattleOnlyModeStartInfo(std::shared_ptr<BattleOnlyModeStartInfo> startInfo) const
+{
+	LobbySetBattleOnlyModeStartInfo lsbomsui;
+	lsbomsui.startInfo = startInfo;
+	sendLobbyPack(lsbomsui);
+}
+
 void CServerHandler::setMapInfo(std::shared_ptr<CMapInfo> to, std::shared_ptr<CMapGenOptions> mapGenOpts) const
 {
 	LobbySetMap lsm;

+ 4 - 0
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<CampaignState> newCampaign) = 0;
 	virtual void setCampaignMap(CampaignScenarioID mapId) const = 0;
 	virtual void setCampaignBonus(int bonusId) const = 0;
+	virtual void setBattleOnlyModeStartInfo(std::shared_ptr<BattleOnlyModeStartInfo> startInfo) const = 0;
 	virtual void setMapInfo(std::shared_ptr<CMapInfo> to, std::shared_ptr<CMapGenOptions> 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<CampaignState> newCampaign) override;
 	void setCampaignMap(CampaignScenarioID mapId) const override;
 	void setCampaignBonus(int bonusId) const override;
+	void setBattleOnlyModeStartInfo(std::shared_ptr<BattleOnlyModeStartInfo> startInfo) const override;
 	void setMapInfo(std::shared_ptr<CMapInfo> to, std::shared_ptr<CMapGenOptions> mapGenOpts = {}) const override;
 	void setPlayer(PlayerColor color) const override;
 	void setPlayerName(PlayerColor color, const std::string & name) const override;

+ 1 - 0
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;
 };

+ 6 - 0
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<BattleOnlyModeWindow>())
+		topWindow->applyStartInfo(pack.startInfo);
+}

+ 12 - 11
client/lobby/BattleOnlyMode.cpp

@@ -62,17 +62,6 @@ void BattleOnlyMode::openBattleWindow()
 	ENGINE->windows().createAndPushWindow<BattleOnlyModeWindow>();
 }
 
-BattleOnlyModeStartInfo::BattleOnlyModeStartInfo()
-	: selectedTerrain(TerrainId::DIRT)
-	, selectedTown(FactionID::NONE)
-{
-	for(auto & element : selectedArmy)
-		element = std::make_shared<CCreatureSet>();
-	for(auto & element : primSkillLevel)
-		for(size_t i=0; i<GameConstants::PRIMARY_SKILLS; i++)
-			element[i] = 0;
-}
-
 BattleOnlyModeWindow::BattleOnlyModeWindow()
 	: CWindowObject(BORDERED)
 	, startInfo(std::make_shared<BattleOnlyModeStartInfo>())
@@ -191,6 +180,18 @@ void BattleOnlyModeWindow::init()
 	map->name = MetaString::createFromTextID("vcmi.lobby.battleOnlyMode");
 
 	cb = std::make_unique<EditorCallback>(map.get());
+
+	onChange();
+}
+
+void BattleOnlyModeWindow::onChange()
+{
+	GAME->server().setBattleOnlyModeStartInfo(startInfo);
+}
+
+void BattleOnlyModeWindow::applyStartInfo(std::shared_ptr<BattleOnlyModeStartInfo> si)
+{
+
 }
 
 void BattleOnlyModeWindow::setTerrainButtonText()

+ 3 - 14
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<std::shared_ptr<CGHeroInstance>, 2> selectedHero;
-	std::array<std::shared_ptr<CCreatureSet>, 2> selectedArmy;
-
-	std::array<std::array<int, GameConstants::PRIMARY_SKILLS>, 2> primSkillLevel;
-
-	BattleOnlyModeStartInfo();
-};
-
 class BattleOnlyModeHeroSelector : public CIntObject
 {
 private:
@@ -92,9 +79,11 @@ private:
 	std::shared_ptr<BattleOnlyModeHeroSelector> heroSelector2;
 
 	void init();
+	void onChange();
 	void setTerrainButtonText();
 	void setOkButtonEnabled();
 	void startBattle();
 public:
 	BattleOnlyModeWindow();
+	void applyStartInfo(std::shared_ptr<BattleOnlyModeStartInfo> si);
 };

+ 2 - 3
client/lobby/SelectionTab.cpp

@@ -242,13 +242,12 @@ SelectionTab::SelectionTab(ESelectionScreen Type)
 		sortByDate->setOverlay(std::make_shared<CPicture>(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<CButton>(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)

+ 12 - 0
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<CCreatureSet>();
+	for(auto & element : primSkillLevel)
+		for(size_t i=0; i<GameConstants::PRIMARY_SKILLS; i++)
+			element[i] = 0;
+}
+
 VCMI_LIB_NAMESPACE_END

+ 24 - 0
lib/StartInfo.h

@@ -25,6 +25,8 @@ VCMI_LIB_NAMESPACE_BEGIN
 class CMapGenOptions;
 class CampaignState;
 class CMapInfo;
+class CGHeroInstance;
+class CCreatureSet;
 struct PlayerInfo;
 class PlayerColor;
 
@@ -239,5 +241,27 @@ struct DLL_LINKAGE LobbyInfo : public LobbyState
 	TeamID getPlayerTeamId(const PlayerColor & color);
 };
 
+class DLL_LINKAGE BattleOnlyModeStartInfo : public Serializeable
+{
+public:
+	TerrainId selectedTerrain;
+	FactionID selectedTown;
+
+	std::array<std::shared_ptr<CGHeroInstance>, 2> selectedHero;
+	std::array<std::shared_ptr<CCreatureSet>, 2> selectedArmy;
+
+	std::array<std::array<int, GameConstants::PRIMARY_SKILLS>, 2> primSkillLevel;
+
+	BattleOnlyModeStartInfo();
+
+	template <typename Handler> void serialize(Handler &h)
+	{
+		h & selectedTerrain;
+		h & selectedTown;
+		h & selectedHero;
+		h & selectedArmy;
+		h & primSkillLevel;
+	}
+};
 
 VCMI_LIB_NAMESPACE_END

+ 1 - 0
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) {}

+ 5 - 0
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);

+ 12 - 0
lib/networkPacks/PacksForLobby.h

@@ -230,6 +230,18 @@ struct DLL_LINKAGE LobbySetCampaignBonus : public CLobbyPackToServer
 	}
 };
 
+struct DLL_LINKAGE LobbySetBattleOnlyModeStartInfo : public CLobbyPackToPropagate
+{
+	std::shared_ptr<BattleOnlyModeStartInfo> startInfo;
+
+	void visitTyped(ICPackVisitor & visitor) override;
+
+	template <typename Handler> 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};

+ 1 - 0
lib/serializer/RegisterTypes.h

@@ -291,6 +291,7 @@ void registerTypes(Serializer &s)
 	s.template registerType<TimesStackSizeUpdater>(249);
 	s.template registerType<TimesArmySizeUpdater>(250);
 	s.template registerType<PackageReceived>(251);
+	s.template registerType<LobbySetBattleOnlyModeStartInfo>(252);
 }
 
 VCMI_LIB_NAMESPACE_END