mirror of
https://github.com/osukey/osukey.git
synced 2025-08-03 14:46:38 +09:00
Animate Additive / FlipH and FlipV.
This commit is contained in:
27
osu.Game/Storyboards/Drawables/DrawablesExtensions.cs
Normal file
27
osu.Game/Storyboards/Drawables/DrawablesExtensions.cs
Normal 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;
|
||||
}
|
||||
}
|
@ -1,11 +1,55 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// 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
|
||||
{
|
||||
public interface IFlippable
|
||||
public interface IFlippable : ITransformable
|
||||
{
|
||||
bool FlipH { 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));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user