1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-26 17:52:54 +08:00
osu-lazer/osu.Game/Storyboards/Storyboard.cs

65 lines
2.4 KiB
C#
Raw Normal View History

// 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 17:19:50 +08:00
using System.Collections.Generic;
using System.Linq;
using osu.Game.Beatmaps;
using osu.Game.Storyboards.Drawables;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Storyboards
{
2019-05-10 15:31:22 +08:00
public class Storyboard
2018-04-13 17:19:50 +08:00
{
private readonly Dictionary<string, StoryboardLayer> layers = new Dictionary<string, StoryboardLayer>();
public IEnumerable<StoryboardLayer> Layers => layers.Values;
public BeatmapInfo BeatmapInfo = new BeatmapInfo();
public bool HasDrawable => Layers.Any(l => l.Elements.Any(e => e.IsDrawable));
public double FirstEventTime => Layers.Min(l => l.Elements.FirstOrDefault()?.StartTime ?? 0);
2018-04-13 17:19:50 +08:00
public Storyboard()
{
layers.Add("Video", new StoryboardLayer("Video", 4, false));
2018-04-13 17:19:50 +08:00
layers.Add("Background", new StoryboardLayer("Background", 3));
2020-03-25 10:08:08 +08:00
layers.Add("Fail", new StoryboardLayer("Fail", 2) { VisibleWhenPassing = false, });
layers.Add("Pass", new StoryboardLayer("Pass", 1) { VisibleWhenFailing = false, });
2018-04-13 17:19:50 +08:00
layers.Add("Foreground", new StoryboardLayer("Foreground", 0));
}
public StoryboardLayer GetLayer(string name)
{
2019-11-12 18:22:35 +08:00
if (!layers.TryGetValue(name, out var layer))
2018-04-13 17:19:50 +08:00
layers[name] = layer = new StoryboardLayer(name, layers.Values.Min(l => l.Depth) - 1);
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;
if (GetLayer("Video").Elements.Any())
return true;
return GetLayer("Background").Elements.Any(e => e.Path.ToLowerInvariant() == backgroundPath);
2018-04-13 17:19:50 +08:00
}
}
public DrawableStoryboard CreateDrawable(WorkingBeatmap working = null)
{
var drawable = new DrawableStoryboard(this);
drawable.Width = drawable.Height * (BeatmapInfo.WidescreenStoryboard ? 16 / 9f : 4 / 3f);
2018-04-13 17:19:50 +08:00
return drawable;
}
}
}