Add a "Video Player" menu with basic impl; kill the music player widget.

This commit is contained in:
Paul Chote
2010-08-12 18:05:54 +12:00
parent 74500c369c
commit 2c1ab33893
10 changed files with 236 additions and 98 deletions

View File

@@ -222,6 +222,7 @@
<Compile Include="Traits\RepairableBuilding.cs" />
<Compile Include="Traits\Activities\Drag.cs" />
<Compile Include="Widgets\VqaPlayerWidget.cs" />
<Compile Include="Widgets\Delegates\VideoPlayerDelegate.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -20,7 +20,7 @@ namespace OpenRA.Widgets.Delegates
bg.GetWidget("BUTTON_PLAY").OnMouseUp = mi =>
{
var foo = Widget.RootWidget.GetWidget<VqaPlayerWidget>("VIDEOPLAYER");
foo.Load("ally1.vqa");
foo.Load("intro2.vqa");
foo.Play();
/*
if (Sound.MusicStopped)

View File

@@ -0,0 +1,45 @@
#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
namespace OpenRA.Widgets.Delegates
{
public class VideoPlayerDelegate : IWidgetDelegate
{
public VideoPlayerDelegate()
{
var bg = Widget.RootWidget.GetWidget("VIDEOPLAYER_MENU");
var player = bg.GetWidget<VqaPlayerWidget>("VIDEOPLAYER");
bg.GetWidget("BUTTON_PLAY").OnMouseUp = mi =>
{
player.Load("foo.vqa");
player.Play();
return true;
};
bg.GetWidget("BUTTON_STOP").OnMouseUp = mi =>
{
player.Stop();
return true;
};
bg.GetWidget("BUTTON_CLOSE").OnMouseUp = mi => {
player.Stop();
Widget.RootWidget.CloseWindow();
return true;
};
// Menu Buttons
Widget.RootWidget.GetWidget("MAINMENU_BUTTON_VIDEOPLAYER").OnMouseUp = mi => {
Widget.RootWidget.OpenWindow("VIDEOPLAYER_MENU");
return true;
};
}
}
}

View File

@@ -18,11 +18,11 @@ namespace OpenRA.Widgets
{
public class VqaPlayerWidget : Widget
{
float timestep;
Sprite videoSprite;
VqaReader video = null;
string cachedVideo;
float invLength;
float2 videoOrigin, videoSize;
public void Load(string filename)
{
if (filename == cachedVideo)
@@ -30,16 +30,19 @@ namespace OpenRA.Widgets
cachedVideo = filename;
video = new VqaReader(FileSystem.Open(filename));
timestep = 1f/video.Framerate;
invLength = video.Framerate*1f/video.Frames;
var size = OpenRA.Graphics.Util.NextPowerOf2(Math.Max(video.Width, video.Height));
videoSprite = new Sprite(new Sheet(new Size(size,size)), new Rectangle( 0, 0, video.Width, video.Height ), TextureChannel.Alpha);
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);
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);
}
bool playing = false;
Stopwatch sw = new Stopwatch();
bool first;
public override void DrawInner(World world)
{
if (!playing)
@@ -58,8 +61,7 @@ namespace OpenRA.Widgets
if (nextFrame == video.CurrentFrame)
videoSprite.sheet.Texture.SetData(video.FrameData);
}
Game.Renderer.RgbaSpriteRenderer.DrawSprite(videoSprite, new int2(RenderBounds.X,RenderBounds.Y), "chrome");
Game.Renderer.RgbaSpriteRenderer.DrawSprite(videoSprite, videoOrigin, "chrome", videoSize);
}
public void Play()