1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 15:47:26 +08:00

Implement IAccented interface + transform.

This commit is contained in:
smoogipooo 2017-03-31 11:01:42 +09:00
parent e335b16ee3
commit d944b8c192
8 changed files with 80 additions and 5 deletions

@ -1 +1 @@
Subproject commit 269a1fd192c573d558a5ab0ff990a8b462947287
Subproject commit 3931f8e358365b1853a76e1d141fcf4c929a2143

View File

@ -0,0 +1,36 @@
// 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.Graphics;
using osu.Framework.Graphics;
using osu.Game.Graphics.Transforms;
namespace osu.Game.Graphics
{
/// <summary>
/// A type of drawable that has an accent colour.
/// The accent colour is used to colorize various objects inside a drawable
/// without colorizing the drawable itself.
/// </summary>
public interface IAccented : IDrawable
{
Color4 AccentColour { get; set; }
}
public static class AccentedExtensions
{
/// <summary>
/// Tweens the accent colour of a drawable to another colour.
/// </summary>
/// <typeparam name="TDrawable">The type of drawable.</typeparam>
/// <param name="drawable">The drawable to apply the accent colour to.</param>
/// <param name="newColour">The new accent colour.</param>
/// <param name="duration">The tween duration.</param>
/// <param name="easing">The tween easing.</param>
public static void FadeAccent<TDrawable>(this TDrawable drawable, Color4 newColour, double duration = 0, EasingTypes easing = EasingTypes.None)
where TDrawable : Drawable, IAccented
{
drawable.TransformTo(drawable.AccentColour, newColour, duration, easing, new TransformAccent());
}
}
}

View File

@ -0,0 +1,37 @@
// 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.Graphics;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Transforms;
using osu.Framework.MathUtils;
namespace osu.Game.Graphics.Transforms
{
public class TransformAccent : Transform<Color4>
{
/// <summary>
/// Current value of the transformed colour in linear colour space.
/// </summary>
public override Color4 CurrentValue
{
get
{
double time = Time?.Current ?? 0;
if (time < StartTime) return StartValue;
if (time >= EndTime) return EndValue;
return Interpolation.ValueAt(time, StartValue, EndValue, StartTime, EndTime, Easing);
}
}
public override void Apply(Drawable d)
{
base.Apply(d);
var accented = d as IAccented;
if (accented != null)
accented.AccentColour = CurrentValue;
}
}
}

View File

@ -47,7 +47,7 @@ namespace osu.Game.Graphics.UserInterface
protected class TransformAccuracy : Transform<double>
{
protected override double CurrentValue
public override double CurrentValue
{
get
{

View File

@ -51,7 +51,7 @@ namespace osu.Game.Graphics.UserInterface
protected class TransformScore : Transform<double>
{
protected override double CurrentValue
public override double CurrentValue
{
get
{

View File

@ -213,7 +213,7 @@ namespace osu.Game.Modes.UI
protected class TransformComboRoll : Transform<int>
{
protected override int CurrentValue
public override int CurrentValue
{
get
{

View File

@ -36,7 +36,7 @@ namespace osu.Game.Modes.UI
protected class TransformComboResult : Transform<ulong>
{
protected override ulong CurrentValue
public override ulong CurrentValue
{
get
{

View File

@ -82,7 +82,9 @@
<Compile Include="Graphics\Backgrounds\Triangles.cs" />
<Compile Include="Graphics\Cursor\CursorTrail.cs" />
<Compile Include="Graphics\Cursor\GameplayCursor.cs" />
<Compile Include="Graphics\IAccented.cs" />
<Compile Include="Graphics\Sprites\OsuSpriteText.cs" />
<Compile Include="Graphics\Transforms\TransformAccent.cs" />
<Compile Include="Graphics\UserInterface\BackButton.cs" />
<Compile Include="Graphics\UserInterface\FocusedTextBox.cs" />
<Compile Include="Graphics\UserInterface\Nub.cs" />