1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

campaignset

This commit is contained in:
Laserlicht 2023-09-20 03:13:54 +02:00 committed by GitHub
parent 7b37c2353a
commit 34182069f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 19 deletions

View File

@ -689,6 +689,8 @@ void CServerHandler::startCampaignScenario(std::shared_ptr<CampaignState> cs)
GH.windows().pushWindow(CMM->menu); GH.windows().pushWindow(CMM->menu);
CMM->openCampaignLobby(ourCampaign); CMM->openCampaignLobby(ourCampaign);
} }
else
CMM->openCampaignScreen(ourCampaign->campaignSet);
}; };
if(epilogue.hasPrologEpilog) if(epilogue.hasPrologEpilog)
{ {

View File

@ -47,12 +47,12 @@
#include "../../lib/mapObjects/CGHeroInstance.h" #include "../../lib/mapObjects/CGHeroInstance.h"
CCampaignScreen::CCampaignScreen(const JsonNode & config) CCampaignScreen::CCampaignScreen(const JsonNode & config, std::string name)
: CWindowObject(BORDERED) : CWindowObject(BORDERED), campaignSet(name)
{ {
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE; OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
for(const JsonNode & node : config["images"].Vector()) for(const JsonNode & node : config[name]["images"].Vector())
images.push_back(CMainMenu::createPicture(node)); images.push_back(CMainMenu::createPicture(node));
if(!images.empty()) if(!images.empty())
@ -63,14 +63,14 @@ CCampaignScreen::CCampaignScreen(const JsonNode & config)
pos = images[0]->pos; // fix height\width of this window pos = images[0]->pos; // fix height\width of this window
} }
if(!config["exitbutton"].isNull()) if(!config[name]["exitbutton"].isNull())
{ {
buttonBack = createExitButton(config["exitbutton"]); buttonBack = createExitButton(config[name]["exitbutton"]);
buttonBack->hoverable = true; buttonBack->hoverable = true;
} }
for(const JsonNode & node : config["items"].Vector()) for(const JsonNode & node : config[name]["items"].Vector())
campButtons.push_back(std::make_shared<CCampaignButton>(node)); campButtons.push_back(std::make_shared<CCampaignButton>(node, campaignSet));
} }
void CCampaignScreen::activate() void CCampaignScreen::activate()
@ -89,7 +89,8 @@ std::shared_ptr<CButton> CCampaignScreen::createExitButton(const JsonNode & butt
return std::make_shared<CButton>(Point((int)button["x"].Float(), (int)button["y"].Float()), AnimationPath::fromJson(button["name"]), help, [=](){ close();}, EShortcut::GLOBAL_CANCEL); return std::make_shared<CButton>(Point((int)button["x"].Float(), (int)button["y"].Float()), AnimationPath::fromJson(button["name"]), help, [=](){ close();}, EShortcut::GLOBAL_CANCEL);
} }
CCampaignScreen::CCampaignButton::CCampaignButton(const JsonNode & config) CCampaignScreen::CCampaignButton::CCampaignButton(const JsonNode & config, std::string set)
: set(set)
{ {
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE; OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
@ -134,7 +135,7 @@ void CCampaignScreen::CCampaignButton::show(Canvas & to)
void CCampaignScreen::CCampaignButton::clickReleased(const Point & cursorPosition) void CCampaignScreen::CCampaignButton::clickReleased(const Point & cursorPosition)
{ {
CCS->videoh->close(); CCS->videoh->close();
CMainMenu::openCampaignLobby(campFile); CMainMenu::openCampaignLobby(campFile, set);
} }
void CCampaignScreen::CCampaignButton::hover(bool on) void CCampaignScreen::CCampaignButton::hover(bool on)

View File

@ -40,14 +40,18 @@ private:
VideoPath video; // the resource name of the video VideoPath video; // the resource name of the video
std::string hoverText; std::string hoverText;
std::string set;
void clickReleased(const Point & cursorPosition) override; void clickReleased(const Point & cursorPosition) override;
void hover(bool on) override; void hover(bool on) override;
public: public:
CCampaignButton(const JsonNode & config); CCampaignButton(const JsonNode & config, std::string set);
void show(Canvas & to) override; void show(Canvas & to) override;
}; };
std::string campaignSet;
std::vector<std::shared_ptr<CCampaignButton>> campButtons; std::vector<std::shared_ptr<CCampaignButton>> campButtons;
std::vector<std::shared_ptr<CPicture>> images; std::vector<std::shared_ptr<CPicture>> images;
std::shared_ptr<CButton> buttonBack; std::shared_ptr<CButton> buttonBack;
@ -55,9 +59,7 @@ private:
std::shared_ptr<CButton> createExitButton(const JsonNode & button); std::shared_ptr<CButton> createExitButton(const JsonNode & button);
public: public:
enum CampaignSet {ROE, AB, SOD, WOG}; CCampaignScreen(const JsonNode & config, std::string name);
CCampaignScreen(const JsonNode & config);
void activate() override; void activate() override;
}; };

View File

@ -349,14 +349,16 @@ void CMainMenu::openLobby(ESelectionScreen screenType, bool host, const std::vec
GH.windows().createAndPushWindow<CSimpleJoinScreen>(host); GH.windows().createAndPushWindow<CSimpleJoinScreen>(host);
} }
void CMainMenu::openCampaignLobby(const std::string & campaignFileName) void CMainMenu::openCampaignLobby(const std::string & campaignFileName, std::string campaignSet)
{ {
auto ourCampaign = CampaignHandler::getCampaign(campaignFileName); auto ourCampaign = CampaignHandler::getCampaign(campaignFileName);
openCampaignLobby(ourCampaign); openCampaignLobby(ourCampaign, campaignSet);
} }
void CMainMenu::openCampaignLobby(std::shared_ptr<CampaignState> campaign) void CMainMenu::openCampaignLobby(std::shared_ptr<CampaignState> campaign, std::string campaignSet)
{ {
campaign->campaignSet = campaignSet;
CSH->resetStateForLobby(StartInfo::CAMPAIGN); CSH->resetStateForLobby(StartInfo::CAMPAIGN);
CSH->screenType = ESelectionScreen::campaignList; CSH->screenType = ESelectionScreen::campaignList;
CSH->campaignStateToSend = campaign; CSH->campaignStateToSend = campaign;
@ -367,7 +369,7 @@ void CMainMenu::openCampaignScreen(std::string name)
{ {
if(vstd::contains(CMainMenuConfig::get().getCampaigns().Struct(), name)) if(vstd::contains(CMainMenuConfig::get().getCampaigns().Struct(), name))
{ {
GH.windows().createAndPushWindow<CCampaignScreen>(CMainMenuConfig::get().getCampaigns()[name]); GH.windows().createAndPushWindow<CCampaignScreen>(CMainMenuConfig::get().getCampaigns(), name);
return; return;
} }
logGlobal->error("Unknown campaign set: %s", name); logGlobal->error("Unknown campaign set: %s", name);

View File

@ -149,8 +149,8 @@ public:
void onScreenResize() override; void onScreenResize() override;
void update() override; void update() override;
static void openLobby(ESelectionScreen screenType, bool host, const std::vector<std::string> * names, ELoadMode loadMode); static void openLobby(ESelectionScreen screenType, bool host, const std::vector<std::string> * names, ELoadMode loadMode);
static void openCampaignLobby(const std::string & campaignFileName); static void openCampaignLobby(const std::string & campaignFileName, std::string campaignSet = "");
static void openCampaignLobby(std::shared_ptr<CampaignState> campaign); static void openCampaignLobby(std::shared_ptr<CampaignState> campaign, std::string campaignSet = "");
static void startTutorial(); static void startTutorial();
void openCampaignScreen(std::string name); void openCampaignScreen(std::string name);

View File

@ -293,6 +293,8 @@ public:
static JsonNode crossoverSerialize(CGHeroInstance * hero); static JsonNode crossoverSerialize(CGHeroInstance * hero);
static CGHeroInstance * crossoverDeserialize(const JsonNode & node, CMap * map); static CGHeroInstance * crossoverDeserialize(const JsonNode & node, CMap * map);
std::string campaignSet = "";
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
h & static_cast<Campaign&>(*this); h & static_cast<Campaign&>(*this);
@ -302,6 +304,7 @@ public:
h & mapsConquered; h & mapsConquered;
h & currentMap; h & currentMap;
h & chosenCampaignBonuses; h & chosenCampaignBonuses;
h & campaignSet;
} }
}; };