Browse Source

Fix battle startup with "no intro sound" mod

Ivan Savenko 2 years ago
parent
commit
2167cb2a68
2 changed files with 25 additions and 22 deletions
  1. 23 20
      client/battle/BattleInterface.cpp
  2. 2 2
      client/battle/BattleInterface.h

+ 23 - 20
client/battle/BattleInterface.cpp

@@ -54,6 +54,7 @@ BattleInterface::BattleInterface(const CCreatureSet *army1, const CCreatureSet *
 	, attackerInt(att)
 	, defenderInt(defen)
 	, curInt(att)
+	, battleOpeningDelayActive(true)
 {
 	if(spectatorInt)
 	{
@@ -112,7 +113,7 @@ void BattleInterface::playIntroSoundAndUnlockInterface()
 		}
 	};
 
-	battleIntroSoundChannel = CCS->soundh->playSoundFromSet(CCS->soundh->battleIntroSounds);
+	int battleIntroSoundChannel = CCS->soundh->playSoundFromSet(CCS->soundh->battleIntroSounds);
 	if (battleIntroSoundChannel != -1)
 	{
 		CCS->soundh->setCallback(battleIntroSoundChannel, onIntroPlayed);
@@ -120,8 +121,15 @@ void BattleInterface::playIntroSoundAndUnlockInterface()
 		if (settings["gameTweaks"]["skipBattleIntroMusic"].Bool())
 			openingEnd();
 	}
-	else
+	else // failed to play sound
+	{
 		onIntroSoundPlayed();
+	}
+}
+
+bool BattleInterface::openingPlaying()
+{
+	return battleOpeningDelayActive;
 }
 
 void BattleInterface::onIntroSoundPlayed()
@@ -132,6 +140,19 @@ void BattleInterface::onIntroSoundPlayed()
 	CCS->musich->playMusicFromSet("battle", true, true);
 }
 
+void BattleInterface::openingEnd()
+{
+	assert(openingPlaying());
+	if (!openingPlaying())
+		return;
+
+	onAnimationsFinished();
+	if(tacticsMode)
+		tacticNextStack(nullptr);
+	activateStack();
+	battleOpeningDelayActive = false;
+}
+
 BattleInterface::~BattleInterface()
 {
 	CPlayerInterface::battleInt = nullptr;
@@ -530,24 +551,6 @@ void BattleInterface::activateStack()
 	GH.fakeMouseMove();
 }
 
-bool BattleInterface::openingPlaying()
-{
-	return battleIntroSoundChannel != -1;
-}
-
-void BattleInterface::openingEnd()
-{
-	assert(openingPlaying());
-	if (!openingPlaying())
-		return;
-
-	onAnimationsFinished();
-	if(tacticsMode)
-		tacticNextStack(nullptr);
-	activateStack();
-	battleIntroSoundChannel = -1;
-}
-
 bool BattleInterface::makingTurn() const
 {
 	return stacksController->getActiveStack() != nullptr;

+ 2 - 2
client/battle/BattleInterface.h

@@ -111,8 +111,8 @@ class BattleInterface
 	/// defender interface, not null if attacker is human in our vcmiclient
 	std::shared_ptr<CPlayerInterface> defenderInt;
 
-	/// ID of channel on which battle opening sound is playing, or -1 if none
-	int battleIntroSoundChannel;
+	/// if set to true, battle is still starting and waiting for intro sound to end / key press from player
+	bool battleOpeningDelayActive;
 
 	void playIntroSoundAndUnlockInterface();
 	void onIntroSoundPlayed();