1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 08:32:57 +08:00

Add ability to toggle labels on argon counter components

This commit is contained in:
Joseph Madamba 2023-11-14 20:45:23 -08:00
parent 87ace7565d
commit 62352ce5f3
5 changed files with 51 additions and 6 deletions

View File

@ -49,6 +49,16 @@ namespace osu.Game.Localisation.SkinComponents
/// </summary>
public static LocalisableString CornerRadiusDescription => new TranslatableString(getKey(@"corner_radius_description"), "How rounded the corners should be.");
/// <summary>
/// "Show label"
/// </summary>
public static LocalisableString ShowLabel => new TranslatableString(getKey(@"show_label"), @"Show label");
/// <summary>
/// "Whether the label should be shown."
/// </summary>
public static LocalisableString ShowLabelDescription => new TranslatableString(getKey(@"show_label_description"), @"Whether the label should be shown.");
private static string getKey(string key) => $"{prefix}:{key}";
}
}

View File

@ -2,11 +2,14 @@
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Bindables;
using osu.Framework.Extensions.LocalisationExtensions;
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.Localisation.SkinComponents;
using osu.Game.Resources.Localisation.Web;
using osu.Game.Skinning;
using osuTK;
@ -25,20 +28,27 @@ namespace osu.Game.Screens.Play.HUD
MaxValue = 1,
};
[SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.ShowLabel), nameof(SkinnableComponentStrings.ShowLabelDescription))]
public Bindable<bool> ShowLabel { get; } = new BindableBool(true);
public bool UsesFixedAnchor { get; set; }
protected override IHasText CreateText() => new ArgonAccuracyTextComponent
{
WireframeOpacity = { BindTarget = WireframeOpacity },
ShowLabel = { BindTarget = ShowLabel },
};
private partial class ArgonAccuracyTextComponent : CompositeDrawable, IHasText
{
private readonly ArgonCounterTextComponent wholePart;
private readonly ArgonCounterTextComponent fractionPart;
private readonly ArgonCounterTextComponent percentText;
public IBindable<float> WireframeOpacity { get; } = new BindableFloat();
public Bindable<bool> ShowLabel { get; } = new BindableBool();
public LocalisableString Text
{
get => wholePart.Text;
@ -67,24 +77,34 @@ namespace osu.Game.Screens.Play.HUD
Child = wholePart = new ArgonCounterTextComponent(Anchor.TopRight, BeatmapsetsStrings.ShowScoreboardHeadersAccuracy.ToUpper())
{
RequiredDisplayDigits = { Value = 3 },
WireframeOpacity = { BindTarget = WireframeOpacity }
WireframeOpacity = { BindTarget = WireframeOpacity },
ShowLabel = { BindTarget = ShowLabel },
}
},
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)
percentText = new ArgonCounterTextComponent(Anchor.TopLeft)
{
Text = @"%",
Margin = new MarginPadding { Top = 12f },
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);
}
}
}
}

View File

@ -4,10 +4,13 @@
using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.LocalisationExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Localisation;
using osu.Game.Configuration;
using osu.Game.Localisation.SkinComponents;
using osu.Game.Resources.Localisation.Web;
using osu.Game.Rulesets.Scoring;
using osuTK;
using osuTK.Graphics;
@ -29,6 +32,9 @@ namespace osu.Game.Screens.Play.HUD
MaxValue = 1,
};
[SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.ShowLabel), nameof(SkinnableComponentStrings.ShowLabelDescription))]
public Bindable<bool> ShowLabel { get; } = new BindableBool(true);
[BackgroundDependencyLoader]
private void load(ScoreProcessor scoreProcessor)
{
@ -56,6 +62,7 @@ namespace osu.Game.Screens.Play.HUD
protected override IHasText CreateText() => text = new ArgonCounterTextComponent(Anchor.TopLeft, MatchesStrings.MatchScoreStatsCombo.ToUpper())
{
WireframeOpacity = { BindTarget = WireframeOpacity },
ShowLabel = { BindTarget = ShowLabel },
};
}
}

View File

@ -26,6 +26,7 @@ namespace osu.Game.Screens.Play.HUD
public IBindable<float> WireframeOpacity { get; } = new BindableFloat();
public Bindable<int> RequiredDisplayDigits { get; } = new BindableInt();
public Bindable<bool> ShowLabel { get; } = new BindableBool();
public Container NumberContainer { get; private set; }
@ -56,7 +57,7 @@ namespace osu.Game.Screens.Play.HUD
{
labelText = new OsuSpriteText
{
Alpha = label != null ? 1 : 0,
Alpha = 0,
Text = label.GetValueOrDefault(),
Font = OsuFont.Torus.With(size: 12, weight: FontWeight.Bold),
Margin = new MarginPadding { Left = 2.5f },
@ -114,6 +115,7 @@ namespace osu.Game.Screens.Play.HUD
{
base.LoadComplete();
WireframeOpacity.BindValueChanged(v => wireframesPart.Alpha = v.NewValue, true);
ShowLabel.BindValueChanged(s => labelText.Alpha = s.NewValue ? 1 : 0, true);
}
private partial class ArgonCounterSpriteText : OsuSpriteText

View File

@ -7,6 +7,8 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Localisation;
using osu.Game.Configuration;
using osu.Game.Localisation.SkinComponents;
using osu.Game.Resources.Localisation.Web;
using osu.Game.Skinning;
namespace osu.Game.Screens.Play.HUD
@ -24,14 +26,18 @@ namespace osu.Game.Screens.Play.HUD
MaxValue = 1,
};
[SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.ShowLabel), nameof(SkinnableComponentStrings.ShowLabelDescription))]
public Bindable<bool> ShowLabel { get; } = new BindableBool();
public bool UsesFixedAnchor { get; set; }
protected override LocalisableString FormatCount(long count) => count.ToLocalisableString();
protected override IHasText CreateText() => new ArgonScoreTextComponent(Anchor.TopRight)
protected override IHasText CreateText() => new ArgonScoreTextComponent(Anchor.TopRight, BeatmapsetsStrings.ShowScoreboardHeadersScore.ToUpper())
{
RequiredDisplayDigits = { BindTarget = RequiredDisplayDigits },
WireframeOpacity = { BindTarget = WireframeOpacity },
ShowLabel = { BindTarget = ShowLabel },
};
private partial class ArgonScoreTextComponent : ArgonCounterTextComponent