1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 02:42:54 +08:00

Revert all counter commits. Requires much further review.

This commit is contained in:
Dean Herbert 2016-10-13 14:45:41 +09:00
parent 1a9dede98c
commit 5e3e949fd6
12 changed files with 2 additions and 1141 deletions

View File

@ -1,159 +0,0 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using OpenTK.Input;
using osu.Framework.GameModes.Testing;
using osu.Framework.Graphics;
using osu.Game.Graphics.UserInterface;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Graphics.Transformations;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.MathUtils;
using osu.Framework.Graphics.Sprites;
namespace osu.Desktop.Tests
{
class TestCaseScoreCounter : TestCase
{
public override string Name => @"ScoreCounter";
public override string Description => @"Tests multiple counters";
public override void Reset()
{
base.Reset();
ScoreCounter uc = new ScoreCounter
{
Origin = Anchor.TopRight,
Anchor = Anchor.TopRight,
TextSize = 40,
RollingDuration = 1000,
RollingEasing = EasingTypes.Out,
Count = 0,
Position = new Vector2(20, 20),
LeadingZeroes = 7,
};
Add(uc);
StandardComboCounter sc = new StandardComboCounter
{
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
Position = new Vector2(20, 20),
IsRollingProportional = true,
RollingDuration = 20,
PopOutDuration = 250,
Count = 0,
TextSize = 40,
};
Add(sc);
CatchComboCounter cc = new CatchComboCounter
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
IsRollingProportional = true,
RollingDuration = 20,
PopOutDuration = 250,
Count = 0,
TextSize = 40,
};
Add(cc);
AlternativeComboCounter ac = new AlternativeComboCounter
{
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
Position = new Vector2(20, 80),
IsRollingProportional = true,
RollingDuration = 20,
ScaleFactor = 2,
Count = 0,
TextSize = 40,
};
Add(ac);
AccuracyCounter pc = new AccuracyCounter
{
Origin = Anchor.TopRight,
Anchor = Anchor.TopRight,
RollingDuration = 1000,
RollingEasing = EasingTypes.Out,
Count = 100.0f,
Position = new Vector2(20, 60),
};
Add(pc);
SpriteText text = new SpriteText
{
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
Position = new Vector2(20, 190),
Text = @"- unset -",
};
Add(text);
StarCounter tc = new StarCounter
{
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
Position = new Vector2(20, 160),
};
Add(tc);
AddButton(@"Reset all", delegate
{
uc.Count = 0;
sc.Count = 0;
ac.Count = 0;
cc.Count = 0;
pc.SetCount(0, 0);
tc.Count = 0;
text.Text = tc.Count.ToString("0.00");
});
AddButton(@"Hit! :D", delegate
{
uc.Count += 300 + (ulong)(300.0 * (sc.Count > 0 ? sc.Count - 1 : 0) / 25.0);
sc.Count++;
ac.Count++;
cc.CatchFruit(new Color4(
Math.Max(0.5f, RNG.NextSingle()),
Math.Max(0.5f, RNG.NextSingle()),
Math.Max(0.5f, RNG.NextSingle()),
1)
);
pc.Numerator++;
pc.Denominator++;
});
AddButton(@"miss...", delegate
{
sc.Count = 0;
ac.Count = 0;
cc.Count = 0;
pc.Denominator++;
});
AddButton(@"Alter stars", delegate
{
tc.Count = RNG.NextSingle() * (tc.MaxStars + 1);
text.Text = tc.Count.ToString("0.00");
});
AddButton(@"Stop counters", delegate
{
uc.StopRolling();
sc.StopRolling();
cc.StopRolling();
ac.StopRolling();
pc.StopRolling();
tc.StopRolling();
});
}
}
}

View File

@ -140,7 +140,6 @@
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Tests\TestCaseChatDisplay.cs" /> <Compile Include="Tests\TestCaseChatDisplay.cs" />
<Compile Include="Tests\TestCaseGamefield.cs" /> <Compile Include="Tests\TestCaseGamefield.cs" />
<Compile Include="Tests\TestCaseScoreCounter.cs" />
<Compile Include="Tests\TestCaseKeyCounter.cs" /> <Compile Include="Tests\TestCaseKeyCounter.cs" />
<Compile Include="Tests\TestCaseMenuButtonSystem.cs" /> <Compile Include="Tests\TestCaseMenuButtonSystem.cs" />
<Compile Include="Tests\TestCaseTextAwesome.cs" /> <Compile Include="Tests\TestCaseTextAwesome.cs" />

View File

@ -1,102 +0,0 @@
//Copyright (c) 2007-2016 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.Transformations;
using osu.Framework.MathUtils;
using osu.Framework.Timing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace osu.Game.Graphics.UserInterface
{
/// <summary>
/// Used as an accuracy counter. Represented visually as a percentage, internally as a fraction.
/// </summary>
public class AccuracyCounter : NumericRollingCounter<float>
{
protected override Type transformType => typeof(TransformAccuracy);
private long numerator = 0;
public long Numerator
{
get
{
return numerator;
}
set
{
numerator = value;
updateCount();
}
}
private ulong denominator = 0;
public ulong Denominator
{
get
{
return denominator;
}
set
{
denominator = value;
updateCount();
}
}
public void SetCount(long num, ulong den)
{
numerator = num;
denominator = den;
updateCount();
}
private void updateCount()
{
Count = Denominator == 0 ? 100.0f : (Numerator * 100.0f) / Denominator;
}
public override void ResetCount()
{
numerator = 0;
denominator = 0;
updateCount();
StopRolling();
}
protected override string formatCount(float count)
{
return count.ToString("0.00") + "%";
}
protected class TransformAccuracy : Transform<float>
{
public override float CurrentValue
{
get
{
double time = Time;
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);
(d as AccuracyCounter).VisibleCount = CurrentValue;
}
public TransformAccuracy(IClock clock)
: base(clock)
{
}
}
}
}

View File

@ -1,91 +0,0 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using OpenTK.Graphics;
using osu.Framework;
using osu.Framework.Graphics.Transformations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace osu.Game.Graphics.UserInterface
{
/// <summary>
/// Allows tint and vertical scaling animation. Used in osu!taiko and osu!mania.
/// </summary>
public class AlternativeComboCounter : ULongCounter // btw, I'm terribly bad with names... OUENDAN!
{
public Color4 OriginalColour;
public Color4 TintColour = Color4.OrangeRed;
public int TintDuration = 250;
public float ScaleFactor = 2;
public EasingTypes TintEasing = EasingTypes.None;
public bool CanAnimateWhenBackwards = false;
public AlternativeComboCounter() : base()
{
IsRollingContinuous = false;
}
public override void Load(BaseGame game)
{
base.Load(game);
countSpriteText.Hide();
OriginalColour = Colour;
}
public override void ResetCount()
{
SetCountWithoutRolling(0);
}
protected override void transformCount(ulong currentValue, ulong newValue)
{
// Animate rollover only when going backwards
if (newValue > currentValue)
{
updateTransforms(typeof(TransformULongCounter));
removeTransforms(typeof(TransformULongCounter));
VisibleCount = newValue;
}
else
transformCount(new TransformULongCounter(Clock), currentValue, newValue);
}
protected override ulong getProportionalDuration(ulong currentValue, ulong newValue)
{
ulong difference = currentValue > newValue ? currentValue - newValue : currentValue - newValue;
return difference * RollingDuration;
}
protected virtual void transformAnimate()
{
countSpriteText.FadeColour(TintColour, 0);
countSpriteText.ScaleTo(new Vector2(1, ScaleFactor));
countSpriteText.FadeColour(OriginalColour, TintDuration, TintEasing);
countSpriteText.ScaleTo(new Vector2(1, 1), TintDuration, TintEasing);
}
protected override void transformVisibleCount(ulong currentValue, ulong newValue)
{
if (countSpriteText != null)
{
countSpriteText.Text = newValue.ToString("#,0");
if (newValue == 0)
{
countSpriteText.FadeOut(TintDuration);
return;
}
countSpriteText.Show();
if (newValue > currentValue || CanAnimateWhenBackwards)
{
transformAnimate();
}
}
}
}
}

View File

@ -1,60 +0,0 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace osu.Game.Graphics.UserInterface
{
/// <summary>
/// Similar to Standard, but without the 'x' and has tinted pop-ups. Used in osu!catch.
/// </summary>
public class CatchComboCounter : StandardComboCounter
{
public CatchComboCounter() : base()
{
CanPopOutWhenBackwards = true;
}
protected override string formatCount(ulong count)
{
return count.ToString("#,0");
}
protected override void transformCount(ulong currentValue, ulong newValue)
{
// Animate rollover only when going backwards
if (newValue > currentValue)
{
updateTransforms(typeof(TransformULongCounter));
removeTransforms(typeof(TransformULongCounter));
VisibleCount = newValue;
}
else
{
// Backwards pop-up animation has no tint colour
popOutSpriteText.Colour = countSpriteText.Colour;
transformCount(new TransformULongCounter(Clock), currentValue, newValue);
}
}
/// <summary>
/// Increaces counter and tints pop-out before animation.
/// </summary>
/// <param name="colour">Last grabbed fruit colour.</param>
public void CatchFruit(Color4 colour)
{
popOutSpriteText.Colour = colour;
Count++;
}
public override void ResetCount()
{
base.ResetCount();
}
}
}

View File

@ -1,65 +0,0 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace osu.Game.Graphics.UserInterface
{
/// <summary>
/// Skeleton for a numeric counter with a simple roll-up animation.
/// </summary>
/// <typeparam name="T">Type of the actual counter.</typeparam>
public abstract class NumericRollingCounter<T> : RollingCounter<T>
{
protected SpriteText countSpriteText;
protected float textSize = 20.0f;
public float TextSize
{
get { return textSize; }
set
{
textSize = value;
updateTextSize();
}
}
public override void Load(BaseGame game)
{
base.Load(game);
Children = new Drawable[]
{
countSpriteText = new SpriteText
{
Text = formatCount(Count),
TextSize = this.TextSize,
Anchor = this.Anchor,
Origin = this.Origin,
},
};
}
protected override void transformVisibleCount(T currentValue, T newValue)
{
if (countSpriteText != null)
{
countSpriteText.Text = formatCount(newValue);
}
}
protected virtual void updateTextSize()
{
if (countSpriteText != null)
countSpriteText.TextSize = TextSize;
}
}
}

View File

@ -1,241 +0,0 @@
using osu.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Transformations;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace osu.Game.Graphics.UserInterface
{
/// <summary>
/// Skeleton for a counter which value rolls-up in a lapse of time.
/// </summary>
/// <remarks>
/// This class only abstracts the basics to roll-up a value in a lapse of time by using Transforms.
/// In order to show a value, you must implement a way to display it, i.e., as a numeric counter or a bar.
/// </remarks>
/// <typeparam name="T">Type of the actual counter.</typeparam>
public abstract class RollingCounter<T> : Container
{
/// <summary>
/// Type of the Transform to use.
/// </summary>
/// <remarks>
/// Must be a subclass of Transform<T>
/// </remarks>
protected virtual Type transformType => typeof(Transform<T>);
protected ulong RollingTotalDuration = 0;
/// <summary>
/// If true, each time the Count is updated, it will roll over from the current visible value.
/// Else, it will roll up from the current count value.
/// </summary>
public bool IsRollingContinuous = true;
/// <summary>
/// If true, the roll-up duration will be proportional to the counter.
/// </summary>
public bool IsRollingProportional = false;
/// <summary>
/// If IsRollingProportional = false, duration in milliseconds for the counter roll-up animation for each
/// element; else duration in milliseconds for the counter roll-up animation in total.
/// </summary>
public ulong RollingDuration = 0;
/// <summary>
/// Easing for the counter rollover animation.
/// </summary>
public EasingTypes RollingEasing = EasingTypes.None;
protected T prevVisibleCount;
protected T visibleCount;
/// <summary>
/// Value shown at the current moment.
/// </summary>
public virtual T VisibleCount
{
get
{
return visibleCount;
}
protected set
{
prevVisibleCount = visibleCount;
if (visibleCount.Equals(value))
return;
visibleCount = value;
transformVisibleCount(prevVisibleCount, value);
}
}
protected T prevCount;
protected T count;
/// <summary>
/// Actual value of counter.
/// </summary>
public virtual T Count
{
get
{
return count;
}
set
{
prevCount = count;
count = value;
if (Clock != null)
{
RollingTotalDuration =
IsRollingProportional
? getProportionalDuration(VisibleCount, value)
: RollingDuration;
transformCount(IsRollingContinuous ? VisibleCount : prevCount, value);
}
}
}
protected RollingCounter()
{
Debug.Assert(
transformType.IsSubclassOf(typeof(Transform<T>)) || transformType == typeof(Transform<T>),
@"transformType should be a subclass of Transform<T>."
);
}
public override void Load(BaseGame game)
{
base.Load(game);
removeTransforms(transformType);
if (Count == null)
ResetCount();
VisibleCount = Count;
}
/// <summary>
/// Sets count value, bypassing rollover animation.
/// </summary>
/// <param name="count">New count value.</param>
public virtual void SetCountWithoutRolling(T count)
{
Count = count;
StopRolling();
}
/// <summary>
/// Stops rollover animation, forcing the visible count to be the actual count.
/// </summary>
public virtual void StopRolling()
{
removeTransforms(transformType);
VisibleCount = Count;
}
/// <summary>
/// Resets count to default value.
/// </summary>
public abstract void ResetCount();
/// <summary>
/// Calculates the duration of the roll-up animation by using the difference between the current visible value
/// and the new final value.
/// </summary>
/// <remarks>
/// To be used in conjunction with IsRollingProportional = true.
/// Unless a derived class needs to have a proportional rolling, it is not necessary to override this function.
/// </remarks>
/// <param name="currentValue">Current visible value.</param>
/// <param name="newValue">New final value.</param>
/// <returns>Calculated rollover duration in milliseconds.</returns>
protected virtual ulong getProportionalDuration(T currentValue, T newValue)
{
return RollingDuration;
}
/// <summary>
/// Used to format counts.
/// </summary>
/// <param name="count">Count to format.</param>
/// <returns>Count formatted as a string.</returns>
protected virtual string formatCount(T count)
{
return count.ToString();
}
protected void updateTransforms(Type type)
{
foreach (ITransform t in Transforms.AliveItems)
if (t.GetType() == type)
t.Apply(this);
}
protected void removeTransforms(Type type)
{
Transforms.RemoveAll(t => t.GetType() == type);
}
/// <summary>
/// Called when the count is updated to add a transformer that changes the value of the visible count (i.e.
/// implement the rollover animation).
/// </summary>
/// <param name="currentValue">Count value before modification.</param>
/// <param name="newValue">Expected count value after modification-</param>
/// <remarks>
/// Unless you need to set a custom animation according to the current or new value of the count, the
/// recommended approach is to call transformCount(CustomTransformer(Clock), currentValue, newValue), where
/// CustomTransformer is of type transformerType.
/// By using this approach, there is no need to check if the Clock is not null; this validation is done before
/// adding the transformer.
/// </remarks>
/// <seealso cref="transformType"/>
protected virtual void transformCount(T currentValue, T newValue)
{
object[] parameters = { Clock };
transformCount((Transform<T>)Activator.CreateInstance(transformType, parameters), currentValue, newValue);
}
/// <summary>
/// Intended to be used by transformCount().
/// </summary>
/// <see cref="transformCount"/>
protected void transformCount(Transform<T> transform, T currentValue, T newValue)
{
Type type = transform.GetType();
updateTransforms(type);
removeTransforms(type);
if (Clock == null)
return;
if (RollingDuration == 0)
{
VisibleCount = Count;
return;
}
transform.StartTime = Time;
transform.EndTime = Time + RollingTotalDuration;
transform.StartValue = currentValue;
transform.EndValue = newValue;
transform.Easing = RollingEasing;
Transforms.Add(transform);
}
/// <summary>
/// This procedure is called each time the visible count value is updated.
/// Override to create custom animations.
/// </summary>
/// <param name="currentValue">Visible count value before modification.</param>
/// <param name="newValue">Expected visible count value after modification-</param>
protected abstract void transformVisibleCount(T currentValue, T newValue);
}
}

View File

@ -1,32 +0,0 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace osu.Game.Graphics.UserInterface
{
public class ScoreCounter : ULongCounter
{
/// <summary>
/// How many leading zeroes the counter will have.
/// </summary>
public uint LeadingZeroes = 0;
public override void Load(BaseGame game)
{
base.Load(game);
countSpriteText.FixedWidth = true;
}
protected override string formatCount(ulong count)
{
return count.ToString("D" + LeadingZeroes);
}
}
}

View File

@ -1,110 +0,0 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Transformations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace osu.Game.Graphics.UserInterface
{
/// <summary>
/// Uses the 'x' symbol and has a pop-out effect while rolling over. Used in osu! standard.
/// </summary>
public class StandardComboCounter : ULongCounter
{
public SpriteText popOutSpriteText;
public ulong PopOutDuration = 0;
public float PopOutBigScale = 2.0f;
public float PopOutSmallScale = 1.2f;
public EasingTypes PopOutEasing = EasingTypes.None;
public bool CanPopOutWhenBackwards = false;
public float PopOutInitialAlpha = 0.75f;
public StandardComboCounter() : base()
{
IsRollingContinuous = false;
}
public override void Load(BaseGame game)
{
base.Load(game);
countSpriteText.Alpha = 0;
Add(popOutSpriteText = new SpriteText
{
Text = formatCount(Count),
Origin = this.Origin,
Anchor = this.Anchor,
TextSize = this.TextSize,
Alpha = 0,
});
}
protected override void updateTextSize()
{
base.updateTextSize();
if (popOutSpriteText != null)
popOutSpriteText.TextSize = this.TextSize;
}
protected override void transformCount(ulong currentValue, ulong newValue)
{
// Animate rollover only when going backwards
if (newValue > currentValue)
{
updateTransforms(typeof(TransformULongCounter));
removeTransforms(typeof(TransformULongCounter));
VisibleCount = newValue;
}
else
transformCount(new TransformULongCounter(Clock), currentValue, newValue);
}
protected override ulong getProportionalDuration(ulong currentValue, ulong newValue)
{
ulong difference = currentValue > newValue ? currentValue - newValue : currentValue - newValue;
return difference * RollingDuration;
}
protected override string formatCount(ulong count)
{
return count.ToString("#,0") + "x";
}
protected virtual void transformPopOut()
{
countSpriteText.ScaleTo(PopOutSmallScale);
countSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing);
popOutSpriteText.ScaleTo(PopOutBigScale);
popOutSpriteText.FadeTo(PopOutInitialAlpha);
popOutSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing);
popOutSpriteText.FadeOut(PopOutDuration, PopOutEasing);
}
protected override void transformVisibleCount(ulong currentValue, ulong newValue)
{
if (countSpriteText != null && popOutSpriteText != null)
{
countSpriteText.Text = popOutSpriteText.Text = formatCount(newValue);
if (newValue == 0)
{
countSpriteText.FadeOut(PopOutDuration);
}
else
{
countSpriteText.Show();
if (newValue > currentValue || CanPopOutWhenBackwards)
transformPopOut();
}
}
}
}
}

View File

@ -1,205 +0,0 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using osu.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Transformations;
using osu.Framework.MathUtils;
using osu.Framework.Timing;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace osu.Game.Graphics.UserInterface
{
/// <summary>
/// Shows a float count as stars. Used as star difficulty display.
/// </summary>
public class StarCounter : RollingCounter<float>
{
protected override Type transformType => typeof(TransformStarCounter);
protected Container starContainer;
protected List<TextAwesome> stars = new List<TextAwesome>();
public ulong StarAnimationDuration = 500;
public EasingTypes StarAnimationEasing = EasingTypes.OutElasticHalf;
public ulong FadeDuration = 100;
public float MinStarSize = 0.3f;
public float MinStarAlpha = 0.5f;
public int MaxStars = 10;
public int StarSize = 20;
public int StarSpacing = 4;
public StarCounter() : base()
{
IsRollingProportional = true;
RollingDuration = 150;
}
protected override ulong getProportionalDuration(float currentValue, float newValue)
{
return (ulong)(Math.Abs(currentValue - newValue) * RollingDuration);
}
public override void ResetCount()
{
Count = 0;
StopRolling();
}
public override void Load(BaseGame game)
{
base.Load(game);
Children = new Drawable[]
{
starContainer = new Container
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Width = MaxStars * StarSize + Math.Max(MaxStars - 1, 0) * StarSpacing,
Height = StarSize,
}
};
for (int i = 0; i < MaxStars; i++)
{
TextAwesome star = new TextAwesome
{
Icon = FontAwesome.star,
Anchor = Anchor.CentreLeft,
Origin = Anchor.Centre,
TextSize = StarSize,
Scale = new Vector2(MinStarSize),
Alpha = (i == 0) ? 1.0f : MinStarAlpha,
Position = new Vector2((StarSize + StarSpacing) * i + (StarSize + StarSpacing) / 2, 0),
};
//todo: user Container<T> once we have it.
stars.Add(star);
starContainer.Add(star);
}
ResetCount();
}
protected override void transformCount(float currentValue, float newValue)
{
transformStar((int)Math.Floor(currentValue), currentValue, currentValue < newValue);
transformCount(new TransformStarCounter(Clock), currentValue, newValue);
}
protected void updateTransformStar(int i)
{
foreach (ITransform t in stars[i].Transforms.AliveItems)
if (t.GetType() == typeof(TransformAlpha) || t.GetType() == typeof(TransformScaleVector))
t.Apply(stars[i]);
stars[i].Transforms.RemoveAll(t =>
t.GetType() == typeof(TransformScaleVector) || t.GetType() == typeof(TransformAlpha)
);
}
protected void transformStarScale(int i, TransformScaleVector transform, bool isIncrement, double startTime)
{
transform.StartTime = startTime;
transform.EndTime = transform.StartTime + StarAnimationDuration;
transform.StartValue = stars[i].Scale;
transform.EndValue = new Vector2(
Interpolation.ValueAt(
Math.Min(Math.Max(i, Count), i + 1),
MinStarSize,
1.0f,
i,
i + 1
)
);
transform.Easing = StarAnimationEasing;
stars[i].Transforms.Add(transform);
}
protected void transformStarAlpha(int i, TransformAlpha transform, bool isIncrement, double startTime)
{
transform.StartTime = startTime;
//if (!isIncrement)
//transform.StartTime += StarAnimationDuration - FadeDuration;
transform.EndTime = transform.StartTime + FadeDuration;
transform.StartValue = stars[i].Alpha;
transform.EndValue = i < Count ? 1.0f : MinStarAlpha;
stars[i].Transforms.Add(transform);
}
protected void transformStar(int i, float value, bool isIncrement)
{
if (i >= MaxStars)
return;
if (Clock == null)
return;
// Calculate time where animation should had started
double startTime = Time;
// If incrementing, animation should had started when VisibleCount crossed start of star (i)
if (isIncrement)
startTime -= i == (int)Math.Floor(prevCount) ?
getProportionalDuration(prevCount, value) : getProportionalDuration(i, value);
// If decrementing, animation should had started when VisibleCount crossed end of star (i + 1)
else
startTime -= i == (int)Math.Floor(prevCount) ?
getProportionalDuration(prevCount, value) : getProportionalDuration(i + 1, value);
updateTransformStar(i);
transformStarScale(i, new TransformScaleVector(Clock), isIncrement, startTime);
transformStarAlpha(i, new TransformAlpha(Clock), isIncrement, startTime);
}
protected override void transformVisibleCount(float currentValue, float newValue)
{
// Detect increment that passes over an integer value
if (Math.Ceiling(currentValue) <= Math.Floor(newValue))
for (int i = (int)Math.Ceiling(currentValue); i <= Math.Floor(newValue); i++)
transformStar(i, newValue, true);
// Detect decrement that passes over an integer value
if (Math.Floor(currentValue) >= Math.Ceiling(newValue))
for (int i = (int)Math.Floor(newValue); i < Math.Floor(currentValue); i++)
transformStar(i, newValue, false);
}
protected class TransformStarCounter : Transform<float>
{
public override float CurrentValue
{
get
{
double time = Time;
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);
(d as StarCounter).VisibleCount = CurrentValue;
}
public TransformStarCounter(IClock clock)
: base(clock)
{
}
}
}
}

View File

@ -1,59 +0,0 @@
//Copyright (c) 2007-2016 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.Transformations;
using osu.Framework.MathUtils;
using osu.Framework.Timing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace osu.Game.Graphics.UserInterface
{
/// <summary>
/// A simple rolling counter that accepts unsigned long values.
/// </summary>
public class ULongCounter : NumericRollingCounter<ulong>
{
protected override Type transformType => typeof(TransformULongCounter);
public override void ResetCount()
{
SetCountWithoutRolling(0);
}
protected override string formatCount(ulong count)
{
return count.ToString("#,0");
}
protected class TransformULongCounter : Transform<ulong>
{
public override ulong CurrentValue
{
get
{
double time = Time;
if (time < StartTime) return StartValue;
if (time >= EndTime) return EndValue;
return (ulong)Interpolation.ValueAt(time, StartValue, EndValue, StartTime, EndTime, Easing);
}
}
public override void Apply(Drawable d)
{
base.Apply(d);
(d as ULongCounter).VisibleCount = CurrentValue;
}
public TransformULongCounter(IClock clock)
: base(clock)
{
}
}
}
}

View File

@ -136,19 +136,10 @@
<Compile Include="Graphics\Cursor\OsuCursorContainer.cs" /> <Compile Include="Graphics\Cursor\OsuCursorContainer.cs" />
<Compile Include="Graphics\Processing\RatioAdjust.cs" /> <Compile Include="Graphics\Processing\RatioAdjust.cs" />
<Compile Include="Graphics\TextAwesome.cs" /> <Compile Include="Graphics\TextAwesome.cs" />
<Compile Include="Graphics\UserInterface\AlternativeComboCounter.cs" />
<Compile Include="Graphics\UserInterface\RollingCounter.cs" />
<Compile Include="Graphics\UserInterface\KeyCounter.cs" /> <Compile Include="Graphics\UserInterface\KeyCounter.cs" />
<Compile Include="Graphics\UserInterface\KeyCounterKeyboard.cs" /> <Compile Include="Graphics\UserInterface\KeyCounterKeyboard.cs" />
<Compile Include="Graphics\UserInterface\KeyCounterCollection.cs" /> <Compile Include="Graphics\UserInterface\KeyCounterCollection.cs" />
<Compile Include="Graphics\UserInterface\KeyCounterMouse.cs" /> <Compile Include="Graphics\UserInterface\KeyCounterMouse.cs" />
<Compile Include="Graphics\UserInterface\AccuracyCounter.cs" />
<Compile Include="Graphics\UserInterface\NumericRollingCounter.cs" />
<Compile Include="Graphics\UserInterface\ScoreCounter.cs" />
<Compile Include="Graphics\UserInterface\CatchComboCounter.cs" />
<Compile Include="Graphics\UserInterface\StandardComboCounter.cs" />
<Compile Include="Graphics\UserInterface\StarCounter.cs" />
<Compile Include="Graphics\UserInterface\ULongCounter.cs" />
<Compile Include="Online\API\APIAccess.cs" /> <Compile Include="Online\API\APIAccess.cs" />
<Compile Include="Online\API\APIRequest.cs" /> <Compile Include="Online\API\APIRequest.cs" />
<Compile Include="Online\API\OAuth.cs" /> <Compile Include="Online\API\OAuth.cs" />
@ -197,12 +188,7 @@
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<ItemGroup /> <ItemGroup />
<ItemGroup> <ItemGroup />
<Folder Include="Database\" />
<Folder Include="Beatmaps\Formats\" />
<Folder Include="Beatmaps\IO\" />
<Folder Include="Beatmaps\Events\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.
@ -214,4 +200,4 @@
<Import Project="$(SolutionDir)\packages\SQLitePCLRaw.lib.e_sqlite3.v110_xp.1.0.1\build\SQLitePCLRaw.lib.e_sqlite3.v110_xp.targets" Condition="Exists('..\packages\SQLitePCLRaw.lib.e_sqlite3.v110_xp.1.0.1\build\SQLitePCLRaw.lib.e_sqlite3.v110_xp.targets')" /> <Import Project="$(SolutionDir)\packages\SQLitePCLRaw.lib.e_sqlite3.v110_xp.1.0.1\build\SQLitePCLRaw.lib.e_sqlite3.v110_xp.targets" Condition="Exists('..\packages\SQLitePCLRaw.lib.e_sqlite3.v110_xp.1.0.1\build\SQLitePCLRaw.lib.e_sqlite3.v110_xp.targets')" />
<Import Project="$(SolutionDir)\packages\SQLitePCLRaw.lib.e_sqlite3.osx.1.0.1\build\SQLitePCLRaw.lib.e_sqlite3.osx.targets" Condition="Exists('..\packages\SQLitePCLRaw.lib.e_sqlite3.osx.1.0.1\build\SQLitePCLRaw.lib.e_sqlite3.osx.targets')" /> <Import Project="$(SolutionDir)\packages\SQLitePCLRaw.lib.e_sqlite3.osx.1.0.1\build\SQLitePCLRaw.lib.e_sqlite3.osx.targets" Condition="Exists('..\packages\SQLitePCLRaw.lib.e_sqlite3.osx.1.0.1\build\SQLitePCLRaw.lib.e_sqlite3.osx.targets')" />
<Import Project="$(SolutionDir)\packages\SQLitePCLRaw.lib.e_sqlite3.linux.1.0.1\build\SQLitePCLRaw.lib.e_sqlite3.linux.targets" Condition="Exists('..\packages\SQLitePCLRaw.lib.e_sqlite3.linux.1.0.1\build\SQLitePCLRaw.lib.e_sqlite3.linux.targets')" /> <Import Project="$(SolutionDir)\packages\SQLitePCLRaw.lib.e_sqlite3.linux.1.0.1\build\SQLitePCLRaw.lib.e_sqlite3.linux.targets" Condition="Exists('..\packages\SQLitePCLRaw.lib.e_sqlite3.linux.1.0.1\build\SQLitePCLRaw.lib.e_sqlite3.linux.targets')" />
</Project> </Project>