瀏覽代碼

code review

Laserlicht 1 年之前
父節點
當前提交
c7064377da

+ 8 - 4
client/lobby/CBonusSelection.cpp

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

+ 0 - 2
client/lobby/CBonusSelection.h

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

+ 6 - 6
config/heroes/portraits.json

@@ -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",

+ 3 - 3
lib/campaign/CampaignHandler.cpp

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

+ 28 - 25
lib/campaign/CampaignState.cpp

@@ -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());
-			}
-			else
+			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["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());
 				}
 			}
 		}

+ 2 - 1
lib/campaign/CampaignState.h

@@ -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)
 	{

+ 1 - 1
lib/filesystem/CArchiveLoader.cpp

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

+ 1 - 1
lib/filesystem/CArchiveLoader.h

@@ -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 */