diff --git a/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs b/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs index cf4700bf85..a9a4d9cc49 100644 --- a/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs @@ -212,7 +212,7 @@ namespace osu.Game.Beatmaps.Formats { float startValue = Parsing.ParseFloat(split[4]); float endValue = split.Length > 5 ? Parsing.ParseFloat(split[5]) : startValue; - timelineGroup?.Scale.Add(easing, startTime, endTime, startValue, endValue); + timelineGroup?.Scale.Add(easing, startTime, endTime, new Vector2(startValue), new Vector2(endValue)); break; } diff --git a/osu.Game/Storyboards/CommandTimeline.cs b/osu.Game/Storyboards/CommandTimeline.cs index 0650c97165..2bb606d2bb 100644 --- a/osu.Game/Storyboards/CommandTimeline.cs +++ b/osu.Game/Storyboards/CommandTimeline.cs @@ -24,6 +24,13 @@ namespace osu.Game.Storyboards public T StartValue { get; private set; } public T EndValue { get; private set; } + public string PropertyName { get; } + + public CommandTimeline(string propertyName) + { + PropertyName = propertyName; + } + public void Add(Easing easing, double startTime, double endTime, T startValue, T endValue) { if (endTime < startTime) @@ -31,7 +38,7 @@ namespace osu.Game.Storyboards endTime = startTime; } - commands.Add(new TypedCommand { Easing = easing, StartTime = startTime, EndTime = endTime, StartValue = startValue, EndValue = endValue }); + commands.Add(new TypedCommand { Easing = easing, StartTime = startTime, EndTime = endTime, StartValue = startValue, EndValue = endValue, PropertyName = PropertyName }); if (startTime < StartTime) { @@ -55,6 +62,7 @@ namespace osu.Game.Storyboards public double StartTime { get; set; } public double EndTime { get; set; } public double Duration => EndTime - StartTime; + public string PropertyName { get; set; } public T StartValue; public T EndValue; diff --git a/osu.Game/Storyboards/CommandTimelineGroup.cs b/osu.Game/Storyboards/CommandTimelineGroup.cs index 0b96db6861..cb795e0ffe 100644 --- a/osu.Game/Storyboards/CommandTimelineGroup.cs +++ b/osu.Game/Storyboards/CommandTimelineGroup.cs @@ -3,11 +3,11 @@ using System; using osuTK; -using osuTK.Graphics; using osu.Framework.Graphics; using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; +using osu.Framework.Graphics.Colour; namespace osu.Game.Storyboards { @@ -15,16 +15,16 @@ namespace osu.Game.Storyboards public class CommandTimelineGroup { - public CommandTimeline X = new CommandTimeline(); - public CommandTimeline Y = new CommandTimeline(); - public CommandTimeline Scale = new CommandTimeline(); - public CommandTimeline VectorScale = new CommandTimeline(); - public CommandTimeline Rotation = new CommandTimeline(); - public CommandTimeline Colour = new CommandTimeline(); - public CommandTimeline Alpha = new CommandTimeline(); - public CommandTimeline BlendingParameters = new CommandTimeline(); - public CommandTimeline FlipH = new CommandTimeline(); - public CommandTimeline FlipV = new CommandTimeline(); + public CommandTimeline X = new CommandTimeline("X"); + public CommandTimeline Y = new CommandTimeline("Y"); + public CommandTimeline Scale = new CommandTimeline("Scale"); + public CommandTimeline VectorScale = new CommandTimeline("VectorScale"); + public CommandTimeline Rotation = new CommandTimeline("Rotation"); + public CommandTimeline Colour = new CommandTimeline("Colour"); + public CommandTimeline Alpha = new CommandTimeline("Alpha"); + public CommandTimeline BlendingParameters = new CommandTimeline("Blending"); + public CommandTimeline FlipH = new CommandTimeline("FlipH"); + public CommandTimeline FlipV = new CommandTimeline("FlipV"); private readonly ICommandTimeline[] timelines; @@ -109,6 +109,7 @@ namespace osu.Game.Storyboards EndTime = offset + command.EndTime, StartValue = command.StartValue, EndValue = command.EndValue, + PropertyName = command.PropertyName }); } diff --git a/osu.Game/Storyboards/StoryboardSprite.cs b/osu.Game/Storyboards/StoryboardSprite.cs index 982185d51b..4d3f1c158f 100644 --- a/osu.Game/Storyboards/StoryboardSprite.cs +++ b/osu.Game/Storyboards/StoryboardSprite.cs @@ -98,8 +98,6 @@ namespace osu.Game.Storyboards private delegate void DrawablePropertyInitializer(Drawable drawable, T value); - private delegate void DrawableTransformer(Drawable drawable, T value, double duration, Easing easing); - public StoryboardSprite(string path, Anchor origin, Vector2 initialPosition) { Path = path; @@ -132,27 +130,23 @@ namespace osu.Game.Storyboards List generated = new List(); - generateCommands(generated, getCommands(g => g.X, triggeredGroups), (d, value) => d.X = value, (d, value, duration, easing) => d.MoveToX(value, duration, easing)); - generateCommands(generated, getCommands(g => g.Y, triggeredGroups), (d, value) => d.Y = value, (d, value, duration, easing) => d.MoveToY(value, duration, easing)); - generateCommands(generated, getCommands(g => g.Scale, triggeredGroups), (d, value) => d.Scale = new Vector2(value), (d, value, duration, easing) => d.ScaleTo(value, duration, easing)); - generateCommands(generated, getCommands(g => g.Rotation, triggeredGroups), (d, value) => d.Rotation = value, (d, value, duration, easing) => d.RotateTo(value, duration, easing)); - generateCommands(generated, getCommands(g => g.Colour, triggeredGroups), (d, value) => d.Colour = value, (d, value, duration, easing) => d.FadeColour(value, duration, easing)); - generateCommands(generated, getCommands(g => g.Alpha, triggeredGroups), (d, value) => d.Alpha = value, (d, value, duration, easing) => d.FadeTo(value, duration, easing)); - generateCommands(generated, getCommands(g => g.BlendingParameters, triggeredGroups), (d, value) => d.Blending = value, (d, value, duration, _) => d.TransformBlendingMode(value, duration), - false); + generateCommands(generated, getCommands(g => g.X, triggeredGroups), (d, value) => d.X = value); + generateCommands(generated, getCommands(g => g.Y, triggeredGroups), (d, value) => d.Y = value); + generateCommands(generated, getCommands(g => g.Scale, triggeredGroups), (d, value) => d.Scale = value); + generateCommands(generated, getCommands(g => g.Rotation, triggeredGroups), (d, value) => d.Rotation = value); + generateCommands(generated, getCommands(g => g.Colour, triggeredGroups), (d, value) => d.Colour = value); + generateCommands(generated, getCommands(g => g.Alpha, triggeredGroups), (d, value) => d.Alpha = value); + generateCommands(generated, getCommands(g => g.BlendingParameters, triggeredGroups), (d, value) => d.Blending = value, false); if (drawable is IVectorScalable vectorScalable) { - generateCommands(generated, getCommands(g => g.VectorScale, triggeredGroups), (_, value) => vectorScalable.VectorScale = value, - (_, value, duration, easing) => vectorScalable.VectorScaleTo(value, duration, easing)); + generateCommands(generated, getCommands(g => g.VectorScale, triggeredGroups), (_, value) => vectorScalable.VectorScale = value); } if (drawable is IFlippable flippable) { - generateCommands(generated, getCommands(g => g.FlipH, triggeredGroups), (_, value) => flippable.FlipH = value, (_, value, duration, _) => flippable.TransformFlipH(value, duration), - false); - generateCommands(generated, getCommands(g => g.FlipV, triggeredGroups), (_, value) => flippable.FlipV = value, (_, value, duration, _) => flippable.TransformFlipV(value, duration), - false); + generateCommands(generated, getCommands(g => g.FlipH, triggeredGroups), (_, value) => flippable.FlipH = value, false); + generateCommands(generated, getCommands(g => g.FlipV, triggeredGroups), (_, value) => flippable.FlipV = value, false); } foreach (var command in generated.OrderBy(g => g.StartTime)) @@ -160,7 +154,7 @@ namespace osu.Game.Storyboards } private void generateCommands(List resultList, IEnumerable.TypedCommand> commands, - DrawablePropertyInitializer initializeProperty, DrawableTransformer transform, bool alwaysInitialize = true) + DrawablePropertyInitializer initializeProperty, bool alwaysInitialize = true) { bool initialized = false; @@ -175,7 +169,7 @@ namespace osu.Game.Storyboards initialized = true; } - resultList.Add(new GeneratedCommand(command, initFunc, transform)); + resultList.Add(new GeneratedCommand(command, initFunc)); } } @@ -209,24 +203,59 @@ namespace osu.Game.Storyboards public double StartTime => command.StartTime; private readonly DrawablePropertyInitializer? initializeProperty; - private readonly DrawableTransformer transform; private readonly CommandTimeline.TypedCommand command; - public GeneratedCommand(CommandTimeline.TypedCommand command, DrawablePropertyInitializer? initializeProperty, DrawableTransformer transform) + public GeneratedCommand(CommandTimeline.TypedCommand command, DrawablePropertyInitializer? initializeProperty) { this.command = command; this.initializeProperty = initializeProperty; - this.transform = transform; } public void ApplyTo(Drawable drawable) { initializeProperty?.Invoke(drawable, command.StartValue); - using (drawable.BeginAbsoluteSequence(command.StartTime)) + switch (command.PropertyName) { - transform(drawable, command.StartValue, 0, Easing.None); - transform(drawable, command.EndValue, command.Duration, command.Easing); + case "VectorScale": + using (drawable.BeginAbsoluteSequence(command.StartTime)) + { + ((IVectorScalable)drawable).TransformTo(command.PropertyName, command.StartValue).Then().TransformTo(command.PropertyName, command.EndValue, command.Duration, command.Easing); + } + + break; + + case "FlipH": + using (drawable.BeginAbsoluteSequence(command.StartTime)) + { + ((IFlippable)drawable).TransformTo(command.PropertyName, command.StartValue).Delay(command.Duration).TransformTo(command.PropertyName, command.EndValue); + } + + break; + + case "FlipV": + using (drawable.BeginAbsoluteSequence(command.StartTime)) + { + ((IFlippable)drawable).TransformTo(command.PropertyName, command.StartValue).Delay(command.Duration).TransformTo(command.PropertyName, command.EndValue); + } + + break; + + case "Blending": + using (drawable.BeginAbsoluteSequence(command.StartTime)) + { + drawable.TransformTo(command.PropertyName, command.StartValue).Delay(command.Duration).TransformTo(command.PropertyName, command.EndValue); + } + + break; + + default: + using (drawable.BeginAbsoluteSequence(command.StartTime)) + { + drawable.TransformTo(command.PropertyName, command.StartValue).Then().TransformTo(command.PropertyName, command.EndValue, command.Duration, command.Easing); + } + + break; } } }