mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	It is now possible to define custom battle opening sound and custom music
for a battlefield
This commit is contained in:
		| @@ -35,6 +35,7 @@ | ||||
| #include "../adventureMap/AdventureMapInterface.h" | ||||
|  | ||||
| #include "../../CCallback.h" | ||||
| #include "../../lib/BattleFieldHandler.h" | ||||
| #include "../../lib/CStack.h" | ||||
| #include "../../lib/CConfigHandler.h" | ||||
| #include "../../lib/CGeneralTextHandler.h" | ||||
| @@ -113,6 +114,9 @@ void BattleInterface::playIntroSoundAndUnlockInterface() | ||||
| 			onIntroSoundPlayed(); | ||||
| 	}; | ||||
|  | ||||
| 	auto bfieldType = getBattle()->battleGetBattlefieldType(); | ||||
| 	const auto & battlefieldSound = bfieldType.getInfo()->musicFilename; | ||||
|  | ||||
| 	std::vector<soundBase::soundID> battleIntroSounds = | ||||
| 	{ | ||||
| 		soundBase::battle00, soundBase::battle01, | ||||
| @@ -120,7 +124,13 @@ void BattleInterface::playIntroSoundAndUnlockInterface() | ||||
| 		soundBase::battle05, soundBase::battle06, soundBase::battle07 | ||||
| 	}; | ||||
|  | ||||
| 	int battleIntroSoundChannel = CCS->soundh->playSoundFromSet(battleIntroSounds); | ||||
| 	int battleIntroSoundChannel = -1; | ||||
|  | ||||
| 	if (!battlefieldSound.empty()) | ||||
| 		battleIntroSoundChannel = CCS->soundh->playSound(battlefieldSound); | ||||
| 	else | ||||
| 		battleIntroSoundChannel = CCS->soundh->playSoundFromSet(battleIntroSounds); | ||||
|  | ||||
| 	if (battleIntroSoundChannel != -1) | ||||
| 	{ | ||||
| 		CCS->soundh->setCallback(battleIntroSoundChannel, onIntroPlayed); | ||||
| @@ -144,7 +154,13 @@ void BattleInterface::onIntroSoundPlayed() | ||||
| 	if (openingPlaying()) | ||||
| 		openingEnd(); | ||||
|  | ||||
| 	CCS->musich->playMusicFromSet("battle", true, true); | ||||
| 	auto bfieldType = getBattle()->battleGetBattlefieldType(); | ||||
| 	const auto & battlefieldMusic = bfieldType.getInfo()->musicFilename; | ||||
|  | ||||
| 	if (!battlefieldMusic.empty()) | ||||
| 		CCS->musich->playMusic(battlefieldMusic, true, true); | ||||
| 	else | ||||
| 		CCS->musich->playMusicFromSet("battle", true, true); | ||||
| } | ||||
|  | ||||
| void BattleInterface::openingEnd() | ||||
|   | ||||
| @@ -24,6 +24,18 @@ | ||||
| 			"format" : "imageFile", | ||||
| 			"description" : "Background image for this battlefield" | ||||
| 		}, | ||||
| 		"music" : | ||||
| 		{ | ||||
| 			"description" : "Optional, filename for custom music to play during combat on this terrain", | ||||
| 			"type" : "string", | ||||
| 			"format" : "musicFile" | ||||
| 		}, | ||||
| 		"openingSound" : | ||||
| 		{ | ||||
| 			"description" : "Optional, filename for custom sound to play during combat opening on this terrain", | ||||
| 			"type" : "string", | ||||
| 			"format" : "musicFile" | ||||
| 		}, | ||||
| 		"impassableHexes" : { | ||||
| 			"type" : "array", | ||||
| 			"description" : "List of battle hexes that will be always blocked on this battlefield (e.g. ship to ship battles)", | ||||
|   | ||||
| @@ -1,17 +1,23 @@ | ||||
| ```jsonc | ||||
| 	// Human-readable name of the battlefield | ||||
| 	"name" : "" | ||||
| 	"name" : "", | ||||
| 	 | ||||
| 	// If set to true, obstacles will be taken from "specialBattlefields" property of an obstacle | ||||
| 	// If set to false, obstacles will be taken from "allowedTerrains" instead | ||||
| 	"isSpecial" : false | ||||
| 	"isSpecial" : false, | ||||
| 	 | ||||
| 	// List of bonuses that will affect all battles on this battlefield | ||||
| 	"bonuses" : { BONUS_FORMAT } | ||||
| 	"bonuses" : { BONUS_FORMAT }, | ||||
| 	 | ||||
| 	// Background image for this battlefield | ||||
| 	"graphics" : "" | ||||
| 	"graphics" : "", | ||||
| 	 | ||||
| 	// Optional, filename for custom music to play during combat on this terrain | ||||
| 	"music" : "", | ||||
| 	 | ||||
| 	// Optional, filename for custom sound to play during combat opening on this terrain | ||||
| 	"openingSound" : "", | ||||
| 	 | ||||
| 	// List of battle hexes that will be always blocked on this battlefield (e.g. ship to ship battles) | ||||
| 	"impassableHexes" : [ 10, 20, 50 ] | ||||
| 	"impassableHexes" : [ 10, 20, 50 ], | ||||
| ``` | ||||
| @@ -40,6 +40,9 @@ std::shared_ptr<BattleFieldInfo> BattleFieldHandler::loadFromJson(const std::str | ||||
| 	for(auto node : json["impassableHexes"].Vector()) | ||||
| 		info->impassableHexes.emplace_back(node.Integer()); | ||||
|  | ||||
| 	info->openingSoundFilename = AudioPath::fromJson(json["openingSound"]); | ||||
| 	info->musicFilename = AudioPath::fromJson(json["music"]); | ||||
|  | ||||
| 	return info; | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -32,6 +32,8 @@ public: | ||||
| 	std::string icon; | ||||
| 	si32 iconIndex; | ||||
| 	std::vector<BattleHex> impassableHexes; | ||||
| 	AudioPath openingSoundFilename; | ||||
| 	AudioPath musicFilename; | ||||
|  | ||||
| 	BattleFieldInfo()  | ||||
| 		: BattleFieldInfo(BattleField::NONE, "") | ||||
|   | ||||
		Reference in New Issue
	
	Block a user