2019-01-24 08:43:03 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-10-23 06:33:38 +00:00
|
|
|
|
using System;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2020-10-23 06:33:38 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics.Textures;
|
2020-03-13 06:29:11 +00:00
|
|
|
|
using osu.Game.Beatmaps;
|
2020-10-23 06:33:38 +00:00
|
|
|
|
using osu.Game.Skinning;
|
2020-03-13 06:29:11 +00:00
|
|
|
|
using osu.Game.Storyboards.Drawables;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Storyboards
|
|
|
|
|
{
|
2019-05-10 07:31:22 +00:00
|
|
|
|
public class Storyboard
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly Dictionary<string, StoryboardLayer> layers = new Dictionary<string, StoryboardLayer>();
|
|
|
|
|
public IEnumerable<StoryboardLayer> Layers => layers.Values;
|
|
|
|
|
|
|
|
|
|
public BeatmapInfo BeatmapInfo = new BeatmapInfo();
|
|
|
|
|
|
2020-10-19 21:32:04 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether the storyboard can fall back to skin sprites in case no matching storyboard sprites are found.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool UseSkinSprites { get; set; }
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public bool HasDrawable => Layers.Any(l => l.Elements.Any(e => e.IsDrawable));
|
|
|
|
|
|
2019-03-26 07:18:15 +00:00
|
|
|
|
public double FirstEventTime => Layers.Min(l => l.Elements.FirstOrDefault()?.StartTime ?? 0);
|
|
|
|
|
|
2020-05-18 19:01:13 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Depth of the currently front-most storyboard layer, excluding the overlay layer.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int minimumLayerDepth;
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public Storyboard()
|
|
|
|
|
{
|
2020-03-25 03:04:09 +00:00
|
|
|
|
layers.Add("Video", new StoryboardLayer("Video", 4, false));
|
2018-04-13 09:19:50 +00:00
|
|
|
|
layers.Add("Background", new StoryboardLayer("Background", 3));
|
2020-03-25 02:08:08 +00:00
|
|
|
|
layers.Add("Fail", new StoryboardLayer("Fail", 2) { VisibleWhenPassing = false, });
|
|
|
|
|
layers.Add("Pass", new StoryboardLayer("Pass", 1) { VisibleWhenFailing = false, });
|
2020-05-18 19:01:13 +00:00
|
|
|
|
layers.Add("Foreground", new StoryboardLayer("Foreground", minimumLayerDepth = 0));
|
|
|
|
|
|
|
|
|
|
layers.Add("Overlay", new StoryboardLayer("Overlay", int.MinValue));
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public StoryboardLayer GetLayer(string name)
|
|
|
|
|
{
|
2019-11-12 10:22:35 +00:00
|
|
|
|
if (!layers.TryGetValue(name, out var layer))
|
2020-05-18 19:01:13 +00:00
|
|
|
|
layers[name] = layer = new StoryboardLayer(name, --minimumLayerDepth);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
return layer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether the beatmap's background should be hidden while this storyboard is being displayed.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool ReplacesBackground
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var backgroundPath = BeatmapInfo.BeatmapSet?.Metadata?.BackgroundFile?.ToLowerInvariant();
|
|
|
|
|
if (backgroundPath == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
2020-03-13 06:29:11 +00:00
|
|
|
|
return GetLayer("Background").Elements.Any(e => e.Path.ToLowerInvariant() == backgroundPath);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DrawableStoryboard CreateDrawable(WorkingBeatmap working = null)
|
|
|
|
|
{
|
|
|
|
|
var drawable = new DrawableStoryboard(this);
|
2020-03-25 03:04:09 +00:00
|
|
|
|
drawable.Width = drawable.Height * (BeatmapInfo.WidescreenStoryboard ? 16 / 9f : 4 / 3f);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
return drawable;
|
|
|
|
|
}
|
2020-10-23 06:33:38 +00:00
|
|
|
|
|
|
|
|
|
public Drawable CreateSpriteFromResourcePath(string path, TextureStore textureStore)
|
|
|
|
|
{
|
|
|
|
|
Drawable drawable = null;
|
|
|
|
|
var storyboardPath = BeatmapInfo.BeatmapSet?.Files?.Find(f => f.Filename.Equals(path, StringComparison.OrdinalIgnoreCase))?.FileInfo.StoragePath;
|
|
|
|
|
|
|
|
|
|
if (storyboardPath != null)
|
|
|
|
|
drawable = new Sprite { Texture = textureStore.Get(storyboardPath) };
|
|
|
|
|
// if the texture isn't available locally in the beatmap, some storyboards choose to source from the underlying skin lookup hierarchy.
|
|
|
|
|
else if (UseSkinSprites)
|
|
|
|
|
drawable = new SkinnableSprite(path);
|
|
|
|
|
|
|
|
|
|
return drawable;
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|