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
|
|
|
|
|
2019-12-18 14:59:48 +00:00
|
|
|
|
using System;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Storyboards
|
|
|
|
|
{
|
|
|
|
|
public delegate CommandTimeline<T> CommandTimelineSelector<T>(CommandTimelineGroup commandTimelineGroup);
|
|
|
|
|
|
|
|
|
|
public class CommandTimelineGroup
|
|
|
|
|
{
|
|
|
|
|
public CommandTimeline<float> X = new CommandTimeline<float>();
|
|
|
|
|
public CommandTimeline<float> Y = new CommandTimeline<float>();
|
2019-12-18 08:21:38 +00:00
|
|
|
|
public CommandTimeline<float> Scale = new CommandTimeline<float>();
|
|
|
|
|
public CommandTimeline<Vector2> VectorScale = new CommandTimeline<Vector2>();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public CommandTimeline<float> Rotation = new CommandTimeline<float>();
|
|
|
|
|
public CommandTimeline<Color4> Colour = new CommandTimeline<Color4>();
|
|
|
|
|
public CommandTimeline<float> Alpha = new CommandTimeline<float>();
|
2019-08-21 04:29:50 +00:00
|
|
|
|
public CommandTimeline<BlendingParameters> BlendingParameters = new CommandTimeline<BlendingParameters>();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public CommandTimeline<bool> FlipH = new CommandTimeline<bool>();
|
|
|
|
|
public CommandTimeline<bool> FlipV = new CommandTimeline<bool>();
|
|
|
|
|
|
2019-12-18 14:59:48 +00:00
|
|
|
|
private readonly ICommandTimeline[] timelines;
|
|
|
|
|
|
|
|
|
|
public CommandTimelineGroup()
|
|
|
|
|
{
|
|
|
|
|
timelines = new ICommandTimeline[]
|
|
|
|
|
{
|
|
|
|
|
X,
|
|
|
|
|
Y,
|
|
|
|
|
Scale,
|
|
|
|
|
VectorScale,
|
|
|
|
|
Rotation,
|
|
|
|
|
Colour,
|
|
|
|
|
Alpha,
|
|
|
|
|
BlendingParameters,
|
|
|
|
|
FlipH,
|
|
|
|
|
FlipV
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-09 06:55:05 +00:00
|
|
|
|
/// <summary>
|
2021-03-11 03:15:59 +00:00
|
|
|
|
/// Returns the earliest visible time. Will be null unless this group's first <see cref="Alpha"/> command has a start value of zero.
|
2021-03-09 06:55:05 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
public double? EarliestDisplayedTime
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var first = Alpha.Commands.FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
return first?.StartValue == 0 ? first.StartTime : (double?)null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
[JsonIgnore]
|
2019-12-18 14:59:48 +00:00
|
|
|
|
public double CommandsStartTime
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2021-03-09 06:55:05 +00:00
|
|
|
|
// if the first alpha command starts at zero it should be given priority over anything else.
|
|
|
|
|
// this is due to it creating a state where the target is not present before that time, causing any other events to not be visible.
|
2021-10-27 04:04:41 +00:00
|
|
|
|
double? earliestDisplay = EarliestDisplayedTime;
|
2021-03-09 06:55:05 +00:00
|
|
|
|
if (earliestDisplay != null)
|
|
|
|
|
return earliestDisplay.Value;
|
|
|
|
|
|
2019-12-18 14:59:48 +00:00
|
|
|
|
double min = double.MaxValue;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < timelines.Length; i++)
|
|
|
|
|
min = Math.Min(min, timelines[i].StartTime);
|
|
|
|
|
|
|
|
|
|
return min;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[JsonIgnore]
|
2019-12-18 14:59:48 +00:00
|
|
|
|
public double CommandsEndTime
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
double max = double.MinValue;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-12-18 14:59:48 +00:00
|
|
|
|
for (int i = 0; i < timelines.Length; i++)
|
|
|
|
|
max = Math.Max(max, timelines[i].EndTime);
|
|
|
|
|
|
|
|
|
|
return max;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
[JsonIgnore]
|
|
|
|
|
public double CommandsDuration => CommandsEndTime - CommandsStartTime;
|
|
|
|
|
|
|
|
|
|
[JsonIgnore]
|
|
|
|
|
public virtual double StartTime => CommandsStartTime;
|
|
|
|
|
|
|
|
|
|
[JsonIgnore]
|
|
|
|
|
public virtual double EndTime => CommandsEndTime;
|
|
|
|
|
|
|
|
|
|
[JsonIgnore]
|
|
|
|
|
public double Duration => EndTime - StartTime;
|
|
|
|
|
|
|
|
|
|
[JsonIgnore]
|
2019-12-18 14:59:48 +00:00
|
|
|
|
public bool HasCommands
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < timelines.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (timelines[i].HasCommands)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
public virtual IEnumerable<CommandTimeline<T>.TypedCommand> GetCommands<T>(CommandTimelineSelector<T> timelineSelector, double offset = 0)
|
|
|
|
|
{
|
|
|
|
|
if (offset != 0)
|
2019-11-11 11:53:22 +00:00
|
|
|
|
{
|
2018-04-13 09:19:50 +00:00
|
|
|
|
return timelineSelector(this).Commands.Select(command =>
|
|
|
|
|
new CommandTimeline<T>.TypedCommand
|
|
|
|
|
{
|
|
|
|
|
Easing = command.Easing,
|
|
|
|
|
StartTime = offset + command.StartTime,
|
|
|
|
|
EndTime = offset + command.EndTime,
|
|
|
|
|
StartValue = command.StartValue,
|
|
|
|
|
EndValue = command.EndValue,
|
|
|
|
|
});
|
2019-11-11 11:53:22 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
return timelineSelector(this).Commands;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|