Unify MediaGlobal/Scripting.Media PlayFMV* methods
- Improve consistency - Remove dead code - Removed AsyncAction! - Delegate.BeginInvoke is unsupported since .NET Core and throws an "Operation is not supported on this platform." exception.
This commit is contained in:
@@ -1,39 +0,0 @@
|
|||||||
#region Copyright & License Information
|
|
||||||
/*
|
|
||||||
* Copyright (c) The OpenRA Developers and Contributors
|
|
||||||
* 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, either version 3 of
|
|
||||||
* the License, or (at your option) any later version. For more
|
|
||||||
* information, see COPYING.
|
|
||||||
*/
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using OpenRA.Graphics;
|
|
||||||
|
|
||||||
namespace OpenRA.Effects
|
|
||||||
{
|
|
||||||
public class AsyncAction : IEffect
|
|
||||||
{
|
|
||||||
readonly Action a;
|
|
||||||
readonly IAsyncResult ar;
|
|
||||||
|
|
||||||
public AsyncAction(IAsyncResult ar, Action a)
|
|
||||||
{
|
|
||||||
this.a = a;
|
|
||||||
this.ar = ar;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Tick(World world)
|
|
||||||
{
|
|
||||||
if (ar.IsCompleted)
|
|
||||||
{
|
|
||||||
world.AddFrameEndTask(w => { w.Remove(this); a(); });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<IRenderable> Render(WorldRenderer r) { yield break; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -10,15 +10,12 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
|
||||||
using Eluant;
|
using Eluant;
|
||||||
using OpenRA.Effects;
|
|
||||||
using OpenRA.GameRules;
|
using OpenRA.GameRules;
|
||||||
using OpenRA.Mods.Common.Effects;
|
using OpenRA.Mods.Common.Effects;
|
||||||
using OpenRA.Mods.Common.Traits;
|
using OpenRA.Mods.Common.Traits;
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Primitives;
|
||||||
using OpenRA.Scripting;
|
using OpenRA.Scripting;
|
||||||
using OpenRA.Video;
|
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Scripting
|
namespace OpenRA.Mods.Common.Scripting
|
||||||
{
|
{
|
||||||
@@ -96,41 +93,18 @@ namespace OpenRA.Mods.Common.Scripting
|
|||||||
playlist.Stop();
|
playlist.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Desc("Play a VQA video fullscreen. File name has to include the file extension.")]
|
[Desc("Play a video fullscreen. File name has to include the file extension.")]
|
||||||
public void PlayMovieFullscreen(string movie, LuaFunction onPlayComplete = null)
|
public void PlayMovieFullscreen(string videoFileName, LuaFunction onPlayComplete = null)
|
||||||
{
|
{
|
||||||
var onComplete = WrapOnPlayComplete(onPlayComplete);
|
var onComplete = WrapOnPlayComplete(onPlayComplete);
|
||||||
Media.PlayFMVFullscreen(world, movie, onComplete);
|
Media.PlayFMVFullscreen(world, videoFileName, onComplete);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Desc("Play a VQA video in the radar window. File name has to include the file extension. " +
|
[Desc("Play a video in the radar window. File name has to include the file extension.")]
|
||||||
"Returns true on success, if the movie wasn't found the function returns false and the callback is executed.")]
|
public void PlayMovieInRadar(string videoFileName, LuaFunction onPlayComplete = null)
|
||||||
public bool PlayMovieInRadar(string movie, LuaFunction onPlayComplete = null)
|
|
||||||
{
|
{
|
||||||
var onComplete = WrapOnPlayComplete(onPlayComplete);
|
var onComplete = WrapOnPlayComplete(onPlayComplete);
|
||||||
|
Media.PlayFMVInRadar(videoFileName, onComplete);
|
||||||
Stream s;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
s = world.Map.Open(movie);
|
|
||||||
}
|
|
||||||
catch (FileNotFoundException e)
|
|
||||||
{
|
|
||||||
Log.Write("lua", $"Couldn't play movie {e.FileName}! File doesn't exist.");
|
|
||||||
onComplete();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var l = new AsyncLoader(Media.LoadVideo);
|
|
||||||
var ar = l.BeginInvoke(s, null, null);
|
|
||||||
Action onLoadComplete = () =>
|
|
||||||
{
|
|
||||||
Media.StopFMVInRadar();
|
|
||||||
world.AddFrameEndTask(_ => Media.PlayFMVInRadar(l.EndInvoke(ar), onComplete));
|
|
||||||
};
|
|
||||||
|
|
||||||
world.AddFrameEndTask(w => w.Add(new AsyncAction(ar, onLoadComplete)));
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Desc("Display a text message to all players.")]
|
[Desc("Display a text message to all players.")]
|
||||||
@@ -183,8 +157,6 @@ namespace OpenRA.Mods.Common.Scripting
|
|||||||
world.AddFrameEndTask(w => w.Add(new FloatingText(position, c, text, duration)));
|
world.AddFrameEndTask(w => w.Add(new FloatingText(position, c, text, duration)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public delegate IVideo AsyncLoader(Stream s);
|
|
||||||
|
|
||||||
Action WrapOnPlayComplete(LuaFunction onPlayComplete)
|
Action WrapOnPlayComplete(LuaFunction onPlayComplete)
|
||||||
{
|
{
|
||||||
Action onComplete;
|
Action onComplete;
|
||||||
|
|||||||
@@ -12,21 +12,20 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using OpenRA.Mods.Common.Widgets;
|
using OpenRA.Mods.Common.Widgets;
|
||||||
using OpenRA.Video;
|
|
||||||
using OpenRA.Widgets;
|
using OpenRA.Widgets;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Scripting
|
namespace OpenRA.Mods.Common.Scripting
|
||||||
{
|
{
|
||||||
public static class Media
|
public static class Media
|
||||||
{
|
{
|
||||||
public static void PlayFMVFullscreen(World w, string movie, Action onComplete)
|
public static void PlayFMVFullscreen(World w, string videoFileName, Action onComplete)
|
||||||
{
|
{
|
||||||
var playerRoot = Game.OpenWindow(w, "FMVPLAYER");
|
var playerRoot = Game.OpenWindow(w, "FMVPLAYER");
|
||||||
var player = playerRoot.Get<VideoPlayerWidget>("PLAYER");
|
var player = playerRoot.Get<VideoPlayerWidget>("PLAYER");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
player.Load(movie);
|
player.Load(videoFileName);
|
||||||
}
|
}
|
||||||
catch (FileNotFoundException)
|
catch (FileNotFoundException)
|
||||||
{
|
{
|
||||||
@@ -60,10 +59,19 @@ namespace OpenRA.Mods.Common.Scripting
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void PlayFMVInRadar(IVideo movie, Action onComplete)
|
public static void PlayFMVInRadar(string videoFileName, Action onComplete)
|
||||||
{
|
{
|
||||||
var player = Ui.Root.Get<VideoPlayerWidget>("PLAYER");
|
var player = Ui.Root.Get<VideoPlayerWidget>("PLAYER");
|
||||||
player.Open(movie);
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
player.Load(videoFileName);
|
||||||
|
}
|
||||||
|
catch (FileNotFoundException)
|
||||||
|
{
|
||||||
|
onComplete();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
player.PlayThen(() =>
|
player.PlayThen(() =>
|
||||||
{
|
{
|
||||||
@@ -71,16 +79,5 @@ namespace OpenRA.Mods.Common.Scripting
|
|||||||
player.CloseVideo();
|
player.CloseVideo();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void StopFMVInRadar()
|
|
||||||
{
|
|
||||||
var player = Ui.Root.Get<VideoPlayerWidget>("PLAYER");
|
|
||||||
player.Stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IVideo LoadVideo(Stream s)
|
|
||||||
{
|
|
||||||
return VideoLoader.GetVideo(s, true, Game.ModData.VideoLoaders);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user