mirror of
https://github.com/ppy/osu.git
synced 2024-12-13 08:32:57 +08:00
Allow providing custom sprite text for RollingCounter<T>
This commit is contained in:
parent
8a9036938f
commit
9d10658e3c
@ -8,6 +8,7 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Tournament.IPC;
|
||||
using osu.Game.Tournament.Models;
|
||||
@ -127,21 +128,28 @@ namespace osu.Game.Tournament.Screens.Gameplay.Components
|
||||
|
||||
private class MatchScoreCounter : ScoreCounter
|
||||
{
|
||||
private OsuSpriteText displayedSpriteText;
|
||||
|
||||
public MatchScoreCounter()
|
||||
{
|
||||
Margin = new MarginPadding { Top = bar_height, Horizontal = 10 };
|
||||
|
||||
Winning = false;
|
||||
|
||||
DisplayedCountSpriteText.Spacing = new Vector2(-6);
|
||||
}
|
||||
|
||||
public bool Winning
|
||||
{
|
||||
set => DisplayedCountSpriteText.Font = value
|
||||
set => displayedSpriteText.Font = value
|
||||
? OsuFont.Torus.With(weight: FontWeight.Bold, size: 50, fixedWidth: true)
|
||||
: OsuFont.Torus.With(weight: FontWeight.Regular, size: 40, fixedWidth: true);
|
||||
}
|
||||
|
||||
protected override OsuSpriteText CreateSpriteText()
|
||||
{
|
||||
displayedSpriteText = base.CreateSpriteText();
|
||||
displayedSpriteText.Spacing = new Vector2(-6);
|
||||
Winning = false;
|
||||
|
||||
return displayedSpriteText;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
using System;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Utils;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
@ -23,7 +24,6 @@ namespace osu.Game.Graphics.UserInterface
|
||||
|
||||
public PercentageCounter()
|
||||
{
|
||||
DisplayedCountSpriteText.Font = DisplayedCountSpriteText.Font.With(fixedWidth: true);
|
||||
Current.Value = DisplayedCount = 1.0f;
|
||||
}
|
||||
|
||||
@ -37,6 +37,13 @@ namespace osu.Game.Graphics.UserInterface
|
||||
return Math.Abs(currentValue - newValue) * RollingDuration * 100.0f;
|
||||
}
|
||||
|
||||
protected override OsuSpriteText CreateSpriteText()
|
||||
{
|
||||
var spriteText = base.CreateSpriteText();
|
||||
spriteText.Font = spriteText.Font.With(fixedWidth: true);
|
||||
return spriteText;
|
||||
}
|
||||
|
||||
public override void Increment(double amount)
|
||||
{
|
||||
Current.Value += amount;
|
||||
|
@ -7,6 +7,7 @@ using osu.Framework.Graphics.Sprites;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osuTK.Graphics;
|
||||
|
||||
@ -20,7 +21,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
/// </summary>
|
||||
public Bindable<T> Current = new Bindable<T>();
|
||||
|
||||
protected SpriteText DisplayedCountSpriteText;
|
||||
private SpriteText displayedCountSpriteText;
|
||||
|
||||
/// <summary>
|
||||
/// If true, the roll-up duration will be proportional to change in value.
|
||||
@ -46,29 +47,49 @@ namespace osu.Game.Graphics.UserInterface
|
||||
public virtual T DisplayedCount
|
||||
{
|
||||
get => displayedCount;
|
||||
|
||||
set
|
||||
{
|
||||
if (EqualityComparer<T>.Default.Equals(displayedCount, value))
|
||||
return;
|
||||
|
||||
displayedCount = value;
|
||||
DisplayedCountSpriteText.Text = FormatCount(value);
|
||||
if (displayedCountSpriteText != null)
|
||||
displayedCountSpriteText.Text = FormatCount(value);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void Increment(T amount);
|
||||
|
||||
private float textSize = 40f;
|
||||
|
||||
public float TextSize
|
||||
{
|
||||
get => DisplayedCountSpriteText.Font.Size;
|
||||
set => DisplayedCountSpriteText.Font = DisplayedCountSpriteText.Font.With(size: value);
|
||||
get => displayedCountSpriteText?.Font.Size ?? textSize;
|
||||
set
|
||||
{
|
||||
if (TextSize == value)
|
||||
return;
|
||||
|
||||
textSize = value;
|
||||
if (displayedCountSpriteText != null)
|
||||
displayedCountSpriteText.Font = displayedCountSpriteText.Font.With(size: value);
|
||||
}
|
||||
}
|
||||
|
||||
private Color4 accentColour;
|
||||
|
||||
public Color4 AccentColour
|
||||
{
|
||||
get => DisplayedCountSpriteText.Colour;
|
||||
set => DisplayedCountSpriteText.Colour = value;
|
||||
get => displayedCountSpriteText?.Colour ?? accentColour;
|
||||
set
|
||||
{
|
||||
if (AccentColour == value)
|
||||
return;
|
||||
|
||||
accentColour = value;
|
||||
if (displayedCountSpriteText != null)
|
||||
displayedCountSpriteText.Colour = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -76,27 +97,21 @@ namespace osu.Game.Graphics.UserInterface
|
||||
/// </summary>
|
||||
protected RollingCounter()
|
||||
{
|
||||
Children = new Drawable[]
|
||||
{
|
||||
DisplayedCountSpriteText = new OsuSpriteText { Font = OsuFont.Numeric }
|
||||
};
|
||||
|
||||
TextSize = 40;
|
||||
AutoSizeAxes = Axes.Both;
|
||||
|
||||
DisplayedCount = Current.Value;
|
||||
|
||||
Current.ValueChanged += val =>
|
||||
{
|
||||
if (IsLoaded) TransformCount(displayedCount, val.NewValue);
|
||||
if (IsLoaded)
|
||||
TransformCount(DisplayedCount, val.NewValue);
|
||||
};
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
DisplayedCountSpriteText.Text = FormatCount(Current.Value);
|
||||
displayedCountSpriteText = CreateSpriteText();
|
||||
displayedCountSpriteText.Text = FormatCount(displayedCount);
|
||||
Child = displayedCountSpriteText;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -167,5 +182,11 @@ namespace osu.Game.Graphics.UserInterface
|
||||
|
||||
this.TransformTo(nameof(DisplayedCount), newValue, rollingTotalDuration, RollingEasing);
|
||||
}
|
||||
|
||||
protected virtual OsuSpriteText CreateSpriteText() => new OsuSpriteText
|
||||
{
|
||||
Font = OsuFont.Numeric.With(size: textSize),
|
||||
Colour = accentColour,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
@ -24,7 +25,6 @@ namespace osu.Game.Graphics.UserInterface
|
||||
/// <param name="leading">How many leading zeroes the counter will have.</param>
|
||||
public ScoreCounter(uint leading = 0)
|
||||
{
|
||||
DisplayedCountSpriteText.Font = DisplayedCountSpriteText.Font.With(fixedWidth: true);
|
||||
LeadingZeroes = leading;
|
||||
}
|
||||
|
||||
@ -49,6 +49,13 @@ namespace osu.Game.Graphics.UserInterface
|
||||
return ((long)count).ToString(format);
|
||||
}
|
||||
|
||||
protected override OsuSpriteText CreateSpriteText()
|
||||
{
|
||||
var spriteText = base.CreateSpriteText();
|
||||
spriteText.Font = spriteText.Font.With(fixedWidth: true);
|
||||
return spriteText;
|
||||
}
|
||||
|
||||
public override void Increment(double amount)
|
||||
{
|
||||
Current.Value += amount;
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Screens.Ranking.Expanded.Accuracy;
|
||||
using osu.Game.Utils;
|
||||
@ -43,16 +44,18 @@ namespace osu.Game.Screens.Ranking.Expanded.Statistics
|
||||
|
||||
protected override Easing RollingEasing => AccuracyCircle.ACCURACY_TRANSFORM_EASING;
|
||||
|
||||
public Counter()
|
||||
{
|
||||
DisplayedCountSpriteText.Font = OsuFont.Torus.With(size: 20, fixedWidth: true);
|
||||
DisplayedCountSpriteText.Spacing = new Vector2(-2, 0);
|
||||
}
|
||||
|
||||
protected override string FormatCount(double count) => count.FormatAccuracy();
|
||||
|
||||
public override void Increment(double amount)
|
||||
=> Current.Value += amount;
|
||||
|
||||
protected override OsuSpriteText CreateSpriteText()
|
||||
{
|
||||
var spriteText = base.CreateSpriteText();
|
||||
spriteText.Font = OsuFont.Torus.With(size: 20, fixedWidth: true);
|
||||
spriteText.Spacing = new Vector2(-2, 0);
|
||||
return spriteText;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Screens.Ranking.Expanded.Accuracy;
|
||||
using osuTK;
|
||||
@ -43,10 +44,12 @@ namespace osu.Game.Screens.Ranking.Expanded.Statistics
|
||||
|
||||
protected override Easing RollingEasing => AccuracyCircle.ACCURACY_TRANSFORM_EASING;
|
||||
|
||||
public Counter()
|
||||
protected override OsuSpriteText CreateSpriteText()
|
||||
{
|
||||
DisplayedCountSpriteText.Font = OsuFont.Torus.With(size: 20, fixedWidth: true);
|
||||
DisplayedCountSpriteText.Spacing = new Vector2(-2, 0);
|
||||
var spriteText = base.CreateSpriteText();
|
||||
spriteText.Font = OsuFont.Torus.With(size: 20, fixedWidth: true);
|
||||
spriteText.Spacing = new Vector2(-2, 0);
|
||||
return spriteText;
|
||||
}
|
||||
|
||||
public override void Increment(int amount)
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Screens.Ranking.Expanded.Accuracy;
|
||||
using osuTK;
|
||||
@ -23,15 +24,21 @@ namespace osu.Game.Screens.Ranking.Expanded
|
||||
// Todo: AutoSize X removed here due to https://github.com/ppy/osu-framework/issues/3369
|
||||
AutoSizeAxes = Axes.Y;
|
||||
RelativeSizeAxes = Axes.X;
|
||||
DisplayedCountSpriteText.Anchor = Anchor.TopCentre;
|
||||
DisplayedCountSpriteText.Origin = Anchor.TopCentre;
|
||||
|
||||
DisplayedCountSpriteText.Font = OsuFont.Torus.With(size: 60, weight: FontWeight.Light, fixedWidth: true);
|
||||
DisplayedCountSpriteText.Spacing = new Vector2(-5, 0);
|
||||
}
|
||||
|
||||
protected override string FormatCount(long count) => count.ToString("N0");
|
||||
|
||||
protected override OsuSpriteText CreateSpriteText()
|
||||
{
|
||||
var spriteText = base.CreateSpriteText();
|
||||
spriteText.Anchor = Anchor.TopCentre;
|
||||
spriteText.Origin = Anchor.TopCentre;
|
||||
|
||||
spriteText.Font = OsuFont.Torus.With(size: 60, weight: FontWeight.Light, fixedWidth: true);
|
||||
spriteText.Spacing = new Vector2(-5, 0);
|
||||
return spriteText;
|
||||
}
|
||||
|
||||
public override void Increment(long amount)
|
||||
=> Current.Value += amount;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user