Storyboards implementation.

This commit is contained in:
Damnae
2017-09-07 23:55:05 +02:00
parent c2b16dae10
commit e547416193
20 changed files with 925 additions and 25 deletions

View File

@ -0,0 +1,11 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
namespace osu.Game.Storyboards.Drawables
{
public interface IFlippable
{
bool FlipH { get; set; }
bool FlipV { get; set; }
}
}

View File

@ -0,0 +1,59 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Textures;
using osu.Game.IO;
namespace osu.Game.Storyboards.Drawables
{
public class Storyboard : Container<StoryboardLayer>
{
public StoryboardDefinition Definition { get; private set; }
protected override Vector2 DrawScale => new Vector2(Parent.DrawHeight / 480);
public override bool HandleInput => false;
private bool passing = true;
public bool Passing
{
get { return passing; }
set
{
if (passing == value) return;
passing = value;
updateLayerVisibility();
}
}
private DependencyContainer dependencies;
protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent) =>
dependencies = new DependencyContainer(base.CreateLocalDependencies(parent));
public Storyboard(StoryboardDefinition definition)
{
Definition = definition;
Size = new Vector2(640, 480);
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
}
[BackgroundDependencyLoader]
private void load(FileStore fileStore)
{
dependencies.Cache(new TextureStore(new RawTextureLoaderStore(fileStore.Store), false) { ScaleAdjust = 1, });
foreach (var layerDefinition in Definition.Layers)
Add(layerDefinition.CreateDrawable());
}
private void updateLayerVisibility()
{
foreach (var layer in Children)
layer.Enabled = passing ? layer.Definition.EnabledWhenPassing : layer.Definition.ShowWhenFailing;
}
}
}

View File

@ -0,0 +1,55 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Animations;
using osu.Framework.Graphics.Textures;
using osu.Framework.IO.File;
using System.Linq;
namespace osu.Game.Storyboards.Drawables
{
public class StoryboardAnimation : TextureAnimation, IFlippable
{
public AnimationDefinition Definition { get; private set; }
protected override bool ShouldBeAlive => Definition.HasCommands && base.ShouldBeAlive;
public override bool RemoveWhenNotAlive => !Definition.HasCommands || base.RemoveWhenNotAlive;
public bool FlipH { get; set; }
public bool FlipV { get; set; }
protected override Vector2 DrawScale => new Vector2(FlipH ? -base.DrawScale.X : base.DrawScale.X, FlipV ? -base.DrawScale.Y : base.DrawScale.Y);
public StoryboardAnimation(AnimationDefinition definition)
{
Definition = definition;
Origin = definition.Origin;
Position = definition.InitialPosition;
Repeat = definition.LoopType == AnimationLoopType.LoopForever;
if (definition.HasCommands)
{
LifetimeStart = definition.StartTime;
LifetimeEnd = definition.EndTime;
}
}
[BackgroundDependencyLoader]
private void load(OsuGameBase game, TextureStore textureStore)
{
for (var frame = 0; frame < Definition.FrameCount; frame++)
{
var framePath = Definition.Path.Replace(".", frame + ".");
var path = game.Beatmap.Value.BeatmapSetInfo.Files.FirstOrDefault(f => f.Filename == framePath)?.FileInfo.StoragePath;
if (path == null)
continue;
var texture = textureStore.Get(path);
AddFrame(texture, Definition.FrameDelay);
}
Definition.ApplyTransforms(this);
}
}
}

View File

@ -0,0 +1,37 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
namespace osu.Game.Storyboards.Drawables
{
public class StoryboardLayer : Container
{
public LayerDefinition Definition { get; private set; }
public bool Enabled;
public override bool IsPresent => Enabled && base.IsPresent;
public StoryboardLayer(LayerDefinition definition)
{
Definition = definition;
RelativeSizeAxes = Axes.Both;
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
Enabled = definition.EnabledWhenPassing;
}
[BackgroundDependencyLoader]
private void load()
{
foreach (var element in Definition.Elements)
{
var drawable = element.CreateDrawable();
if (drawable != null)
Add(drawable);
}
}
}
}

View File

@ -0,0 +1,49 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Framework.IO.File;
using System.Linq;
namespace osu.Game.Storyboards.Drawables
{
public class StoryboardSprite : Sprite, IFlippable
{
public SpriteDefinition Definition { get; private set; }
protected override bool ShouldBeAlive => Definition.HasCommands && base.ShouldBeAlive;
public override bool RemoveWhenNotAlive => !Definition.HasCommands || base.RemoveWhenNotAlive;
public bool FlipH { get; set; }
public bool FlipV { get; set; }
protected override Vector2 DrawScale => new Vector2(FlipH ? -base.DrawScale.X : base.DrawScale.X, FlipV ? -base.DrawScale.Y : base.DrawScale.Y);
public StoryboardSprite(SpriteDefinition definition)
{
Definition = definition;
Origin = definition.Origin;
Position = definition.InitialPosition;
if (definition.HasCommands)
{
LifetimeStart = definition.StartTime;
LifetimeEnd = definition.EndTime;
}
}
[BackgroundDependencyLoader]
private void load(OsuGameBase game, TextureStore textureStore)
{
var spritePath = Definition.Path;
var path = game.Beatmap.Value.BeatmapSetInfo.Files.FirstOrDefault(f => f.Filename == spritePath)?.FileInfo.StoragePath;
if (path == null)
return;
Texture = textureStore.Get(path);
Definition.ApplyTransforms(this);
}
}
}