Reduce mission music code duplication

This commit is contained in:
Scott_NZ
2012-12-31 17:37:54 +13:00
parent c8e84b3a11
commit 82809f27f7
6 changed files with 30 additions and 106 deletions

View File

@@ -324,35 +324,15 @@ namespace OpenRA.Mods.RA.Missions
alliesRes.TakeCash(alliesRes.Cash);
alliesRes.TakeOre(alliesRes.Ore);
Game.MoveViewport(insertionLZ.Location.ToFloat2());
Game.ConnectionStateChanged += StopMusic;
Media.PlayFMVFullscreen(w, "ally1.vqa", () =>
{
Media.PlayFMVFullscreen(w, "landing.vqa", () =>
{
InsertTanyaAtLZ();
SendPatrol();
PlayMusic();
MissionUtils.PlayMissionMusic();
});
});
}
void PlayMusic()
{
if (!Rules.InstalledMusic.Any())
{
return;
}
var track = Rules.InstalledMusic.Random(Game.CosmeticRandom);
Sound.PlayMusicThen(track.Value, PlayMusic);
}
void StopMusic(OrderManager orderManager)
{
if (!orderManager.GameStarted)
{
Sound.StopMusic();
Game.ConnectionStateChanged -= StopMusic;
}
}
}
}

View File

@@ -569,8 +569,7 @@ namespace OpenRA.Mods.RA.Missions
{
Game.MoveViewport(allies2BasePoint.Location.ToFloat2());
}
PlayMusic();
Game.ConnectionStateChanged += StopMusic;
MissionUtils.PlayMissionMusic();
}
void SetupAlliedBase(Dictionary<string, Actor> actors)
@@ -588,24 +587,5 @@ namespace OpenRA.Mods.RA.Missions
});
});
}
void PlayMusic()
{
if (!Rules.InstalledMusic.Any())
{
return;
}
var track = Rules.InstalledMusic.Random(Game.CosmeticRandom);
Sound.PlayMusicThen(track.Value, PlayMusic);
}
void StopMusic(OrderManager orderManager)
{
if (!orderManager.GameStarted)
{
Sound.StopMusic();
Game.ConnectionStateChanged -= StopMusic;
}
}
}
}

View File

@@ -472,28 +472,8 @@ namespace OpenRA.Mods.RA.Missions
{
Game.MoveViewport(allies2EntryPoint.Location.ToFloat2());
}
PlayMusic();
OnObjectivesUpdated(false);
Game.ConnectionStateChanged += StopMusic;
}
void PlayMusic()
{
if (!Rules.InstalledMusic.Any())
{
return;
}
var track = Rules.InstalledMusic.Random(Game.CosmeticRandom);
Sound.PlayMusicThen(track.Value, PlayMusic);
}
void StopMusic(OrderManager orderManager)
{
if (!orderManager.GameStarted)
{
Sound.StopMusic();
Game.ConnectionStateChanged -= StopMusic;
}
MissionUtils.PlayMissionMusic();
}
}
}

View File

@@ -34,11 +34,12 @@ namespace OpenRA.Mods.RA.Missions
Dictionary<int, Objective> objectives = new Dictionary<int, Objective>
{
{ InfiltrateID, new Objective(ObjectiveType.Primary, "", ObjectiveStatus.InProgress) },
{ DestroyID, new Objective(ObjectiveType.Primary, "Secure the laboratory and destroy the rest of the Soviet base. Ensure that the laboratory is not destroyed.", ObjectiveStatus.Inactive) }
{ DestroyID, new Objective(ObjectiveType.Primary, Destroy, ObjectiveStatus.Inactive) }
};
const int InfiltrateID = 0;
const int DestroyID = 1;
const string Destroy = "Secure the laboratory and destroy the rest of the Soviet base. Ensure that the laboratory is not destroyed.";
const string Infiltrate = "The Soviets are currently developing a new defensive system named the \"Iron Curtain\" at their main research laboratory. Get our {0} into the laboratory undetected.";
Actor lstEntryPoint;
@@ -415,27 +416,7 @@ namespace OpenRA.Mods.RA.Missions
OnObjectivesUpdated(false);
SetupSubStances();
Game.MoveViewport(lstEntryPoint.Location.ToFloat2());
PlayMusic();
Game.ConnectionStateChanged += StopMusic;
}
void PlayMusic()
{
if (!Rules.InstalledMusic.Any())
{
return;
}
var track = Rules.InstalledMusic.Random(Game.CosmeticRandom);
Sound.PlayMusicThen(track.Value, PlayMusic);
}
void StopMusic(OrderManager orderManager)
{
if (!orderManager.GameStarted)
{
Sound.StopMusic();
Game.ConnectionStateChanged -= StopMusic;
}
MissionUtils.PlayMissionMusic();
}
}

View File

@@ -16,6 +16,7 @@ using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Air;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Traits;
using OpenRA.Network;
namespace OpenRA.Mods.RA.Missions
{
@@ -141,5 +142,27 @@ namespace OpenRA.Mods.RA.Missions
{
return world.Actors.FirstOrDefault(a => a.HasTrait<Cargo>() && a.Trait<Cargo>().Passengers.Contains(actor));
}
public static void PlayMissionMusic()
{
if (!Rules.InstalledMusic.Any()) return;
Game.ConnectionStateChanged += StopMusic;
PlayMusic();
}
static void PlayMusic()
{
var track = Rules.InstalledMusic.Random(Game.CosmeticRandom);
Sound.PlayMusicThen(track.Value, PlayMusic);
}
static void StopMusic(OrderManager orderManager)
{
if (!orderManager.GameStarted)
{
Sound.StopMusic();
Game.ConnectionStateChanged -= StopMusic;
}
}
}
}

View File

@@ -135,32 +135,12 @@ namespace OpenRA.Mods.RA.Missions
airfield3 = actors["Airfield3"];
airfields = new[] { airfield1, airfield2, airfield3 };
Game.MoveViewport(startJeep.Location.ToFloat2());
Game.ConnectionStateChanged += StopMusic;
Media.PlayFMVFullscreen(w, "soviet1.vqa", () =>
{
PlayMusic();
MissionUtils.PlayMissionMusic();
LandYaks();
MoveJeep();
});
}
void PlayMusic()
{
if (!Rules.InstalledMusic.Any())
{
return;
}
var track = Rules.InstalledMusic.Random(Game.CosmeticRandom);
Sound.PlayMusicThen(track.Value, PlayMusic);
}
void StopMusic(OrderManager orderManager)
{
if (!orderManager.GameStarted)
{
Sound.StopMusic();
Game.ConnectionStateChanged -= StopMusic;
}
}
}
}