mirror of
https://github.com/ppy/osu.git
synced 2026-05-16 19:23:11 +08:00
e73e9275ba
Closes https://github.com/ppy/osu/issues/34959. `ArgonCounterTextComponent` is pretty terrible and prevents being able to fix the issue easily. The core issue is that this is the first instance of the component's usage where the label text can be longer than the counter in the X dimension, so the total width of any counter is equal to max(label width, counter width), and the label will be aligned to the left of that width, while the counter will be aligned to the right of that width. The fix sort of relies on the fact that I don't expect *any* consumer of `ArgonCounterTextComponent` that meaningfully uses the wireframe digits to want the non-wireframe digits to be aligned to the *left* rather than the right. It's not what I'd expect any segmented display to work. (There are usages that specify `TopLeft` anchor, but they usually display the same number of wireframe and non-wireframe digits, so for them it doesn't really matter if the digits are left-aligned to the wireframes or not.)
75 lines
2.6 KiB
C#
75 lines
2.6 KiB
C#
// 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 System.Linq;
|
|
using osu.Framework.Allocation;
|
|
using osu.Framework.Bindables;
|
|
using osu.Framework.Extensions.LocalisationExtensions;
|
|
using osu.Framework.Graphics;
|
|
using osu.Framework.Graphics.Containers;
|
|
using osu.Game.Graphics;
|
|
using osu.Game.Rulesets.Scoring;
|
|
using osu.Game.Screens.Play.HUD;
|
|
using osu.Game.Screens.Play.HUD.JudgementCounter;
|
|
using osuTK.Graphics;
|
|
|
|
namespace osu.Game.Skinning.Components
|
|
{
|
|
public sealed partial class ArgonJudgementCounter : VisibilityContainer
|
|
{
|
|
public readonly JudgementCount Result;
|
|
|
|
public IBindable<float> WireframeOpacity => textComponent.WireframeOpacity;
|
|
|
|
public IBindable<int?> WireframeDigits { get; } = new Bindable<int?>();
|
|
|
|
public IBindable<bool> ShowLabel => textComponent.ShowLabel;
|
|
|
|
private readonly ArgonCounterTextComponent textComponent;
|
|
private readonly BindableInt displayedValue = new BindableInt();
|
|
|
|
[Resolved]
|
|
private OsuColour colours { get; set; } = null!;
|
|
|
|
public ArgonJudgementCounter(JudgementCount result)
|
|
{
|
|
Result = result;
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
AddInternal(textComponent = new ArgonCounterTextComponent(Anchor.TopLeft, result.DisplayName.ToUpper()));
|
|
}
|
|
|
|
private void updateWireframe()
|
|
{
|
|
textComponent.WireframeTemplate = new string('#', WireframeDigits.Value ?? Math.Max(2, textComponent.Text.ToString().Length));
|
|
}
|
|
|
|
protected override void LoadComplete()
|
|
{
|
|
base.LoadComplete();
|
|
|
|
WireframeDigits.BindValueChanged(_ => updateWireframe());
|
|
|
|
displayedValue.BindTo(Result.ResultCount);
|
|
displayedValue.BindValueChanged(v =>
|
|
{
|
|
textComponent.Text = v.NewValue.ToString();
|
|
updateWireframe();
|
|
}, true);
|
|
|
|
var result = Result.Types.First();
|
|
textComponent.LabelColour.Value = getJudgementColor(result);
|
|
textComponent.ShowLabel.BindValueChanged(v => textComponent.TextColour.Value = !v.NewValue ? getJudgementColor(result) : Color4.White, true);
|
|
}
|
|
|
|
private Color4 getJudgementColor(HitResult result)
|
|
{
|
|
return result.IsBasic() ? colours.ForHitResult(result) : !result.IsBonus() ? colours.PurpleLight : colours.PurpleLighter;
|
|
}
|
|
|
|
protected override void PopIn() => this.FadeIn(JudgementCounterDisplay.TRANSFORM_DURATION, Easing.OutQuint);
|
|
protected override void PopOut() => this.FadeOut();
|
|
}
|
|
}
|