1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-02 00:10:22 +02:00

code review

This commit is contained in:
Laserlicht 2024-09-01 12:23:10 +02:00
parent b80852617a
commit c7064377da
8 changed files with 49 additions and 43 deletions

View File

@ -71,14 +71,16 @@ CampaignIntroVideo::CampaignIntroVideo(VideoPath video, ImagePath rim, std::shar
videoPlayer = std::make_shared<VideoWidgetOnce>(Point(80, 186), video, true, [this](){ exit(); });
setBackground(rim);
audioVol = CCS->musich->getVolume();
CCS->musich->setVolume(0);
CCS->musich->stopMusic();
}
void CampaignIntroVideo::exit()
{
close();
CCS->musich->setVolume(audioVol);
if (!CSH->si->campState->getMusic().empty())
CCS->musich->playMusic(CSH->si->campState->getMusic(), true, false);
GH.windows().pushWindow(bonusSel);
}
@ -127,7 +129,9 @@ CBonusSelection::CBonusSelection()
labelCampaignDescription = std::make_shared<CLabel>(481, 63, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, CGI->generaltexth->allTexts[38]);
campaignDescription = std::make_shared<CTextBox>(getCampaign()->getDescriptionTranslated(), Rect(480, 86, 286, 117), 1);
mapName = std::make_shared<CLabel>(481, 219, FONT_BIG, ETextAlignment::TOPLEFT, Colors::YELLOW, CSH->mi->getNameTranslated(), CSH->getState() == EClientState::GAMEPLAY ? 225 : 285); //if video button active theres fewer space
bool videoButtonActive = CSH->getState() == EClientState::GAMEPLAY;
int availableSpace = videoButtonActive ? 225 : 285;
mapName = std::make_shared<CLabel>(481, 219, FONT_BIG, ETextAlignment::TOPLEFT, Colors::YELLOW, CSH->mi->getNameTranslated(), availableSpace );
labelMapDescription = std::make_shared<CLabel>(481, 253, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, CGI->generaltexth->allTexts[496]);
mapDescription = std::make_shared<CTextBox>("", Rect(480, 278, 292, 108), 1);

View File

@ -38,8 +38,6 @@ class CampaignIntroVideo : public CWindowObject
std::shared_ptr<VideoWidgetOnce> videoPlayer;
std::shared_ptr<CBonusSelection> bonusSel;
ui32 audioVol;
void exit();
public:
CampaignIntroVideo(VideoPath video, ImagePath rim, std::shared_ptr<CBonusSelection> bonusSel);

View File

@ -206,7 +206,7 @@
"portraitTarnumBarbarian" :
{
"class" : "barbarian",
"special" : false,
"special" : true,
"images": {
"large" : "Hc_HPL137",
"small" : "Hc_HPS137",
@ -235,7 +235,7 @@
"portraitTarnumKnight" :
{
"class" : "knight",
"special" : false,
"special" : true,
"images": {
"large" : "Hc_HPL138",
"small" : "Hc_HPS138",
@ -264,7 +264,7 @@
"portraitTarnumWizard" :
{
"class" : "wizard",
"special" : false,
"special" : true,
"images": {
"large" : "Hc_HPL139",
"small" : "Hc_HPS139",
@ -293,7 +293,7 @@
"portraitTarnumRanger" :
{
"class" : "ranger",
"special" : false,
"special" : true,
"images": {
"large" : "Hc_HPL140",
"small" : "Hc_HPS140",
@ -322,7 +322,7 @@
"portraitTarnumOverlord" :
{
"class" : "overlord",
"special" : false,
"special" : true,
"images": {
"large" : "Hc_HPL141",
"small" : "Hc_HPS141",
@ -351,7 +351,7 @@
"portraitTarnumBeastmaster" :
{
"class" : "beastmaster",
"special" : false,
"special" : true,
"images": {
"large" : "Hc_HPL142",
"small" : "Hc_HPS142",

View File

@ -38,14 +38,14 @@ void CampaignHandler::readCampaign(Campaign * ret, const std::vector<ui8> & inpu
CBinaryReader reader(&stream);
readHeaderFromMemory(*ret, reader, filename, modName, encoding);
ret->overrideCampaign(false);
ret->overrideCampaign();
for(int g = 0; g < ret->numberOfScenarios; ++g)
{
auto scenarioID = static_cast<CampaignScenarioID>(ret->scenarios.size());
ret->scenarios[scenarioID] = readScenarioFromMemory(reader, *ret);
}
ret->overrideCampaign(true);
ret->overrideCampaignScenarios();
}
else // text format (json)
{
@ -397,7 +397,7 @@ void CampaignHandler::readHeaderFromMemory( CampaignHeader & ret, CBinaryReader
{
ret.version = static_cast<CampaignVersion>(reader.readUInt32());
ui8 campId = reader.readUInt8() - 1;//change range of it from [1, 20] to [0, 19]
if(ret.version != CampaignVersion::Chr)
if(ret.version != CampaignVersion::Chr) // For chronicles: Will be overridden later; Chronicles uses own logic (reusing OH3 ID's)
ret.loadLegacyData(campId);
ret.name.appendTextID(readLocalizedString(ret, reader, filename, modName, encoding, "name"));
ret.description.appendTextID(readLocalizedString(ret, reader, filename, modName, encoding, "description"));

View File

@ -477,37 +477,40 @@ std::set<CampaignScenarioID> Campaign::allScenarios() const
return result;
}
void Campaign::overrideCampaign(bool scenario)
void Campaign::overrideCampaign()
{
JsonNode node = JsonUtils::assembleFromFiles("config/campaignOverrides.json");
const JsonNode node = JsonUtils::assembleFromFiles("config/campaignOverrides.json");
for (auto & entry : node.Struct())
if(filename == entry.first)
{
if(!scenario)
if(!entry.second["regions"].isNull() && !entry.second["scenarioCount"].isNull())
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());
}
}
void Campaign::overrideCampaignScenarios()
{
const JsonNode node = JsonUtils::assembleFromFiles("config/campaignOverrides.json");
for (auto & entry : node.Struct())
if(filename == entry.first)
{
if(!entry.second["scenarios"].isNull())
{
if(!entry.second["regions"].isNull() && !entry.second["scenarioCount"].isNull())
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
{
if(!entry.second["scenarios"].isNull())
auto sc = entry.second["scenarios"].Vector();
for(int i = 0; i < sc.size(); i++)
{
auto sc = entry.second["scenarios"].Vector();
for(int i = 0; i < sc.size(); i++)
{
auto it = scenarios.begin();
std::advance(it, i);
if(!sc.at(i)["voiceProlog"].isNull())
it->second.prolog.prologVoice = AudioPath::builtin(sc.at(i)["voiceProlog"].String());
if(!sc.at(i)["voiceEpilog"].isNull())
it->second.epilog.prologVoice = AudioPath::builtin(sc.at(i)["voiceEpilog"].String());
}
auto it = scenarios.begin();
std::advance(it, i);
if(!sc.at(i)["voiceProlog"].isNull())
it->second.prolog.prologVoice = AudioPath::builtin(sc.at(i)["voiceProlog"].String());
if(!sc.at(i)["voiceEpilog"].isNull())
it->second.epilog.prologVoice = AudioPath::builtin(sc.at(i)["voiceEpilog"].String());
}
}
}

View File

@ -261,7 +261,8 @@ public:
std::set<CampaignScenarioID> allScenarios() const;
int scenariosCount() const;
void overrideCampaign(bool scenario);
void overrideCampaign();
void overrideCampaignScenarios();
template <typename Handler> void serialize(Handler &h)
{

View File

@ -197,7 +197,7 @@ std::string CArchiveLoader::getMountPoint() const
return mountPoint;
}
std::unordered_map<ResourcePath, ArchiveEntry> CArchiveLoader::getEntries() const
const std::unordered_map<ResourcePath, ArchiveEntry> & CArchiveLoader::getEntries() const
{
return entries;
}

View File

@ -63,7 +63,7 @@ public:
std::unique_ptr<CInputStream> load(const ResourcePath & resourceName) const override;
bool existsResource(const ResourcePath & resourceName) const override;
std::string getMountPoint() const override;
std::unordered_map<ResourcePath, ArchiveEntry> getEntries() const;
const std::unordered_map<ResourcePath, ArchiveEntry> & getEntries() const;
void updateFilteredFiles(std::function<bool(const std::string &)> filter) const override {}
std::unordered_set<ResourcePath> getFilteredFiles(std::function<bool(const ResourcePath &)> filter) const override;
/** Extracts one archive entry to the specified subfolder. Used for Video and Sound */