From 127cbf3f965a347585566b98a1e2eb453d2ff65a Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 14 Oct 2010 22:16:01 +1300 Subject: [PATCH] Start pulling out useful scripting components - stalled by widget changes having broken the fmv player. --- OpenRA.Mods.Cnc/Missions/Gdi01Script.cs | 42 +++++-------------- OpenRA.Mods.RA/OpenRA.Mods.RA.csproj | 6 ++- OpenRA.Mods.RA/Scripting/Media.cs | 54 +++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 32 deletions(-) create mode 100644 OpenRA.Mods.RA/Scripting/Media.cs diff --git a/OpenRA.Mods.Cnc/Missions/Gdi01Script.cs b/OpenRA.Mods.Cnc/Missions/Gdi01Script.cs index 38df05e2e8..e608e6f06a 100644 --- a/OpenRA.Mods.Cnc/Missions/Gdi01Script.cs +++ b/OpenRA.Mods.Cnc/Missions/Gdi01Script.cs @@ -14,10 +14,12 @@ using OpenRA.Traits; using OpenRA.Widgets; using OpenRA.Traits.Activities; using OpenRA.FileFormats; +using OpenRA; using OpenRA.Mods.RA.Activities; using System; +using OpenRA.Mods.RA; -namespace OpenRA.Mods.RA +namespace OpenRA.Mods.Cnc { class Gdi01ScriptInfo : TraitInfo { } @@ -27,29 +29,6 @@ namespace OpenRA.Mods.RA Dictionary Players; Map Map; - public static void PlayFullscreenFMVThen(World w, string movie, Action then) - { - var playerRoot = Widget.OpenWindow("FMVPLAYER"); - var player = playerRoot.GetWidget("PLAYER"); - w.DisableTick = true; - player.Load(movie); - - // Stop music while fmv plays - var music = Sound.MusicPlaying; - if (music) - Sound.PauseMusic(); - - player.PlayThen(() => - { - if (music) - Sound.PlayMusic(); - - Widget.CloseWindow(); - w.DisableTick = false; - then(); - }); - } - public void WorldLoaded(World w) { Map = w.Map; @@ -57,11 +36,12 @@ namespace OpenRA.Mods.RA Actors = w.WorldActor.Trait().Actors; Game.MoveViewport((.5f * (w.Map.TopLeft + w.Map.BottomRight).ToFloat2()).ToInt2()); - PlayFullscreenFMVThen(w, "gdi1.vqa", () => PlayFullscreenFMVThen(w, "landing.vqa", () => - { - Sound.PlayMusic(Rules.Music["aoi"].Filename); - started = true; - })); + Scripting.Media.PlayFMVFullscreen(w, "gdi1.vqa", + () => Scripting.Media.PlayFMVFullscreen(w, "landing.vqa", () => + { + Sound.PlayMusic(Rules.Music["aoi"].Filename); + started = true; + })); } public void OnVictory(World w) @@ -72,7 +52,7 @@ namespace OpenRA.Mods.RA w.WorldActor.CancelActivity(); w.WorldActor.QueueActivity(new Wait(125)); - w.WorldActor.QueueActivity(new CallFunc(() => PlayFullscreenFMVThen(w, "consyard.vqa", () => + w.WorldActor.QueueActivity(new CallFunc(() => Scripting.Media.PlayFMVFullscreen(w, "consyard.vqa", () => { Sound.StopMusic(); Game.Disconnect(); @@ -87,7 +67,7 @@ namespace OpenRA.Mods.RA w.WorldActor.CancelActivity(); w.WorldActor.QueueActivity(new Wait(125)); - w.WorldActor.QueueActivity(new CallFunc(() => PlayFullscreenFMVThen(w, "gameover.vqa", () => + w.WorldActor.QueueActivity(new CallFunc(() => Scripting.Media.PlayFMVFullscreen(w, "gameover.vqa", () => { Sound.StopMusic(); Game.Disconnect(); diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index cf7d5f081d..530d3e99f4 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -1,4 +1,4 @@ - + Debug @@ -262,6 +262,7 @@ + @@ -288,4 +289,7 @@ copy "$(TargetPath)" "$(SolutionDir)mods/ra/" cd "$(SolutionDir)" + + + \ No newline at end of file diff --git a/OpenRA.Mods.RA/Scripting/Media.cs b/OpenRA.Mods.RA/Scripting/Media.cs new file mode 100644 index 0000000000..c947afc222 --- /dev/null +++ b/OpenRA.Mods.RA/Scripting/Media.cs @@ -0,0 +1,54 @@ +#region Copyright & License Information +/* + * Copyright 2007-2010 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see LICENSE. + */ +#endregion + +using System.Collections.Generic; +using System.Linq; +using OpenRA.Traits; +using OpenRA.Widgets; +using OpenRA.Traits.Activities; +using OpenRA.FileFormats; +using OpenRA.Mods.RA.Activities; +using System; + +namespace OpenRA.Scripting +{ + public class Media + { + public static void PlayFMVFullscreen(World w, string movie, Action onComplete) + { + var playerRoot = Widget.OpenWindow("FMVPLAYER"); + var player = playerRoot.GetWidget("PLAYER"); + w.DisableTick = true; + + Console.WriteLine("PlayFMV {0}",movie); + player.Load(movie); + + // Mute world sounds + var oldModifier = Sound.SoundVolumeModifier; + //Sound.SoundVolumeModifier = 0f; + + // Stop music while fmv plays + var music = Sound.MusicPlaying; + if (music) + Sound.PauseMusic(); + + player.PlayThen(() => + { + if (music) + Sound.PlayMusic(); + + Widget.CloseWindow(); + Sound.SoundVolumeModifier = oldModifier; + w.DisableTick = false; + onComplete(); + }); + } + } +}