1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 06:47:24 +08:00
osu-lazer/osu.Game/Storyboards/CommandTimelineGroup.cs

112 lines
5.0 KiB
C#
Raw Normal View History

2017-09-08 05:55:05 +08:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Transforms;
2017-09-08 05:55:05 +08:00
using osu.Game.Storyboards.Drawables;
using System.Collections.Generic;
using System.Linq;
namespace osu.Game.Storyboards
{
public class CommandTimelineGroup
{
public CommandTimeline<float> X = new CommandTimeline<float>();
public CommandTimeline<float> Y = new CommandTimeline<float>();
public CommandTimeline<Vector2> Scale = new CommandTimeline<Vector2>();
public CommandTimeline<float> Rotation = new CommandTimeline<float>();
public CommandTimeline<Color4> Colour = new CommandTimeline<Color4>();
public CommandTimeline<float> Alpha = new CommandTimeline<float>();
public CommandTimeline<bool> Additive = new CommandTimeline<bool>();
public CommandTimeline<bool> FlipH = new CommandTimeline<bool>();
public CommandTimeline<bool> FlipV = new CommandTimeline<bool>();
2017-09-08 19:04:53 +08:00
public IEnumerable<ICommandTimeline> Timelines
2017-09-08 05:55:05 +08:00
{
get
{
yield return X;
yield return Y;
yield return Scale;
yield return Rotation;
yield return Colour;
yield return Alpha;
yield return Additive;
yield return FlipH;
yield return FlipV;
}
}
2017-09-09 00:03:04 +08:00
public double CommandsStartTime => Timelines.Where(t => t.HasCommands).Min(t => t.StartTime);
public double CommandsEndTime => Timelines.Where(t => t.HasCommands).Max(t => t.EndTime);
public double CommandsDuration => CommandsEndTime - CommandsStartTime;
public virtual double StartTime => CommandsStartTime;
public virtual double EndTime => CommandsEndTime;
public double Duration => EndTime - StartTime;
2017-09-09 00:03:04 +08:00
2017-09-08 05:55:05 +08:00
public bool HasCommands => Timelines.Any(t => t.HasCommands);
public virtual void ApplyTransforms(Drawable drawable, double offset = 0)
2017-09-08 05:55:05 +08:00
{
if (X.HasCommands) drawable.X = X.StartValue;
foreach (var command in X.Commands)
using (drawable.BeginAbsoluteSequence(offset + command.StartTime))
PostProcess(command,
drawable.MoveToX(command.StartValue)
.MoveToX(command.EndValue, command.Duration, command.Easing));
2017-09-08 05:55:05 +08:00
if (Y.HasCommands) drawable.Y = Y.StartValue;
foreach (var command in Y.Commands)
using (drawable.BeginAbsoluteSequence(offset + command.StartTime))
PostProcess(command,
drawable.MoveToY(command.StartValue)
.MoveToY(command.EndValue, command.Duration, command.Easing));
2017-09-08 05:55:05 +08:00
if (Scale.HasCommands) drawable.Scale = Scale.StartValue;
foreach (var command in Scale.Commands)
using (drawable.BeginAbsoluteSequence(offset + command.StartTime))
PostProcess(command,
drawable.ScaleTo(command.StartValue)
.ScaleTo(command.EndValue, command.Duration, command.Easing));
2017-09-08 05:55:05 +08:00
if (Rotation.HasCommands) drawable.Rotation = Rotation.StartValue;
foreach (var command in Rotation.Commands)
using (drawable.BeginAbsoluteSequence(offset + command.StartTime))
PostProcess(command,
drawable.RotateTo(command.StartValue)
.RotateTo(command.EndValue, command.Duration, command.Easing));
2017-09-08 05:55:05 +08:00
if (Colour.HasCommands) drawable.Colour = Colour.StartValue;
foreach (var command in Colour.Commands)
using (drawable.BeginAbsoluteSequence(offset + command.StartTime))
PostProcess(command,
drawable.FadeColour(command.StartValue)
.FadeColour(command.EndValue, command.Duration, command.Easing));
2017-09-08 05:55:05 +08:00
if (Alpha.HasCommands) drawable.Alpha = Alpha.StartValue;
foreach (var command in Alpha.Commands)
using (drawable.BeginAbsoluteSequence(offset + command.StartTime))
PostProcess(command,
drawable.FadeTo(command.StartValue)
.FadeTo(command.EndValue, command.Duration, command.Easing));
2017-09-08 05:55:05 +08:00
if (Additive.HasCommands)
drawable.BlendingMode = BlendingMode.Additive;
var flippable = drawable as IFlippable;
if (flippable != null)
{
flippable.FlipH = FlipH.HasCommands;
flippable.FlipV = FlipV.HasCommands;
}
}
2017-09-08 19:04:53 +08:00
protected virtual void PostProcess(ICommand command, TransformSequence<Drawable> sequence)
{
}
2017-09-08 05:55:05 +08:00
}
}