2016-10-09 08:11:01 +08:00
|
|
|
|
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
2016-10-09 10:45:01 +08:00
|
|
|
|
using OpenTK;
|
2016-10-09 08:11:01 +08:00
|
|
|
|
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.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(TransformStar);
|
|
|
|
|
|
2016-10-09 10:45:01 +08:00
|
|
|
|
protected float MinStarSize = 0.3f;
|
2016-10-09 08:11:01 +08:00
|
|
|
|
|
2016-10-09 10:45:01 +08:00
|
|
|
|
protected Container starContainer;
|
2016-10-09 08:11:01 +08:00
|
|
|
|
protected List<TextAwesome> stars = new List<TextAwesome>();
|
|
|
|
|
|
2016-10-09 10:45:01 +08:00
|
|
|
|
public float MinStarAlpha = 0.5f;
|
|
|
|
|
|
2016-10-09 08:11:01 +08:00
|
|
|
|
public int MaxStars = 10;
|
|
|
|
|
|
2016-10-09 10:45:01 +08:00
|
|
|
|
public int StarSize = 20;
|
|
|
|
|
|
2016-10-09 10:58:53 +08:00
|
|
|
|
public int StarSpacing = 4;
|
2016-10-09 10:45:01 +08:00
|
|
|
|
|
2016-10-09 08:11:01 +08:00
|
|
|
|
public StarCounter() : base()
|
|
|
|
|
{
|
2016-10-09 10:45:01 +08:00
|
|
|
|
IsRollingProportional = true;
|
2016-10-09 10:58:53 +08:00
|
|
|
|
RollingDuration = 150;
|
|
|
|
|
RollingEasing = EasingTypes.Out;
|
2016-10-09 10:45:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override ulong getProportionalDuration(float currentValue, float newValue)
|
|
|
|
|
{
|
|
|
|
|
return (ulong)(Math.Abs(currentValue - newValue) * RollingDuration);
|
2016-10-09 08:11:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void ResetCount()
|
|
|
|
|
{
|
|
|
|
|
Count = 0;
|
|
|
|
|
StopRolling();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Load()
|
|
|
|
|
{
|
|
|
|
|
base.Load();
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2016-10-09 10:45:01 +08:00
|
|
|
|
starContainer = new Container
|
2016-10-09 08:11:01 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
2016-10-09 11:15:25 +08:00
|
|
|
|
Width = MaxStars * StarSize + Math.Max(MaxStars - 1, 0) * StarSpacing,
|
2016-10-09 10:45:01 +08:00
|
|
|
|
Height = StarSize,
|
2016-10-09 08:11:01 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < MaxStars; i++)
|
|
|
|
|
{
|
|
|
|
|
TextAwesome star = new TextAwesome
|
|
|
|
|
{
|
|
|
|
|
Icon = FontAwesome.star,
|
2016-10-09 10:45:01 +08:00
|
|
|
|
Anchor = Anchor.CentreLeft,
|
2016-10-09 08:11:01 +08:00
|
|
|
|
Origin = Anchor.Centre,
|
2016-10-09 10:45:01 +08:00
|
|
|
|
TextSize = StarSize,
|
|
|
|
|
Scale = new Vector2(MinStarSize),
|
|
|
|
|
Alpha = MinStarAlpha,
|
|
|
|
|
Position = new Vector2((StarSize + StarSpacing) * i + (StarSize + StarSpacing) / 2, 0),
|
2016-10-09 08:11:01 +08:00
|
|
|
|
};
|
|
|
|
|
stars.Add(star);
|
|
|
|
|
starContainer.Add(star);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ResetCount();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void transformVisibleCount(float currentValue, float newValue)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < MaxStars; i++)
|
|
|
|
|
{
|
|
|
|
|
if (newValue < i)
|
2016-10-09 10:45:01 +08:00
|
|
|
|
{
|
|
|
|
|
stars[i].Alpha = MinStarAlpha;
|
2016-10-09 08:11:01 +08:00
|
|
|
|
stars[i].ScaleTo(MinStarSize);
|
2016-10-09 10:45:01 +08:00
|
|
|
|
}
|
2016-10-09 08:11:01 +08:00
|
|
|
|
else
|
2016-10-09 10:45:01 +08:00
|
|
|
|
{
|
|
|
|
|
stars[i].Alpha = 1;
|
|
|
|
|
if (newValue > (i + 1))
|
|
|
|
|
stars[i].ScaleTo(1f);
|
|
|
|
|
else
|
|
|
|
|
stars[i].ScaleTo(Interpolation.ValueAt(newValue, MinStarSize, 1f, i, i + 1, EasingTypes.None));
|
|
|
|
|
}
|
2016-10-09 08:11:01 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected class TransformStar : 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 TransformStar(IClock clock)
|
|
|
|
|
: base(clock)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|