1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 13:07:24 +08:00
osu-lazer/osu.Game/Screens/Play/HUD/ArgonAccuracyCounter.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

112 lines
4.4 KiB
C#
Raw Normal View History

2023-10-26 13:58:47 +08:00
// 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.
2023-11-08 06:48:21 +08:00
using osu.Framework.Bindables;
using osu.Framework.Extensions.LocalisationExtensions;
2023-10-26 13:58:47 +08:00
using osu.Framework.Graphics;
2023-11-10 05:34:29 +08:00
using osu.Framework.Graphics.Containers;
2023-11-08 06:48:21 +08:00
using osu.Framework.Graphics.Sprites;
2023-11-10 05:34:29 +08:00
using osu.Framework.Localisation;
2023-11-08 06:48:21 +08:00
using osu.Game.Configuration;
using osu.Game.Localisation.SkinComponents;
using osu.Game.Resources.Localisation.Web;
2023-10-26 13:58:47 +08:00
using osu.Game.Skinning;
2023-11-08 06:48:21 +08:00
using osuTK;
2023-10-26 13:58:47 +08:00
namespace osu.Game.Screens.Play.HUD
{
public partial class ArgonAccuracyCounter : GameplayAccuracyCounter, ISerialisableDrawable
{
protected override double RollingDuration => 250;
2023-11-10 14:06:19 +08:00
2023-11-08 06:48:21 +08:00
[SettingSource("Wireframe opacity", "Controls the opacity of the wire frames behind the digits.")]
public BindableFloat WireframeOpacity { get; } = new BindableFloat(0.25f)
2023-11-08 06:48:21 +08:00
{
Precision = 0.01f,
MinValue = 0,
MaxValue = 1,
};
[SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.ShowLabel), nameof(SkinnableComponentStrings.ShowLabelDescription))]
public Bindable<bool> ShowLabel { get; } = new BindableBool(true);
2023-10-26 13:58:47 +08:00
public bool UsesFixedAnchor { get; set; }
2023-11-10 05:34:29 +08:00
protected override IHasText CreateText() => new ArgonAccuracyTextComponent
2023-11-08 06:48:21 +08:00
{
WireframeOpacity = { BindTarget = WireframeOpacity },
ShowLabel = { BindTarget = ShowLabel },
2023-11-08 06:48:21 +08:00
};
2023-11-10 05:34:29 +08:00
private partial class ArgonAccuracyTextComponent : CompositeDrawable, IHasText
{
private readonly ArgonCounterTextComponent wholePart;
private readonly ArgonCounterTextComponent fractionPart;
private readonly ArgonCounterTextComponent percentText;
2023-11-10 05:34:29 +08:00
public IBindable<float> WireframeOpacity { get; } = new BindableFloat();
public Bindable<bool> ShowLabel { get; } = new BindableBool();
2023-11-10 05:34:29 +08:00
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, BeatmapsetsStrings.ShowScoreboardHeadersAccuracy.ToUpper())
2023-11-10 05:34:29 +08:00
{
RequiredDisplayDigits = { Value = 3 },
WireframeOpacity = { BindTarget = WireframeOpacity },
ShowLabel = { BindTarget = ShowLabel },
2023-11-10 05:34:29 +08:00
}
},
fractionPart = new ArgonCounterTextComponent(Anchor.TopLeft)
{
RequiredDisplayDigits = { Value = 2 },
2023-11-10 05:34:29 +08:00
WireframeOpacity = { BindTarget = WireframeOpacity },
Scale = new Vector2(0.5f),
},
percentText = new ArgonCounterTextComponent(Anchor.TopLeft)
2023-11-10 05:34:29 +08:00
{
Text = @"%",
RequiredDisplayDigits = { Value = 1 },
2023-11-10 05:34:29 +08:00
WireframeOpacity = { BindTarget = WireframeOpacity }
},
}
};
}
protected override void LoadComplete()
{
base.LoadComplete();
ShowLabel.BindValueChanged(s =>
{
fractionPart.Margin = new MarginPadding { Top = s.NewValue ? 12f * 2f + 4f : 4f }; // +4 to account for the extra spaces above the digits.
percentText.Margin = new MarginPadding { Top = s.NewValue ? 12f : 0 };
}, true);
}
2023-11-10 05:34:29 +08:00
}
2023-10-26 13:58:47 +08:00
}
}