mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 02:22:56 +08:00
Update argon accuracy counter design
This commit is contained in:
parent
2ef17c56b1
commit
6f5d905ce7
@ -3,7 +3,9 @@
|
||||
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Skinning;
|
||||
using osuTK;
|
||||
@ -22,9 +24,64 @@ namespace osu.Game.Screens.Play.HUD
|
||||
|
||||
public bool UsesFixedAnchor { get; set; }
|
||||
|
||||
protected override IHasText CreateText() => new ArgonCounterTextComponent(Anchor.TopLeft, "ACCURACY", new Vector2(-4, 0))
|
||||
protected override IHasText CreateText() => new ArgonAccuracyTextComponent
|
||||
{
|
||||
WireframeOpacity = { BindTarget = WireframeOpacity },
|
||||
};
|
||||
|
||||
private partial class ArgonAccuracyTextComponent : CompositeDrawable, IHasText
|
||||
{
|
||||
private readonly ArgonCounterTextComponent wholePart;
|
||||
private readonly ArgonCounterTextComponent fractionPart;
|
||||
|
||||
public IBindable<float> WireframeOpacity { get; } = new BindableFloat();
|
||||
|
||||
public LocalisableString Text
|
||||
{
|
||||
get => wholePart.Text;
|
||||
set
|
||||
{
|
||||
string[] split = value.ToString().Replace("%", string.Empty).Split(".");
|
||||
|
||||
wholePart.Text = split[0];
|
||||
fractionPart.Text = "." + split[1];
|
||||
}
|
||||
}
|
||||
|
||||
public ArgonAccuracyTextComponent()
|
||||
{
|
||||
AutoSizeAxes = Axes.Both;
|
||||
|
||||
InternalChild = new FillFlowContainer
|
||||
{
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Direction = FillDirection.Horizontal,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Container
|
||||
{
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Child = wholePart = new ArgonCounterTextComponent(Anchor.TopRight, "ACCURACY")
|
||||
{
|
||||
RequiredDisplayDigits = { Value = 3 },
|
||||
WireframeOpacity = { BindTarget = WireframeOpacity }
|
||||
}
|
||||
},
|
||||
fractionPart = new ArgonCounterTextComponent(Anchor.TopLeft)
|
||||
{
|
||||
Margin = new MarginPadding { Top = 12f * 2f + 4f }, // +4 to account for the extra spaces above the digits.
|
||||
WireframeOpacity = { BindTarget = WireframeOpacity },
|
||||
Scale = new Vector2(0.5f),
|
||||
},
|
||||
new ArgonCounterTextComponent(Anchor.TopLeft)
|
||||
{
|
||||
Text = @"%",
|
||||
Margin = new MarginPadding { Top = 12f },
|
||||
WireframeOpacity = { BindTarget = WireframeOpacity }
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
@ -19,62 +20,30 @@ namespace osu.Game.Screens.Play.HUD
|
||||
{
|
||||
public partial class ArgonCounterTextComponent : CompositeDrawable, IHasText
|
||||
{
|
||||
private readonly LocalisableString? label;
|
||||
|
||||
private readonly ArgonCounterSpriteText wireframesPart;
|
||||
private readonly ArgonCounterSpriteText textPart;
|
||||
private readonly OsuSpriteText labelText;
|
||||
|
||||
public IBindable<float> WireframeOpacity { get; } = new BindableFloat();
|
||||
public Bindable<int> RequiredDisplayDigits { get; } = new BindableInt();
|
||||
|
||||
public LocalisableString Text
|
||||
{
|
||||
get => textPart.Text;
|
||||
set
|
||||
{
|
||||
wireframesPart.Text = FormatWireframes(value);
|
||||
int remainingCount = RequiredDisplayDigits.Value - value.ToString().Count(char.IsDigit);
|
||||
string remainingText = remainingCount > 0 ? new string('#', remainingCount) : string.Empty;
|
||||
|
||||
wireframesPart.Text = remainingText + value;
|
||||
textPart.Text = value;
|
||||
}
|
||||
}
|
||||
|
||||
public ArgonCounterTextComponent(Anchor anchor, LocalisableString? label = null, Vector2? spacing = null)
|
||||
public ArgonCounterTextComponent(Anchor anchor, LocalisableString? label = null)
|
||||
{
|
||||
Anchor = anchor;
|
||||
Origin = anchor;
|
||||
|
||||
this.label = label;
|
||||
|
||||
wireframesPart = new ArgonCounterSpriteText(c =>
|
||||
{
|
||||
if (c == '.')
|
||||
return @"dot";
|
||||
|
||||
return @"wireframes";
|
||||
})
|
||||
{
|
||||
Anchor = anchor,
|
||||
Origin = anchor,
|
||||
Spacing = spacing ?? new Vector2(-2, 0),
|
||||
};
|
||||
textPart = new ArgonCounterSpriteText(c =>
|
||||
{
|
||||
if (c == '.')
|
||||
return @"dot";
|
||||
|
||||
if (c == '%')
|
||||
return @"percentage";
|
||||
|
||||
return c.ToString();
|
||||
})
|
||||
{
|
||||
Anchor = anchor,
|
||||
Origin = anchor,
|
||||
Spacing = spacing ?? new Vector2(-2, 0),
|
||||
};
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
AutoSizeAxes = Axes.Both;
|
||||
|
||||
InternalChild = new FillFlowContainer
|
||||
@ -83,12 +52,11 @@ namespace osu.Game.Screens.Play.HUD
|
||||
Direction = FillDirection.Vertical,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new OsuSpriteText
|
||||
labelText = new OsuSpriteText
|
||||
{
|
||||
Alpha = label != null ? 1 : 0,
|
||||
Text = label.GetValueOrDefault(),
|
||||
Font = OsuFont.Torus.With(size: 12, weight: FontWeight.Bold),
|
||||
Colour = colours.Blue0,
|
||||
Margin = new MarginPadding { Left = 2.5f },
|
||||
},
|
||||
new Container
|
||||
@ -96,14 +64,50 @@ namespace osu.Game.Screens.Play.HUD
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Children = new[]
|
||||
{
|
||||
wireframesPart,
|
||||
textPart,
|
||||
wireframesPart = new ArgonCounterSpriteText(wireframesLookup)
|
||||
{
|
||||
Anchor = anchor,
|
||||
Origin = anchor,
|
||||
},
|
||||
textPart = new ArgonCounterSpriteText(textLookup)
|
||||
{
|
||||
Anchor = anchor,
|
||||
Origin = anchor,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private string textLookup(char c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case '.':
|
||||
return @"dot";
|
||||
|
||||
case '%':
|
||||
return @"percentage";
|
||||
|
||||
default:
|
||||
return c.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private string wireframesLookup(char c)
|
||||
{
|
||||
if (c == '.') return @"dot";
|
||||
|
||||
return @"wireframes";
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
labelText.Colour = colours.Blue0;
|
||||
}
|
||||
|
||||
protected virtual LocalisableString FormatWireframes(LocalisableString text) => text;
|
||||
|
||||
protected override void LoadComplete()
|
||||
@ -131,8 +135,8 @@ namespace osu.Game.Screens.Play.HUD
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(ISkinSource skin)
|
||||
{
|
||||
// todo: rename font
|
||||
Font = new FontUsage(@"argon-score", 1);
|
||||
Spacing = new Vector2(-2f, 0f);
|
||||
Font = new FontUsage(@"argon-counter", 1);
|
||||
glyphStore = new GlyphStore(skin, getLookup);
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions.LocalisationExtensions;
|
||||
using osu.Framework.Graphics;
|
||||
@ -34,14 +33,10 @@ namespace osu.Game.Screens.Play.HUD
|
||||
|
||||
private partial class ArgonScoreTextComponent : ArgonCounterTextComponent
|
||||
{
|
||||
public IBindable<int> RequiredDisplayDigits { get; } = new BindableInt();
|
||||
|
||||
public ArgonScoreTextComponent(Anchor anchor, LocalisableString? label = null)
|
||||
: base(anchor, label)
|
||||
{
|
||||
}
|
||||
|
||||
protected override LocalisableString FormatWireframes(LocalisableString text) => new string('#', Math.Max(text.ToString().Length, RequiredDisplayDigits.Value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user