From cdc27d1fcf3a5e27c3b90e2663f4f8e5fe61e4a7 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Tue, 27 Jun 2023 20:09:11 +0300 Subject: [PATCH] Play correct music file in campaign menu --- client/lobby/CBonusSelection.cpp | 3 +++ client/mainmenu/CCampaignScreen.cpp | 7 +++++++ client/mainmenu/CCampaignScreen.h | 2 ++ lib/campaign/CampaignHandler.cpp | 5 +++-- lib/campaign/CampaignState.cpp | 25 ++++++++++++++++++++----- lib/campaign/CampaignState.h | 16 ++++++++++------ 6 files changed, 45 insertions(+), 13 deletions(-) diff --git a/client/lobby/CBonusSelection.cpp b/client/lobby/CBonusSelection.cpp index e27aeaaf1..3d83f262a 100644 --- a/client/lobby/CBonusSelection.cpp +++ b/client/lobby/CBonusSelection.cpp @@ -112,6 +112,9 @@ CBonusSelection::CBonusSelection() else if(getCampaign()->isConquered(scenarioID)) //display as striped regions.push_back(std::make_shared(scenarioID, false, false, getCampaign()->getRegions())); } + + if (!getCampaign()->getMusic().empty()) + CCS->musich->playMusic( "Music/" + getCampaign()->getMusic(), true, false); } void CBonusSelection::createBonusesIcons() diff --git a/client/mainmenu/CCampaignScreen.cpp b/client/mainmenu/CCampaignScreen.cpp index d5f4a280f..2f8696116 100644 --- a/client/mainmenu/CCampaignScreen.cpp +++ b/client/mainmenu/CCampaignScreen.cpp @@ -73,6 +73,13 @@ CCampaignScreen::CCampaignScreen(const JsonNode & config) campButtons.push_back(std::make_shared(node)); } +void CCampaignScreen::activate() +{ + CCS->musich->playMusic("Music/MainMenu", true, false); + + CWindowObject::activate(); +} + std::shared_ptr CCampaignScreen::createExitButton(const JsonNode & button) { std::pair help; diff --git a/client/mainmenu/CCampaignScreen.h b/client/mainmenu/CCampaignScreen.h index fcb505a71..67baf0c8f 100644 --- a/client/mainmenu/CCampaignScreen.h +++ b/client/mainmenu/CCampaignScreen.h @@ -58,4 +58,6 @@ public: enum CampaignSet {ROE, AB, SOD, WOG}; CCampaignScreen(const JsonNode & config); + + void activate() override; }; diff --git a/lib/campaign/CampaignHandler.cpp b/lib/campaign/CampaignHandler.cpp index 41323f780..f4452ab7d 100644 --- a/lib/campaign/CampaignHandler.cpp +++ b/lib/campaign/CampaignHandler.cpp @@ -150,7 +150,7 @@ void CampaignHandler::readHeaderFromJson(CampaignHeader & ret, JsonNode & reader ret.name = reader["name"].String(); ret.description = reader["description"].String(); ret.difficultyChoosenByPlayer = reader["allowDifficultySelection"].Bool(); - //skip ret.music because it's unused in vcmi + ret.music = reader["music"].String(); ret.filename = filename; ret.modName = modName; ret.encoding = encoding; @@ -386,7 +386,8 @@ void CampaignHandler::readHeaderFromMemory( CampaignHeader & ret, CBinaryReader ret.difficultyChoosenByPlayer = reader.readInt8(); else ret.difficultyChoosenByPlayer = false; - reader.readInt8(); //music - skip as unused + + ret.music = prologMusicName(reader.readInt8()); ret.filename = filename; ret.modName = modName; ret.encoding = encoding; diff --git a/lib/campaign/CampaignState.cpp b/lib/campaign/CampaignState.cpp index 10a03c277..554f89d44 100644 --- a/lib/campaign/CampaignState.cpp +++ b/lib/campaign/CampaignState.cpp @@ -149,6 +149,21 @@ std::string CampaignHeader::getFilename() const return filename; } +std::string CampaignHeader::getModName() const +{ + return modName; +} + +std::string CampaignHeader::getEncoding() const +{ + return encoding; +} + +std::string CampaignHeader::getMusic() const +{ + return music; +} + const CampaignRegions & CampaignHeader::getRegions() const { return campaignRegions; @@ -304,11 +319,11 @@ std::unique_ptr CampaignState::getMap(CampaignScenarioID scenarioId) const scenarioId = currentMap.value(); CMapService mapService; - std::string scenarioName = filename.substr(0, filename.find('.')); + std::string scenarioName = getFilename().substr(0, getFilename().find('.')); boost::to_lower(scenarioName); scenarioName += ':' + std::to_string(static_cast(scenarioId)); const auto & mapContent = mapPieces.find(scenarioId)->second; - return mapService.loadMap(mapContent.data(), mapContent.size(), scenarioName, modName, encoding); + return mapService.loadMap(mapContent.data(), mapContent.size(), scenarioName, getModName(), getEncoding()); } std::unique_ptr CampaignState::getMapHeader(CampaignScenarioID scenarioId) const @@ -317,11 +332,11 @@ std::unique_ptr CampaignState::getMapHeader(CampaignScenarioID scena scenarioId = currentMap.value(); CMapService mapService; - std::string scenarioName = filename.substr(0, filename.find('.')); + std::string scenarioName = getFilename().substr(0, getFilename().find('.')); boost::to_lower(scenarioName); scenarioName += ':' + std::to_string(static_cast(scenarioId)); const auto & mapContent = mapPieces.find(scenarioId)->second; - return mapService.loadMapHeader(mapContent.data(), mapContent.size(), scenarioName, modName, encoding); + return mapService.loadMapHeader(mapContent.data(), mapContent.size(), scenarioName, getModName(), getEncoding()); } std::shared_ptr CampaignState::getMapInfo(CampaignScenarioID scenarioId) const @@ -330,7 +345,7 @@ std::shared_ptr CampaignState::getMapInfo(CampaignScenarioID scenarioI scenarioId = currentMap.value(); auto mapInfo = std::make_shared(); - mapInfo->fileURI = filename; + mapInfo->fileURI = getFilename(); mapInfo->mapHeader = getMapHeader(scenarioId); mapInfo->countPlayers(); return mapInfo; diff --git a/lib/campaign/CampaignState.h b/lib/campaign/CampaignState.h index 35b25717b..51fb5c034 100644 --- a/lib/campaign/CampaignState.h +++ b/lib/campaign/CampaignState.h @@ -71,20 +71,20 @@ class DLL_LINKAGE CampaignHeader : public boost::noncopyable { friend class CampaignHandler; - int numberOfScenarios = 0; CampaignVersion version = CampaignVersion::NONE; CampaignRegions campaignRegions; std::string name; std::string description; - bool difficultyChoosenByPlayer = false; - - void loadLegacyData(ui8 campId); - -protected: + std::string music; std::string filename; std::string modName; std::string encoding; + int numberOfScenarios = 0; + bool difficultyChoosenByPlayer = false; + + void loadLegacyData(ui8 campId); + public: bool playerSelectedDifficulty() const; bool formatVCMI() const; @@ -92,6 +92,9 @@ public: std::string getDescription() const; std::string getName() const; std::string getFilename() const; + std::string getModName() const; + std::string getEncoding() const; + std::string getMusic() const; const CampaignRegions & getRegions() const; @@ -105,6 +108,7 @@ public: h & difficultyChoosenByPlayer; h & filename; h & modName; + h & music; h & encoding; } };