mirror of
https://github.com/osukey/osukey.git
synced 2025-06-29 23:28:00 +09:00
Refactor + Stars Counter (initial)
Moved a few things to allow using common transforms for a star counter. This implementation is basic and hacky, but good enough as proof of concept.
This commit is contained in:
parent
a3b4a34a1a
commit
5ebb2fc289
@ -87,6 +87,14 @@ namespace osu.Desktop.Tests
|
|||||||
};
|
};
|
||||||
Add(pc);
|
Add(pc);
|
||||||
|
|
||||||
|
StarCounter tc = new StarCounter
|
||||||
|
{
|
||||||
|
Origin = Anchor.BottomLeft,
|
||||||
|
Anchor = Anchor.BottomLeft,
|
||||||
|
Position = new Vector2(20, 160),
|
||||||
|
};
|
||||||
|
Add(tc);
|
||||||
|
|
||||||
AddButton(@"Reset all", delegate
|
AddButton(@"Reset all", delegate
|
||||||
{
|
{
|
||||||
uc.Count = 0;
|
uc.Count = 0;
|
||||||
@ -119,6 +127,11 @@ namespace osu.Desktop.Tests
|
|||||||
pc.Denominator++;
|
pc.Denominator++;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
AddButton(@"Alter stars", delegate
|
||||||
|
{
|
||||||
|
tc.Count = RNG.NextSingle() * tc.MaxStars;
|
||||||
|
});
|
||||||
|
|
||||||
AddButton(@"Stop counters", delegate
|
AddButton(@"Stop counters", delegate
|
||||||
{
|
{
|
||||||
uc.StopRolling();
|
uc.StopRolling();
|
||||||
@ -126,6 +139,7 @@ namespace osu.Desktop.Tests
|
|||||||
cc.StopRolling();
|
cc.StopRolling();
|
||||||
ac.StopRolling();
|
ac.StopRolling();
|
||||||
pc.StopRolling();
|
pc.StopRolling();
|
||||||
|
tc.StopRolling();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Used as an accuracy counter. Represented visually as a percentage, internally as a fraction.
|
/// Used as an accuracy counter. Represented visually as a percentage, internally as a fraction.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class AccuracyCounter : RollingCounter<float>
|
public class AccuracyCounter : NumericRollingCounter<float>
|
||||||
{
|
{
|
||||||
protected override Type transformType => typeof(TransformAccuracy);
|
protected override Type transformType => typeof(TransformAccuracy);
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
{
|
{
|
||||||
public Color4 OriginalColour;
|
public Color4 OriginalColour;
|
||||||
public Color4 TintColour = Color4.OrangeRed;
|
public Color4 TintColour = Color4.OrangeRed;
|
||||||
public int TintDuration = 500;
|
public int TintDuration = 250;
|
||||||
public float ScaleFactor = 2;
|
public float ScaleFactor = 2;
|
||||||
public EasingTypes TintEasing = EasingTypes.None;
|
public EasingTypes TintEasing = EasingTypes.None;
|
||||||
public bool CanAnimateWhenBackwards = false;
|
public bool CanAnimateWhenBackwards = false;
|
||||||
|
64
osu.Game/Graphics/UserInterface/NumericRollingCounter.cs
Normal file
64
osu.Game/Graphics/UserInterface/NumericRollingCounter.cs
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
//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.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()
|
||||||
|
{
|
||||||
|
|
||||||
|
base.Load();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,5 @@
|
|||||||
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
using osu.Framework.Graphics;
|
||||||
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
||||||
|
|
||||||
using osu.Framework.Graphics;
|
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Sprites;
|
|
||||||
using osu.Framework.Graphics.Transformations;
|
using osu.Framework.Graphics.Transformations;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -15,8 +11,12 @@ using System.Threading.Tasks;
|
|||||||
namespace osu.Game.Graphics.UserInterface
|
namespace osu.Game.Graphics.UserInterface
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Skeleton for a counter with a simple roll-up animation.
|
/// Skeleton for a counter which value rolls-up in a lapse of time.
|
||||||
/// </summary>
|
/// </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>
|
/// <typeparam name="T">Type of the actual counter.</typeparam>
|
||||||
public abstract class RollingCounter<T> : Container
|
public abstract class RollingCounter<T> : Container
|
||||||
{
|
{
|
||||||
@ -28,20 +28,8 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
protected virtual Type transformType => typeof(Transform<T>);
|
protected virtual Type transformType => typeof(Transform<T>);
|
||||||
|
|
||||||
protected SpriteText countSpriteText;
|
|
||||||
protected ulong RollingTotalDuration = 0;
|
protected ulong RollingTotalDuration = 0;
|
||||||
|
|
||||||
protected float textSize = 20.0f;
|
|
||||||
public float TextSize
|
|
||||||
{
|
|
||||||
get { return textSize; }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
textSize = value;
|
|
||||||
updateTextSize();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// If true, each time the Count is updated, it will roll over from the current visible value.
|
/// 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.
|
/// Else, it will roll up from the current count value.
|
||||||
@ -121,16 +109,6 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
if (Count == null)
|
if (Count == null)
|
||||||
ResetCount();
|
ResetCount();
|
||||||
VisibleCount = Count;
|
VisibleCount = Count;
|
||||||
Children = new Drawable[]
|
|
||||||
{
|
|
||||||
countSpriteText = new SpriteText
|
|
||||||
{
|
|
||||||
Text = formatCount(Count),
|
|
||||||
TextSize = this.TextSize,
|
|
||||||
Anchor = this.Anchor,
|
|
||||||
Origin = this.Origin,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -250,18 +228,6 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="currentValue">Visible count value before modification.</param>
|
/// <param name="currentValue">Visible count value before modification.</param>
|
||||||
/// <param name="newValue">Expected visible count value after modification-</param>
|
/// <param name="newValue">Expected visible count value after modification-</param>
|
||||||
protected virtual void transformVisibleCount(T currentValue, T newValue)
|
protected abstract void transformVisibleCount(T currentValue, T newValue);
|
||||||
{
|
|
||||||
if (countSpriteText != null)
|
|
||||||
{
|
|
||||||
countSpriteText.Text = formatCount(newValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void updateTextSize()
|
|
||||||
{
|
|
||||||
if (countSpriteText != null)
|
|
||||||
countSpriteText.TextSize = TextSize;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
119
osu.Game/Graphics/UserInterface/StarCounter.cs
Normal file
119
osu.Game/Graphics/UserInterface/StarCounter.cs
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
//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.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);
|
||||||
|
|
||||||
|
protected float MinStarSize = 0.001f;
|
||||||
|
|
||||||
|
protected FlowContainer starContainer;
|
||||||
|
protected List<TextAwesome> stars = new List<TextAwesome>();
|
||||||
|
|
||||||
|
public int MaxStars = 10;
|
||||||
|
|
||||||
|
public StarCounter() : base()
|
||||||
|
{
|
||||||
|
RollingDuration = 5000;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ResetCount()
|
||||||
|
{
|
||||||
|
Count = 0;
|
||||||
|
StopRolling();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Load()
|
||||||
|
{
|
||||||
|
base.Load();
|
||||||
|
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
starContainer = new FlowContainer
|
||||||
|
{
|
||||||
|
Direction = FlowDirection.HorizontalOnly,
|
||||||
|
Anchor = Anchor.CentreLeft,
|
||||||
|
Origin = Anchor.CentreLeft,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (int i = 0; i < MaxStars; i++)
|
||||||
|
{
|
||||||
|
TextAwesome star = new TextAwesome
|
||||||
|
{
|
||||||
|
Icon = FontAwesome.star,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
TextSize = 20,
|
||||||
|
};
|
||||||
|
stars.Add(star);
|
||||||
|
starContainer.Add(star);
|
||||||
|
}
|
||||||
|
|
||||||
|
// HACK: To mantain container height constant
|
||||||
|
starContainer.Add(new TextAwesome
|
||||||
|
{
|
||||||
|
Icon = FontAwesome.star,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
TextSize = 20,
|
||||||
|
Alpha = 0.002f,
|
||||||
|
});
|
||||||
|
|
||||||
|
ResetCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void transformVisibleCount(float currentValue, float newValue)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < MaxStars; i++)
|
||||||
|
{
|
||||||
|
if (newValue < i)
|
||||||
|
stars[i].ScaleTo(MinStarSize);
|
||||||
|
else if (newValue > (i + 1))
|
||||||
|
stars[i].ScaleTo(1f);
|
||||||
|
else
|
||||||
|
stars[i].ScaleTo(Interpolation.ValueAt(newValue, MinStarSize, 1f, i, i + 1, EasingTypes.None));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -16,7 +16,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// A simple rolling counter that accepts unsigned long values.
|
/// A simple rolling counter that accepts unsigned long values.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ULongCounter : RollingCounter<ulong>
|
public class ULongCounter : NumericRollingCounter<ulong>
|
||||||
{
|
{
|
||||||
protected override Type transformType => typeof(TransformULongCounter);
|
protected override Type transformType => typeof(TransformULongCounter);
|
||||||
|
|
||||||
|
@ -102,15 +102,17 @@
|
|||||||
<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\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\AccuracyCounter.cs" />
|
||||||
<Compile Include="Graphics\UserInterface\RollingCounter.cs" />
|
<Compile Include="Graphics\UserInterface\NumericRollingCounter.cs" />
|
||||||
<Compile Include="Graphics\UserInterface\ScoreCounter.cs" />
|
<Compile Include="Graphics\UserInterface\ScoreCounter.cs" />
|
||||||
<Compile Include="Graphics\UserInterface\CatchComboCounter.cs" />
|
<Compile Include="Graphics\UserInterface\CatchComboCounter.cs" />
|
||||||
<Compile Include="Graphics\UserInterface\StandardComboCounter.cs" />
|
<Compile Include="Graphics\UserInterface\StandardComboCounter.cs" />
|
||||||
|
<Compile Include="Graphics\UserInterface\StarCounter.cs" />
|
||||||
<Compile Include="Graphics\UserInterface\ULongCounter.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" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user