2018-01-05 19:21:19 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-09-13 17:22:24 +08:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
2017-09-25 16:40:22 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2017-09-13 17:22:24 +08:00
|
|
|
|
using osu.Game.Storyboards.Drawables;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2017-11-30 04:54:04 +08:00
|
|
|
|
using System;
|
2017-09-13 17:22:24 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Storyboards
|
|
|
|
|
{
|
2017-11-30 04:54:04 +08:00
|
|
|
|
public class Storyboard : IDisposable
|
2017-09-13 17:22:24 +08:00
|
|
|
|
{
|
|
|
|
|
private readonly Dictionary<string, StoryboardLayer> layers = new Dictionary<string, StoryboardLayer>();
|
|
|
|
|
public IEnumerable<StoryboardLayer> Layers => layers.Values;
|
|
|
|
|
|
2018-02-16 11:07:59 +08:00
|
|
|
|
public BeatmapInfo BeatmapInfo = new BeatmapInfo();
|
|
|
|
|
|
2017-09-15 17:23:37 +08:00
|
|
|
|
public bool HasDrawable => Layers.Any(l => l.Elements.Any(e => e.IsDrawable));
|
|
|
|
|
|
2017-09-13 17:22:24 +08:00
|
|
|
|
public Storyboard()
|
|
|
|
|
{
|
|
|
|
|
layers.Add("Background", new StoryboardLayer("Background", 3));
|
|
|
|
|
layers.Add("Fail", new StoryboardLayer("Fail", 2) { EnabledWhenPassing = false, });
|
|
|
|
|
layers.Add("Pass", new StoryboardLayer("Pass", 1) { EnabledWhenFailing = false, });
|
|
|
|
|
layers.Add("Foreground", new StoryboardLayer("Foreground", 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public StoryboardLayer GetLayer(string name)
|
|
|
|
|
{
|
|
|
|
|
StoryboardLayer layer;
|
|
|
|
|
if (!layers.TryGetValue(name, out layer))
|
|
|
|
|
layers[name] = layer = new StoryboardLayer(name, layers.Values.Min(l => l.Depth) - 1);
|
|
|
|
|
|
|
|
|
|
return layer;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-25 16:40:22 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether the beatmap's background should be hidden while this storyboard is being displayed.
|
|
|
|
|
/// </summary>
|
2018-02-16 11:07:59 +08:00
|
|
|
|
public bool ReplacesBackground
|
2017-09-25 16:40:22 +08:00
|
|
|
|
{
|
2018-02-16 11:07:59 +08:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var backgroundPath = BeatmapInfo.BeatmapSet?.Metadata?.BackgroundFile?.ToLowerInvariant();
|
|
|
|
|
if (backgroundPath == null)
|
|
|
|
|
return false;
|
2017-09-25 16:40:22 +08:00
|
|
|
|
|
2018-02-16 11:07:59 +08:00
|
|
|
|
return GetLayer("Background").Elements.Any(e => e.Path.ToLowerInvariant() == backgroundPath);
|
|
|
|
|
}
|
2017-09-25 16:40:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-25 17:03:57 +08:00
|
|
|
|
public DrawableStoryboard CreateDrawable(WorkingBeatmap working = null)
|
|
|
|
|
{
|
|
|
|
|
var drawable = new DrawableStoryboard(this);
|
2018-02-16 11:07:59 +08:00
|
|
|
|
drawable.Width = drawable.Height * (BeatmapInfo.WidescreenStoryboard ? 16 / 9f : 4 / 3f);
|
2017-09-25 17:03:57 +08:00
|
|
|
|
return drawable;
|
|
|
|
|
}
|
2017-11-30 04:54:04 +08:00
|
|
|
|
|
|
|
|
|
#region Disposal
|
|
|
|
|
|
|
|
|
|
~Storyboard()
|
|
|
|
|
{
|
|
|
|
|
Dispose(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
Dispose(true);
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool isDisposed;
|
|
|
|
|
|
|
|
|
|
protected virtual void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
if (isDisposed)
|
|
|
|
|
return;
|
|
|
|
|
isDisposed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2017-09-13 17:22:24 +08:00
|
|
|
|
}
|
|
|
|
|
}
|