mirror of
https://github.com/ppy/osu
synced 2024-12-12 01:48:49 +00:00
93 lines
3.6 KiB
C#
93 lines
3.6 KiB
C#
// 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.
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using osu.Framework.Graphics;
|
|
using osu.Framework.Graphics.Sprites;
|
|
using osu.Framework.Graphics.Textures;
|
|
using osu.Game.Beatmaps;
|
|
using osu.Game.Skinning;
|
|
using osu.Game.Storyboards.Drawables;
|
|
|
|
namespace osu.Game.Storyboards
|
|
{
|
|
public class Storyboard
|
|
{
|
|
private readonly Dictionary<string, StoryboardLayer> layers = new Dictionary<string, StoryboardLayer>();
|
|
public IEnumerable<StoryboardLayer> Layers => layers.Values;
|
|
|
|
public BeatmapInfo BeatmapInfo = new BeatmapInfo();
|
|
|
|
/// <summary>
|
|
/// Whether the storyboard can fall back to skin sprites in case no matching storyboard sprites are found.
|
|
/// </summary>
|
|
public bool UseSkinSprites { get; set; }
|
|
|
|
public bool HasDrawable => Layers.Any(l => l.Elements.Any(e => e.IsDrawable));
|
|
|
|
public double FirstEventTime => Layers.Min(l => l.Elements.FirstOrDefault()?.StartTime ?? 0);
|
|
|
|
/// <summary>
|
|
/// Depth of the currently front-most storyboard layer, excluding the overlay layer.
|
|
/// </summary>
|
|
private int minimumLayerDepth;
|
|
|
|
public Storyboard()
|
|
{
|
|
layers.Add("Video", new StoryboardLayer("Video", 4, false));
|
|
layers.Add("Background", new StoryboardLayer("Background", 3));
|
|
layers.Add("Fail", new StoryboardLayer("Fail", 2) { VisibleWhenPassing = false, });
|
|
layers.Add("Pass", new StoryboardLayer("Pass", 1) { VisibleWhenFailing = false, });
|
|
layers.Add("Foreground", new StoryboardLayer("Foreground", minimumLayerDepth = 0));
|
|
|
|
layers.Add("Overlay", new StoryboardLayer("Overlay", int.MinValue));
|
|
}
|
|
|
|
public StoryboardLayer GetLayer(string name)
|
|
{
|
|
if (!layers.TryGetValue(name, out var layer))
|
|
layers[name] = layer = new StoryboardLayer(name, --minimumLayerDepth);
|
|
|
|
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;
|
|
|
|
return GetLayer("Background").Elements.Any(e => e.Path.ToLowerInvariant() == backgroundPath);
|
|
}
|
|
}
|
|
|
|
public DrawableStoryboard CreateDrawable(WorkingBeatmap working = null)
|
|
{
|
|
var drawable = new DrawableStoryboard(this);
|
|
drawable.Width = drawable.Height * (BeatmapInfo.WidescreenStoryboard ? 16 / 9f : 4 / 3f);
|
|
return drawable;
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|