From 46872b764b2c25b91800139a4e65d2c35511119a Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sat, 31 Aug 2024 17:57:27 +0200 Subject: [PATCH] integrate campaign intro --- client/NetPacksLobbyClient.cpp | 4 ++-- client/lobby/CBonusSelection.cpp | 21 ++++++++++++++++++++- client/lobby/CBonusSelection.h | 5 +++++ config/campaignOverrides.json | 4 +++- docs/modders/Campaign_Format.md | 2 ++ lib/campaign/CampaignHandler.cpp | 2 ++ lib/campaign/CampaignState.cpp | 14 ++++++++++++++ lib/campaign/CampaignState.h | 6 ++++++ 8 files changed, 54 insertions(+), 4 deletions(-) diff --git a/client/NetPacksLobbyClient.cpp b/client/NetPacksLobbyClient.cpp index ee7a5f9a5..5d81fbdef 100644 --- a/client/NetPacksLobbyClient.cpp +++ b/client/NetPacksLobbyClient.cpp @@ -204,8 +204,8 @@ void ApplyOnLobbyScreenNetPackVisitor::visitLobbyUpdateState(LobbyUpdateState & if(!lobby->bonusSel && handler.si->campState && handler.getState() == EClientState::LOBBY_CAMPAIGN) { lobby->bonusSel = std::make_shared(); - if(!handler.si->campState->conqueredScenarios().size()) - GH.windows().createAndPushWindow(VideoPath::builtin("Hc1_Intro"), ImagePath::builtin("INTRORIM"), lobby->bonusSel); + if(!handler.si->campState->conqueredScenarios().size() && !handler.si->campState->getIntroVideo().empty()) + GH.windows().createAndPushWindow(handler.si->campState->getIntroVideo(), handler.si->campState->getIntroVideoRim().empty() ? ImagePath::builtin("INTRORIM") : handler.si->campState->getIntroVideoRim(), lobby->bonusSel); else GH.windows().pushWindow(lobby->bonusSel); } diff --git a/client/lobby/CBonusSelection.cpp b/client/lobby/CBonusSelection.cpp index e59d924c6..7e4015094 100644 --- a/client/lobby/CBonusSelection.cpp +++ b/client/lobby/CBonusSelection.cpp @@ -63,16 +63,35 @@ CampaignIntroVideo::CampaignIntroVideo(VideoPath video, ImagePath rim, std::shar : CWindowObject(BORDERED), bonusSel(bonusSel) { OBJECT_CONSTRUCTION; - videoPlayer = std::make_shared(Point(0, 0), video, true, [this](){ exit(); }); + + addUsedEvents(LCLICK | KEYBOARD); + + pos = center(Rect(0, 0, 800, 600)); + + videoPlayer = std::make_shared(Point(80, 186), video, true, [this](){ exit(); }); setBackground(rim); + + audioVol = CCS->musich->getVolume(); + CCS->musich->setVolume(0); } void CampaignIntroVideo::exit() { close(); + CCS->musich->setVolume(audioVol); GH.windows().pushWindow(bonusSel); } +void CampaignIntroVideo::clickPressed(const Point & cursorPosition) +{ + exit(); +} + +void CampaignIntroVideo::keyPressed(EShortcut key) +{ + exit(); +} + std::shared_ptr CBonusSelection::getCampaign() { return CSH->si->campState; diff --git a/client/lobby/CBonusSelection.h b/client/lobby/CBonusSelection.h index 2d9066d9c..9f6d021f9 100644 --- a/client/lobby/CBonusSelection.h +++ b/client/lobby/CBonusSelection.h @@ -38,9 +38,14 @@ class CampaignIntroVideo : public CWindowObject std::shared_ptr videoPlayer; std::shared_ptr bonusSel; + ui32 audioVol; + void exit(); public: CampaignIntroVideo(VideoPath video, ImagePath rim, std::shared_ptr bonusSel); + + void clickPressed(const Point & cursorPosition) override; + void keyPressed(EShortcut key) override; }; /// Campaign screen where you can choose one out of three starting bonuses diff --git a/config/campaignOverrides.json b/config/campaignOverrides.json index 55a2f2af5..e68102a21 100644 --- a/config/campaignOverrides.json +++ b/config/campaignOverrides.json @@ -28,6 +28,8 @@ { "voiceProlog": "Hc1_ABvoFL3" }, { "voiceProlog": "Hc1_H3x2BBf", "voiceEpilog": "Hc1_N1C_D" } ], - "loadingBackground": "Hc1_LoadBar" + "loadingBackground": "Hc1_LoadBar", + "introVideoRim": "Hc1_INTRORIM", + "introVideo": "Hc1_Intro" } } diff --git a/docs/modders/Campaign_Format.md b/docs/modders/Campaign_Format.md index d0ecc823a..46cc7b2de 100644 --- a/docs/modders/Campaign_Format.md +++ b/docs/modders/Campaign_Format.md @@ -53,6 +53,8 @@ In header are parameters describing campaign properties - `"creationDateTime"` unix time of campaign creation - `"allowDifficultySelection"` is a boolean field (`true`/`false`) which allows or disallows to choose difficulty before scenario start - `"loadingBackground"` is for setting a different loading screen background +- `"introVideo"` is for defining an optional intro video +- `"introVideoRim"` is for the Rim around the optional video (default is INTRORIM) ## Scenario description diff --git a/lib/campaign/CampaignHandler.cpp b/lib/campaign/CampaignHandler.cpp index e795a15a0..394e48411 100644 --- a/lib/campaign/CampaignHandler.cpp +++ b/lib/campaign/CampaignHandler.cpp @@ -169,6 +169,8 @@ void CampaignHandler::readHeaderFromJson(CampaignHeader & ret, JsonNode & reader ret.modName = modName; ret.encoding = encoding; ret.loadingBackground = ImagePath::fromJson(reader["loadingBackground"]); + ret.introVideoRim = ImagePath::fromJson(reader["introVideoRim"]); + ret.introVideo = VideoPath::fromJson(reader["introVideo"]); } CampaignScenario CampaignHandler::readScenarioFromJson(JsonNode & reader) diff --git a/lib/campaign/CampaignState.cpp b/lib/campaign/CampaignState.cpp index f5b335c40..d142d89b6 100644 --- a/lib/campaign/CampaignState.cpp +++ b/lib/campaign/CampaignState.cpp @@ -210,6 +210,16 @@ ImagePath CampaignHeader::getLoadingBackground() const return loadingBackground; } +ImagePath CampaignHeader::getIntroVideoRim() const +{ + return introVideoRim; +} + +VideoPath CampaignHeader::getIntroVideo() const +{ + return introVideo; +} + const CampaignRegions & CampaignHeader::getRegions() const { return campaignRegions; @@ -479,6 +489,10 @@ void Campaign::overrideCampaign(bool scenario) loadLegacyData(CampaignRegions::fromJson(entry.second["regions"]), entry.second["scenarioCount"].Integer()); if(!entry.second["loadingBackground"].isNull()) loadingBackground = ImagePath::builtin(entry.second["loadingBackground"].String()); + if(!entry.second["introVideoRim"].isNull()) + introVideoRim = ImagePath::builtin(entry.second["introVideoRim"].String()); + if(!entry.second["introVideo"].isNull()) + introVideo = VideoPath::builtin(entry.second["introVideo"].String()); } else { diff --git a/lib/campaign/CampaignState.h b/lib/campaign/CampaignState.h index faafa4670..66f1dafad 100644 --- a/lib/campaign/CampaignState.h +++ b/lib/campaign/CampaignState.h @@ -98,6 +98,8 @@ class DLL_LINKAGE CampaignHeader : public boost::noncopyable std::string modName; std::string encoding; ImagePath loadingBackground; + ImagePath introVideoRim; + VideoPath introVideo; int numberOfScenarios = 0; bool difficultyChosenByPlayer = false; @@ -122,6 +124,8 @@ public: std::string getEncoding() const; AudioPath getMusic() const; ImagePath getLoadingBackground() const; + ImagePath getIntroVideoRim() const; + VideoPath getIntroVideo() const; const CampaignRegions & getRegions() const; TextContainerRegistrable & getTexts(); @@ -149,6 +153,8 @@ public: if (h.version >= Handler::Version::CHRONICLES_SUPPORT) { h & loadingBackground; + h & introVideoRim; + h & introVideo; } } };