From 11aed465a8605f710d45559cc0ac105c41acd32b Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 12 Aug 2010 19:31:29 +1200 Subject: [PATCH] Populate the list from yaml; Define ra-allies movies; Additional polish. --- OpenRA.FileFormats/Graphics/VqaReader.cs | 2 +- OpenRA.FileFormats/Session.cs | 3 +- OpenRA.Game/GameRules/Rules.cs | 2 + .../Widgets/Delegates/VideoPlayerDelegate.cs | 21 +++----- OpenRA.Game/Widgets/VqaPlayerWidget.cs | 46 +++++++++++------ mods/ra/mod.yaml | 4 ++ mods/ra/movies1.yaml | 51 +++++++++++++++++++ 7 files changed, 97 insertions(+), 32 deletions(-) create mode 100644 mods/ra/movies1.yaml diff --git a/OpenRA.FileFormats/Graphics/VqaReader.cs b/OpenRA.FileFormats/Graphics/VqaReader.cs index d401ba236e..d0ca916b50 100644 --- a/OpenRA.FileFormats/Graphics/VqaReader.cs +++ b/OpenRA.FileFormats/Graphics/VqaReader.cs @@ -257,7 +257,7 @@ namespace OpenRA.FileFormats } } - int cachedFrame; + int cachedFrame = -1; public int[,] FrameData { get { if (cachedFrame != currentFrame) diff --git a/OpenRA.FileFormats/Session.cs b/OpenRA.FileFormats/Session.cs index 1699ca96de..93446620dd 100644 --- a/OpenRA.FileFormats/Session.cs +++ b/OpenRA.FileFormats/Session.cs @@ -56,7 +56,7 @@ namespace OpenRA.FileFormats public readonly string[] Folders, Packages, Rules, Sequences, Chrome, Assemblies, ChromeLayout, - Weapons, Voices, Music, TileSets; + Weapons, Voices, Music, Movies, TileSets; public readonly string ShellmapUid; @@ -76,6 +76,7 @@ namespace OpenRA.FileFormats Weapons = YamlList(yaml, "Weapons"); Voices = YamlList(yaml, "Voices"); Music = YamlList(yaml, "Music"); + Movies = YamlList(yaml, "Movies"); TileSets = YamlList(yaml, "TileSets"); ShellmapUid = yaml["ShellmapUid"].Value; diff --git a/OpenRA.Game/GameRules/Rules.cs b/OpenRA.Game/GameRules/Rules.cs index 0aff73fa8c..4676d17531 100755 --- a/OpenRA.Game/GameRules/Rules.cs +++ b/OpenRA.Game/GameRules/Rules.cs @@ -24,6 +24,7 @@ namespace OpenRA public static Dictionary Weapons; public static Dictionary Voices; public static Dictionary Music; + public static Dictionary Movies; public static Dictionary TileSets; public static void LoadRules(Manifest m, Map map) @@ -32,6 +33,7 @@ namespace OpenRA Weapons = LoadYamlRules(m.Weapons, map.Weapons, (k, _) => new WeaponInfo(k.Key.ToLowerInvariant(), k.Value)); Voices = LoadYamlRules(m.Voices, map.Voices, (k, _) => new VoiceInfo(k.Value)); Music = LoadYamlRules(m.Music, map.Music, (k, _) => new MusicInfo(k.Value)); + Movies = LoadYamlRules(m.Movies, new Dictionary(), (k, v) => k.Value.Value); TileSets = new Dictionary(); foreach (var file in m.TileSets) diff --git a/OpenRA.Game/Widgets/Delegates/VideoPlayerDelegate.cs b/OpenRA.Game/Widgets/Delegates/VideoPlayerDelegate.cs index 6aecfa927b..6bbe7a403c 100644 --- a/OpenRA.Game/Widgets/Delegates/VideoPlayerDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/VideoPlayerDelegate.cs @@ -16,17 +16,13 @@ namespace OpenRA.Widgets.Delegates { public class VideoPlayerDelegate : IWidgetDelegate { - string Selected = null; + string Selected; public VideoPlayerDelegate() { var bg = Widget.RootWidget.GetWidget("VIDEOPLAYER_MENU"); var player = bg.GetWidget("VIDEOPLAYER"); bg.GetWidget("BUTTON_PLAY").OnMouseUp = mi => { - if (Selected == null) - return true; - - player.Load(Selected); player.Play(); return true; }; @@ -53,14 +49,11 @@ namespace OpenRA.Widgets.Delegates var itemTemplate = vl.GetWidget("VIDEO_TEMPLATE"); int offset = itemTemplate.Bounds.Y; - // Todo: pull into per-mod yaml / Manifest - var tempVideos = new Dictionary(); - tempVideos.Add("obel.vqa", "Obelisk ZZZZAAAAAP"); - tempVideos.Add("ally1.vqa", "Allies briefing #1"); - tempVideos.Add("ally10.vqa", "Allies briefing #10"); + Selected = Rules.Movies.Keys.FirstOrDefault(); + if (Selected != null) + player.Load(Selected); - Selected = tempVideos.Keys.FirstOrDefault(); - foreach (var kv in tempVideos) + foreach (var kv in Rules.Movies) { var video = kv.Key; var title = kv.Value; @@ -73,10 +66,8 @@ namespace OpenRA.Widgets.Delegates template.GetBackground = () => ((video == Selected) ? "dialog2" : null); template.OnMouseDown = mi => { - if (Selected == video) - return true; - player.Stop(); Selected = video; + player.Load(video); return true; }; template.Parent = vl; diff --git a/OpenRA.Game/Widgets/VqaPlayerWidget.cs b/OpenRA.Game/Widgets/VqaPlayerWidget.cs index 5bc810e4c0..10faca4b46 100644 --- a/OpenRA.Game/Widgets/VqaPlayerWidget.cs +++ b/OpenRA.Game/Widgets/VqaPlayerWidget.cs @@ -28,6 +28,12 @@ namespace OpenRA.Widgets if (filename == cachedVideo) return; + if (playing) + { + playing = false; + Sound.StopVideoSoundtrack(); + } + cachedVideo = filename; video = new VqaReader(FileSystem.Open(filename)); invLength = video.Framerate*1f/video.Frames; @@ -35,7 +41,8 @@ namespace OpenRA.Widgets var size = Math.Max(video.Width, video.Height); var textureSize = OpenRA.Graphics.Util.NextPowerOf2(size); videoSprite = new Sprite(new Sheet(new Size(textureSize,textureSize)), new Rectangle( 0, 0, video.Width, video.Height ), TextureChannel.Alpha); - + videoSprite.sheet.Texture.SetData(video.FrameData); + var scale = Math.Min(RenderBounds.Width / video.Width, RenderBounds.Height / video.Height); videoOrigin = new float2(RenderBounds.X + (RenderBounds.Width - scale*video.Width)/2, RenderBounds.Y + (RenderBounds.Height - scale*video.Height)/2); videoSize = new float2(video.Width * scale, video.Height * scale); @@ -45,38 +52,47 @@ namespace OpenRA.Widgets Stopwatch sw = new Stopwatch(); public override void DrawInner(World world) { - if (!playing) + if (video == null) return; - - var nextFrame = (int)float2.Lerp(0, video.Frames, (float)(sw.ElapsedTime()*invLength)); - if (nextFrame > video.Frames) - { - Stop(); - return; - } - while (nextFrame > video.CurrentFrame) + if (playing) { - video.AdvanceFrame(); - if (nextFrame == video.CurrentFrame) - videoSprite.sheet.Texture.SetData(video.FrameData); + var nextFrame = (int)float2.Lerp(0, video.Frames, (float)(sw.ElapsedTime()*invLength)); + if (nextFrame > video.Frames) + { + Stop(); + return; + } + + while (nextFrame > video.CurrentFrame) + { + video.AdvanceFrame(); + if (nextFrame == video.CurrentFrame) + videoSprite.sheet.Texture.SetData(video.FrameData); + } } Game.Renderer.RgbaSpriteRenderer.DrawSprite(videoSprite, videoOrigin, "chrome", videoSize); } public void Play() { + if (playing || video == null) + return; + playing = true; - video.Reset(); - videoSprite.sheet.Texture.SetData(video.FrameData); sw.Reset(); Sound.PlayVideoSoundtrack(video.AudioData); } public void Stop() { + if (!playing || video == null) + return; + playing = false; Sound.StopVideoSoundtrack(); + video.Reset(); + videoSprite.sheet.Texture.SetData(video.FrameData); } } } diff --git a/mods/ra/mod.yaml b/mods/ra/mod.yaml index 22a3b3a27b..e59eac7729 100644 --- a/mods/ra/mod.yaml +++ b/mods/ra/mod.yaml @@ -20,6 +20,7 @@ Packages: snow.mix interior.mix scores.mix + ~movies1.mix Rules: mods/ra/defaults.yaml @@ -61,4 +62,7 @@ TileSets: Music: mods/ra/music.yaml +Movies: + mods/ra/movies1.yaml + ShellmapUid:f78ab8d4d40ac3c263d1e404e5bf8233dce1f1a7 diff --git a/mods/ra/movies1.yaml b/mods/ra/movies1.yaml new file mode 100644 index 0000000000..4691d506a3 --- /dev/null +++ b/mods/ra/movies1.yaml @@ -0,0 +1,51 @@ +aagun.vqa: a.a. gun shooting yak +aftrmath.vqa: iron curtain destroyed +ally1.vqa: get einstien +ally2.vqa: clear the way for the convoy +ally4.vqa: close the mountain pass +ally5.vqa: rescue tanya +ally6.vqa: find the iron curtain +ally8.vqa: protect the tech centre +ally9.vqa: rescue kosygin +ally10.vqa: stop nukes +ally10b.vqa: deactivate launch terminals +ally11.vqa: clear the river +ally12.vqa: infiltrate tech centers +ally14.vqa: final assult on moscow +allyend.vqa: stalin is dead +allymorf.vqa: allied logo +apcescpe.vqa: apc running away +assess.vqa: allied found iron curtain +battle.vqa: destroyed vechicles +binoc.vqa: guy viewing tanks through binoculars +bmap.vqa: dagger falls on map of europe & europe turns red +brdgtilt.vqa: a bridge +cronfail.vqa: chronosphere test failed +crontest.vqa: chronosphere test ok +destroyr.vqa: allied destroyers +dud.vqa: dud missile in london +elevator.vqa: inside soviet elevator +flare.vqa: flare man +frozen.vqa: frozen soldier +grvestne.vqa: tanya adams r.i.p. +landing.vqa: helicopter landing outside soviet base +masasslt.vqa: assault on moscow +mcv.vqa: mcv drives up +mcv_land.vqa: helicopter lands near mcv +montpass.vqa: truck drives over sign +oildrum.vqa: artillery blows up barrels +overrun.vqa: soldiers nearly run over +prolog.vqa: einstien eliminating hitler +redintro.vqa: red alert intro sequence +shipsink.vqa: ship sinking +shorbom1.vqa: ships attacking base +shorbom2.vqa: ships attacking base again +shorbomb.vqa: ships attacking another base +snowbomb.vqa: base being blown up in the snow +soviet1.vqa: kill the civillians +sovtstar.vqa: soviets logo +spy.vqa: spy infiltrating building +tanya1.vqa: tanya being interrogated +tanya2.vqa: tanya has been rescued +toofar.vqa: bridge being blown up +trinity.vqa: paris being nuked