From b450abb687823132c9bb3c6b1041bb70bb05d8ea Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 8 Mar 2024 02:02:45 +0300 Subject: [PATCH] Support applying initial values of storyboard commands --- .../Storyboards/Commands/IStoryboardCommand.cs | 14 +++++++++++++- .../Storyboards/Commands/StoryboardAlphaCommand.cs | 8 ++++++-- .../StoryboardBlendingParametersCommand.cs | 9 ++++++--- .../Commands/StoryboardColourCommand.cs | 8 ++++++-- osu.Game/Storyboards/Commands/StoryboardCommand.cs | 12 ++++-------- .../Storyboards/Commands/StoryboardFlipHCommand.cs | 6 ++++-- .../Storyboards/Commands/StoryboardFlipVCommand.cs | 6 ++++-- .../Commands/StoryboardRotationCommand.cs | 6 ++++-- .../Storyboards/Commands/StoryboardScaleCommand.cs | 6 ++++-- .../Commands/StoryboardVectorScaleCommand.cs | 6 ++++-- .../Storyboards/Commands/StoryboardXCommand.cs | 6 ++++-- .../Storyboards/Commands/StoryboardYCommand.cs | 6 ++++-- osu.Game/Storyboards/StoryboardSprite.cs | 10 +++++++++- 13 files changed, 72 insertions(+), 31 deletions(-) diff --git a/osu.Game/Storyboards/Commands/IStoryboardCommand.cs b/osu.Game/Storyboards/Commands/IStoryboardCommand.cs index 848dcab575..05613a987d 100644 --- a/osu.Game/Storyboards/Commands/IStoryboardCommand.cs +++ b/osu.Game/Storyboards/Commands/IStoryboardCommand.cs @@ -18,11 +18,23 @@ namespace osu.Game.Storyboards.Commands /// double EndTime { get; } + /// + /// The name of the property affected by this storyboard command. + /// Used to apply initial property values based on the list of commands given in . + /// + string PropertyName { get; } + + /// + /// Sets the value of the corresponding property in to the start value of this command. + /// + /// The target drawable. + void ApplyInitialValue(Drawable d); + /// /// Applies the transforms described by this storyboard command to the target drawable. /// /// The target drawable. /// The sequence of transforms applied to the target drawable. - TransformSequence ApplyTransform(Drawable d); + TransformSequence ApplyTransforms(Drawable d); } } diff --git a/osu.Game/Storyboards/Commands/StoryboardAlphaCommand.cs b/osu.Game/Storyboards/Commands/StoryboardAlphaCommand.cs index 729ecd72a7..1d91d6ccc1 100644 --- a/osu.Game/Storyboards/Commands/StoryboardAlphaCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardAlphaCommand.cs @@ -13,7 +13,11 @@ namespace osu.Game.Storyboards.Commands { } - public override void SetInitialValue(Drawable d) => d.Alpha = StartValue; - public override TransformSequence ApplyTransform(Drawable d) => d.FadeTo(StartValue).Then().FadeTo(EndValue, Duration, Easing); + public override string PropertyName => nameof(Drawable.Alpha); + + public override void ApplyInitialValue(Drawable d) => d.Alpha = StartValue; + + public override TransformSequence ApplyTransforms(Drawable d) + => d.FadeTo(StartValue).Then().FadeTo(EndValue, Duration, Easing); } } diff --git a/osu.Game/Storyboards/Commands/StoryboardBlendingParametersCommand.cs b/osu.Game/Storyboards/Commands/StoryboardBlendingParametersCommand.cs index cc54909837..3a2d372a66 100644 --- a/osu.Game/Storyboards/Commands/StoryboardBlendingParametersCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardBlendingParametersCommand.cs @@ -13,9 +13,12 @@ namespace osu.Game.Storyboards.Commands { } - public override void SetInitialValue(Drawable d) => d.Blending = StartValue; + public override string PropertyName => nameof(Drawable.Blending); - public override TransformSequence ApplyTransform(Drawable d) - => d.TransformTo(nameof(d.Blending), StartValue).Delay(Duration).TransformTo(nameof(d.Blending), EndValue); + public override void ApplyInitialValue(Drawable d) => d.Blending = StartValue; + + public override TransformSequence ApplyTransforms(Drawable d) + => d.TransformTo(nameof(d.Blending), StartValue).Delay(Duration) + .TransformTo(nameof(d.Blending), EndValue); } } diff --git a/osu.Game/Storyboards/Commands/StoryboardColourCommand.cs b/osu.Game/Storyboards/Commands/StoryboardColourCommand.cs index be56a1d71b..fbde7e1af7 100644 --- a/osu.Game/Storyboards/Commands/StoryboardColourCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardColourCommand.cs @@ -14,7 +14,11 @@ namespace osu.Game.Storyboards.Commands { } - public override void SetInitialValue(Drawable d) => d.Colour = StartValue; - public override TransformSequence ApplyTransform(Drawable d) => d.FadeColour(StartValue).Then().FadeColour(EndValue, Duration, Easing); + public override string PropertyName => nameof(Drawable.Colour); + + public override void ApplyInitialValue(Drawable d) => d.Colour = StartValue; + + public override TransformSequence ApplyTransforms(Drawable d) + => d.FadeColour(StartValue).Then().FadeColour(EndValue, Duration, Easing); } } diff --git a/osu.Game/Storyboards/Commands/StoryboardCommand.cs b/osu.Game/Storyboards/Commands/StoryboardCommand.cs index 1647faf243..58fcb148ff 100644 --- a/osu.Game/Storyboards/Commands/StoryboardCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardCommand.cs @@ -32,15 +32,11 @@ namespace osu.Game.Storyboards.Commands public T StartValue; public T EndValue; - /// - /// Sets the value of the corresponding property in to the start value of this command. - /// - public abstract void SetInitialValue(Drawable d); + public abstract string PropertyName { get; } - /// - /// Transforms a corresponding property in that corresponds to this command group with the specified parameters. - /// - public abstract TransformSequence ApplyTransform(Drawable d); + public abstract void ApplyInitialValue(Drawable d); + + public abstract TransformSequence ApplyTransforms(Drawable d); public int CompareTo(StoryboardCommand? other) { diff --git a/osu.Game/Storyboards/Commands/StoryboardFlipHCommand.cs b/osu.Game/Storyboards/Commands/StoryboardFlipHCommand.cs index 9bcb687d3c..c381b0bb64 100644 --- a/osu.Game/Storyboards/Commands/StoryboardFlipHCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardFlipHCommand.cs @@ -14,9 +14,11 @@ namespace osu.Game.Storyboards.Commands { } - public override void SetInitialValue(Drawable d) => ((IDrawableStoryboardElement)d).FlipH = StartValue; + public override string PropertyName => nameof(IDrawableStoryboardElement.FlipH); - public override TransformSequence ApplyTransform(Drawable d) + public override void ApplyInitialValue(Drawable d) => ((IDrawableStoryboardElement)d).FlipH = StartValue; + + public override TransformSequence ApplyTransforms(Drawable d) => d.TransformTo(nameof(IDrawableStoryboardElement.FlipH), StartValue).Delay(Duration) .TransformTo(nameof(IDrawableStoryboardElement.FlipH), EndValue); } diff --git a/osu.Game/Storyboards/Commands/StoryboardFlipVCommand.cs b/osu.Game/Storyboards/Commands/StoryboardFlipVCommand.cs index 9f1f5faa33..e43e5e9205 100644 --- a/osu.Game/Storyboards/Commands/StoryboardFlipVCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardFlipVCommand.cs @@ -14,9 +14,11 @@ namespace osu.Game.Storyboards.Commands { } - public override void SetInitialValue(Drawable d) => ((IDrawableStoryboardElement)d).FlipV = StartValue; + public override string PropertyName => nameof(IDrawableStoryboardElement.FlipV); - public override TransformSequence ApplyTransform(Drawable d) + public override void ApplyInitialValue(Drawable d) => ((IDrawableStoryboardElement)d).FlipV = StartValue; + + public override TransformSequence ApplyTransforms(Drawable d) => d.TransformTo(nameof(IDrawableStoryboardElement.FlipV), StartValue).Delay(Duration) .TransformTo(nameof(IDrawableStoryboardElement.FlipV), EndValue); } diff --git a/osu.Game/Storyboards/Commands/StoryboardRotationCommand.cs b/osu.Game/Storyboards/Commands/StoryboardRotationCommand.cs index c56dcd130f..2a449af843 100644 --- a/osu.Game/Storyboards/Commands/StoryboardRotationCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardRotationCommand.cs @@ -13,9 +13,11 @@ namespace osu.Game.Storyboards.Commands { } - public override void SetInitialValue(Drawable d) => d.Rotation = StartValue; + public override string PropertyName => nameof(Drawable.Rotation); - public override TransformSequence ApplyTransform(Drawable d) + public override void ApplyInitialValue(Drawable d) => d.Rotation = StartValue; + + public override TransformSequence ApplyTransforms(Drawable d) => d.RotateTo(StartValue).Then().RotateTo(EndValue, Duration, Easing); } } diff --git a/osu.Game/Storyboards/Commands/StoryboardScaleCommand.cs b/osu.Game/Storyboards/Commands/StoryboardScaleCommand.cs index 9dbdd6ebd8..bf9796148c 100644 --- a/osu.Game/Storyboards/Commands/StoryboardScaleCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardScaleCommand.cs @@ -14,9 +14,11 @@ namespace osu.Game.Storyboards.Commands { } - public override void SetInitialValue(Drawable d) => d.Scale = new Vector2(StartValue); + public override string PropertyName => nameof(Drawable.Scale); - public override TransformSequence ApplyTransform(Drawable d) + public override void ApplyInitialValue(Drawable d) => d.Scale = new Vector2(StartValue); + + public override TransformSequence ApplyTransforms(Drawable d) => d.ScaleTo(StartValue).Then().ScaleTo(EndValue, Duration, Easing); } } diff --git a/osu.Game/Storyboards/Commands/StoryboardVectorScaleCommand.cs b/osu.Game/Storyboards/Commands/StoryboardVectorScaleCommand.cs index fefb21b257..638dc6a5ee 100644 --- a/osu.Game/Storyboards/Commands/StoryboardVectorScaleCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardVectorScaleCommand.cs @@ -15,9 +15,11 @@ namespace osu.Game.Storyboards.Commands { } - public override void SetInitialValue(Drawable d) => ((IDrawableStoryboardElement)d).VectorScale = StartValue; + public override string PropertyName => nameof(IDrawableStoryboardElement.VectorScale); - public override TransformSequence ApplyTransform(Drawable d) + public override void ApplyInitialValue(Drawable d) => ((IDrawableStoryboardElement)d).VectorScale = StartValue; + + public override TransformSequence ApplyTransforms(Drawable d) => d.TransformTo(nameof(IDrawableStoryboardElement.VectorScale), StartValue).Then() .TransformTo(nameof(IDrawableStoryboardElement.VectorScale), EndValue, Duration, Easing); } diff --git a/osu.Game/Storyboards/Commands/StoryboardXCommand.cs b/osu.Game/Storyboards/Commands/StoryboardXCommand.cs index a9f9cd4f8f..809a77256c 100644 --- a/osu.Game/Storyboards/Commands/StoryboardXCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardXCommand.cs @@ -13,9 +13,11 @@ namespace osu.Game.Storyboards.Commands { } - public override void SetInitialValue(Drawable d) => d.X = StartValue; + public override string PropertyName => nameof(Drawable.X); - public override TransformSequence ApplyTransform(Drawable d) + public override void ApplyInitialValue(Drawable d) => d.X = StartValue; + + public override TransformSequence ApplyTransforms(Drawable d) => d.MoveToX(StartValue).Then().MoveToX(EndValue, Duration, Easing); } } diff --git a/osu.Game/Storyboards/Commands/StoryboardYCommand.cs b/osu.Game/Storyboards/Commands/StoryboardYCommand.cs index eb30b36720..d054135878 100644 --- a/osu.Game/Storyboards/Commands/StoryboardYCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardYCommand.cs @@ -13,9 +13,11 @@ namespace osu.Game.Storyboards.Commands { } - public override void SetInitialValue(Drawable d) => d.Y = StartValue; + public override string PropertyName => nameof(Drawable.Y); - public override TransformSequence ApplyTransform(Drawable d) + public override void ApplyInitialValue(Drawable d) => d.Y = StartValue; + + public override TransformSequence ApplyTransforms(Drawable d) => d.MoveToY(StartValue).Then().MoveToY(EndValue, Duration, Easing); } } diff --git a/osu.Game/Storyboards/StoryboardSprite.cs b/osu.Game/Storyboards/StoryboardSprite.cs index fc3c5d343c..9d7ab66692 100644 --- a/osu.Game/Storyboards/StoryboardSprite.cs +++ b/osu.Game/Storyboards/StoryboardSprite.cs @@ -131,10 +131,18 @@ namespace osu.Game.Storyboards // if (triggeredGroups != null) // commands = commands.Concat(triggeredGroups.SelectMany(tuple => tuple.Item1.GetAllCommands(tuple.Item2))); + HashSet appliedProperties = new HashSet(); + foreach (var command in commands.OrderBy(c => c.StartTime)) { + if (!appliedProperties.Contains(command.PropertyName)) + { + command.ApplyInitialValue(drawable); + appliedProperties.Add(command.PropertyName); + } + using (drawable.BeginAbsoluteSequence(command.StartTime)) - command.ApplyTransform(drawable); + command.ApplyTransforms(drawable); } }