Animate Additive / FlipH and FlipV.

This commit is contained in:
Damnae 2017-09-09 15:34:26 +02:00
parent 8d55cb7f92
commit bc01d9a1b0
6 changed files with 86 additions and 13 deletions

View File

@ -428,9 +428,9 @@ namespace osu.Game.Beatmaps.Formats
var type = split[4]; var type = split[4];
switch (type) switch (type)
{ {
case "A": timelineGroup?.Additive.Add(easing, startTime, endTime, true, true); break; case "A": timelineGroup?.BlendingMode.Add(easing, startTime, endTime, BlendingMode.Additive, startTime == endTime ? BlendingMode.Additive : BlendingMode.Inherit); break;
case "H": timelineGroup?.FlipH.Add(easing, startTime, endTime, true, true); break; case "H": timelineGroup?.FlipH.Add(easing, startTime, endTime, true, startTime == endTime); break;
case "V": timelineGroup?.FlipV.Add(easing, startTime, endTime, true, true); break; case "V": timelineGroup?.FlipV.Add(easing, startTime, endTime, true, startTime == endTime); break;
} }
} }
break; break;

View File

@ -3,6 +3,7 @@
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Framework.Graphics;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -18,7 +19,7 @@ namespace osu.Game.Storyboards
public CommandTimeline<float> Rotation = new CommandTimeline<float>(); public CommandTimeline<float> Rotation = new CommandTimeline<float>();
public CommandTimeline<Color4> Colour = new CommandTimeline<Color4>(); public CommandTimeline<Color4> Colour = new CommandTimeline<Color4>();
public CommandTimeline<float> Alpha = new CommandTimeline<float>(); public CommandTimeline<float> Alpha = new CommandTimeline<float>();
public CommandTimeline<bool> Additive = new CommandTimeline<bool>(); public CommandTimeline<BlendingMode> BlendingMode = new CommandTimeline<BlendingMode>();
public CommandTimeline<bool> FlipH = new CommandTimeline<bool>(); public CommandTimeline<bool> FlipH = new CommandTimeline<bool>();
public CommandTimeline<bool> FlipV = new CommandTimeline<bool>(); public CommandTimeline<bool> FlipV = new CommandTimeline<bool>();
@ -32,7 +33,7 @@ namespace osu.Game.Storyboards
yield return Rotation; yield return Rotation;
yield return Colour; yield return Colour;
yield return Alpha; yield return Alpha;
yield return Additive; yield return BlendingMode;
yield return FlipH; yield return FlipH;
yield return FlipV; yield return FlipV;
} }

View File

@ -0,0 +1,27 @@
using osu.Framework.Graphics;
using osu.Framework.Graphics.Transforms;
namespace osu.Game.Storyboards.Drawables
{
public static class DrawablesExtensions
{
/// <summary>
/// Adjusts <see cref="Drawable.BlendingMode"/> after a delay.
/// </summary>
/// <returns>A <see cref="TransformSequence{T}"/> to which further transforms can be added.</returns>
public static TransformSequence<T> TransformBlendingMode<T>(this T drawable, BlendingMode newValue, double delay = 0)
where T : Drawable
=> drawable.TransformTo(drawable.PopulateTransform(new TransformBlendingMode(), newValue, delay));
}
public class TransformBlendingMode : Transform<BlendingMode, Drawable>
{
private BlendingMode valueAt(double time)
=> time < EndTime ? StartValue : EndValue;
public override string TargetMember => nameof(Drawable.BlendingMode);
protected override void Apply(Drawable d, double time) => d.BlendingMode = valueAt(time);
protected override void ReadIntoStartValue(Drawable d) => StartValue = d.BlendingMode;
}
}

View File

@ -1,11 +1,55 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Graphics;
using osu.Framework.Graphics.Transforms;
namespace osu.Game.Storyboards.Drawables namespace osu.Game.Storyboards.Drawables
{ {
public interface IFlippable public interface IFlippable : ITransformable
{ {
bool FlipH { get; set; } bool FlipH { get; set; }
bool FlipV { get; set; } bool FlipV { get; set; }
} }
public class TransformFlipH : Transform<bool, IFlippable>
{
private bool valueAt(double time)
=> time < EndTime ? StartValue : EndValue;
public override string TargetMember => nameof(IFlippable.FlipH);
protected override void Apply(IFlippable d, double time) => d.FlipH = valueAt(time);
protected override void ReadIntoStartValue(IFlippable d) => StartValue = d.FlipH;
}
public class TransformFlipV : Transform<bool, IFlippable>
{
private bool valueAt(double time)
=> time < EndTime ? StartValue : EndValue;
public override string TargetMember => nameof(IFlippable.FlipV);
protected override void Apply(IFlippable d, double time) => d.FlipV = valueAt(time);
protected override void ReadIntoStartValue(IFlippable d) => StartValue = d.FlipV;
}
public static class FlippableExtensions
{
/// <summary>
/// Adjusts <see cref="IFlippable.FlipH"/> after a delay.
/// </summary>
/// <returns>A <see cref="TransformSequence{T}"/> to which further transforms can be added.</returns>
public static TransformSequence<T> TransformFlipH<T>(this T flippable, bool newValue, double delay = 0)
where T : IFlippable
=> flippable.TransformTo(flippable.PopulateTransform(new TransformFlipH(), newValue, delay));
/// <summary>
/// Adjusts <see cref="IFlippable.FlipV"/> after a delay.
/// </summary>
/// <returns>A <see cref="TransformSequence{T}"/> to which further transforms can be added.</returns>
public static TransformSequence<T> TransformFlipV<T>(this T flippable, bool newValue, double delay = 0)
where T : IFlippable
=> flippable.TransformTo(flippable.PopulateTransform(new TransformFlipV(), newValue, delay));
}
} }

View File

@ -62,27 +62,27 @@ namespace osu.Game.Storyboards
applyCommands(drawable, triggeredGroups, g => g.Rotation, (d, value) => d.Rotation = value, (d, value, duration, easing) => d.RotateTo(value, duration, easing)); applyCommands(drawable, triggeredGroups, g => g.Rotation, (d, value) => d.Rotation = value, (d, value, duration, easing) => d.RotateTo(value, duration, easing));
applyCommands(drawable, triggeredGroups, g => g.Colour, (d, value) => d.Colour = value, (d, value, duration, easing) => d.FadeColour(value, duration, easing)); applyCommands(drawable, triggeredGroups, g => g.Colour, (d, value) => d.Colour = value, (d, value, duration, easing) => d.FadeColour(value, duration, easing));
applyCommands(drawable, triggeredGroups, g => g.Alpha, (d, value) => d.Alpha = value, (d, value, duration, easing) => d.FadeTo(value, duration, easing)); applyCommands(drawable, triggeredGroups, g => g.Alpha, (d, value) => d.Alpha = value, (d, value, duration, easing) => d.FadeTo(value, duration, easing));
applyCommands(drawable, triggeredGroups, g => g.BlendingMode, (d, value) => d.BlendingMode = value, (d, value, duration, easing) => d.TransformBlendingMode(value, duration), false);
if (getAggregatedCommands(g => g.Additive, triggeredGroups).Any())
drawable.BlendingMode = BlendingMode.Additive;
var flippable = drawable as IFlippable; var flippable = drawable as IFlippable;
if (flippable != null) if (flippable != null)
{ {
flippable.FlipH = getAggregatedCommands(g => g.FlipH, triggeredGroups).Any(); applyCommands(drawable, triggeredGroups, g => g.FlipH, (d, value) => flippable.FlipH = value, (d, value, duration, easing) => flippable.TransformFlipH(value, duration), false);
flippable.FlipV = getAggregatedCommands(g => g.FlipV, triggeredGroups).Any(); applyCommands(drawable, triggeredGroups, g => g.FlipV, (d, value) => flippable.FlipV = value, (d, value, duration, easing) => flippable.TransformFlipV(value, duration), false);
} }
} }
private void applyCommands<T>(Drawable drawable, IEnumerable<Tuple<CommandTimelineGroup, double>> triggeredGroups, private void applyCommands<T>(Drawable drawable, IEnumerable<Tuple<CommandTimelineGroup, double>> triggeredGroups,
CommandTimelineSelector<T> timelineSelector, DrawablePropertyInitializer<T> initializeProperty, DrawableTransformer<T> transform) CommandTimelineSelector<T> timelineSelector, DrawablePropertyInitializer<T> initializeProperty, DrawableTransformer<T> transform, bool alwaysInitialize = true)
where T : struct
{ {
var initialized = false; var initialized = false;
foreach (var command in getAggregatedCommands(timelineSelector, triggeredGroups).OrderBy(l => l)) foreach (var command in getAggregatedCommands(timelineSelector, triggeredGroups).OrderBy(l => l))
{ {
if (!initialized) if (!initialized)
{ {
initializeProperty(drawable, command.StartValue); if (alwaysInitialize || command.StartTime == command.EndTime)
initializeProperty.Invoke(drawable, command.StartValue);
initialized = true; initialized = true;
} }
using (drawable.BeginAbsoluteSequence(command.StartTime)) using (drawable.BeginAbsoluteSequence(command.StartTime))

View File

@ -86,6 +86,7 @@
<Compile Include="Storyboards\Drawables\StoryboardAnimation.cs" /> <Compile Include="Storyboards\Drawables\StoryboardAnimation.cs" />
<Compile Include="Storyboards\Drawables\StoryboardSprite.cs" /> <Compile Include="Storyboards\Drawables\StoryboardSprite.cs" />
<Compile Include="Storyboards\AnimationDefinition.cs" /> <Compile Include="Storyboards\AnimationDefinition.cs" />
<Compile Include="Storyboards\Drawables\DrawablesExtensions.cs" />
<Compile Include="Storyboards\IElementDefinition.cs" /> <Compile Include="Storyboards\IElementDefinition.cs" />
<Compile Include="Storyboards\CommandTimeline.cs" /> <Compile Include="Storyboards\CommandTimeline.cs" />
<Compile Include="Storyboards\CommandTimelineGroup.cs" /> <Compile Include="Storyboards\CommandTimelineGroup.cs" />