1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

Play correct music file in campaign menu

This commit is contained in:
Ivan Savenko 2023-06-27 20:09:11 +03:00
parent 0fdbf54937
commit cdc27d1fcf
6 changed files with 45 additions and 13 deletions

View File

@ -112,6 +112,9 @@ CBonusSelection::CBonusSelection()
else if(getCampaign()->isConquered(scenarioID)) //display as striped
regions.push_back(std::make_shared<CRegion>(scenarioID, false, false, getCampaign()->getRegions()));
}
if (!getCampaign()->getMusic().empty())
CCS->musich->playMusic( "Music/" + getCampaign()->getMusic(), true, false);
}
void CBonusSelection::createBonusesIcons()

View File

@ -73,6 +73,13 @@ CCampaignScreen::CCampaignScreen(const JsonNode & config)
campButtons.push_back(std::make_shared<CCampaignButton>(node));
}
void CCampaignScreen::activate()
{
CCS->musich->playMusic("Music/MainMenu", true, false);
CWindowObject::activate();
}
std::shared_ptr<CButton> CCampaignScreen::createExitButton(const JsonNode & button)
{
std::pair<std::string, std::string> help;

View File

@ -58,4 +58,6 @@ public:
enum CampaignSet {ROE, AB, SOD, WOG};
CCampaignScreen(const JsonNode & config);
void activate() override;
};

View File

@ -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;

View File

@ -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<CMap> 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<int>(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<CMapHeader> CampaignState::getMapHeader(CampaignScenarioID scenarioId) const
@ -317,11 +332,11 @@ std::unique_ptr<CMapHeader> 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<int>(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<CMapInfo> CampaignState::getMapInfo(CampaignScenarioID scenarioId) const
@ -330,7 +345,7 @@ std::shared_ptr<CMapInfo> CampaignState::getMapInfo(CampaignScenarioID scenarioI
scenarioId = currentMap.value();
auto mapInfo = std::make_shared<CMapInfo>();
mapInfo->fileURI = filename;
mapInfo->fileURI = getFilename();
mapInfo->mapHeader = getMapHeader(scenarioId);
mapInfo->countPlayers();
return mapInfo;

View File

@ -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;
}
};