Skip to content

Commit

Permalink
Merge pull request #25469 from Joehuu/argon-hide-counter-labels
Browse files Browse the repository at this point in the history
Add ability to toggle labels on argon counter components
  • Loading branch information
peppy authored Nov 16, 2023
2 parents d09d586 + b45872d commit 0a8ede6
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 18 deletions.
28 changes: 19 additions & 9 deletions osu.Game/Localisation/SkinComponents/SkinnableComponentStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,53 @@ public static class SkinnableComponentStrings
/// <summary>
/// "Sprite name"
/// </summary>
public static LocalisableString SpriteName => new TranslatableString(getKey(@"sprite_name"), "Sprite name");
public static LocalisableString SpriteName => new TranslatableString(getKey(@"sprite_name"), @"Sprite name");

/// <summary>
/// "The filename of the sprite"
/// </summary>
public static LocalisableString SpriteNameDescription => new TranslatableString(getKey(@"sprite_name_description"), "The filename of the sprite");
public static LocalisableString SpriteNameDescription => new TranslatableString(getKey(@"sprite_name_description"), @"The filename of the sprite");

/// <summary>
/// "Font"
/// </summary>
public static LocalisableString Font => new TranslatableString(getKey(@"font"), "Font");
public static LocalisableString Font => new TranslatableString(getKey(@"font"), @"Font");

/// <summary>
/// "The font to use."
/// </summary>
public static LocalisableString FontDescription => new TranslatableString(getKey(@"font_description"), "The font to use.");
public static LocalisableString FontDescription => new TranslatableString(getKey(@"font_description"), @"The font to use.");

/// <summary>
/// "Text"
/// </summary>
public static LocalisableString TextElementText => new TranslatableString(getKey(@"text_element_text"), "Text");
public static LocalisableString TextElementText => new TranslatableString(getKey(@"text_element_text"), @"Text");

/// <summary>
/// "The text to be displayed."
/// </summary>
public static LocalisableString TextElementTextDescription => new TranslatableString(getKey(@"text_element_text_description"), "The text to be displayed.");
public static LocalisableString TextElementTextDescription => new TranslatableString(getKey(@"text_element_text_description"), @"The text to be displayed.");

/// <summary>
/// "Corner radius"
/// </summary>
public static LocalisableString CornerRadius => new TranslatableString(getKey(@"corner_radius"), "Corner radius");
public static LocalisableString CornerRadius => new TranslatableString(getKey(@"corner_radius"), @"Corner radius");

/// <summary>
/// "How rounded the corners should be."
/// </summary>
public static LocalisableString CornerRadiusDescription => new TranslatableString(getKey(@"corner_radius_description"), "How rounded the corners should be.");
public static LocalisableString CornerRadiusDescription => new TranslatableString(getKey(@"corner_radius_description"), @"How rounded the corners should be.");

private static string getKey(string key) => $"{prefix}:{key}";
/// <summary>
/// "Show label"
/// </summary>
public static LocalisableString ShowLabel => new TranslatableString(getKey(@"show_label"), @"Show label");

/// <summary>
/// "Whether the component&#39;s label should be shown."
/// </summary>
public static LocalisableString ShowLabelDescription => new TranslatableString(getKey(@"show_label_description"), @"Whether the component's label should be shown.");

private static string getKey(string key) => $@"{prefix}:{key}";
}
}
30 changes: 25 additions & 5 deletions osu.Game/Screens/Play/HUD/ArgonAccuracyCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -25,20 +28,27 @@ public partial class ArgonAccuracyCounter : GameplayAccuracyCounter, ISerialisab
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;
Expand All @@ -64,27 +74,37 @@ public ArgonAccuracyTextComponent()
new Container
{
AutoSizeAxes = Axes.Both,
Child = wholePart = new ArgonCounterTextComponent(Anchor.TopRight, "ACCURACY")
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);
}
}
}
}
9 changes: 8 additions & 1 deletion osu.Game/Screens/Play/HUD/ArgonComboCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,6 +32,9 @@ public partial class ArgonComboCounter : ComboCounter
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)
{
Expand All @@ -53,9 +59,10 @@ private void load(ScoreProcessor scoreProcessor)

protected override LocalisableString FormatCount(int count) => $@"{count}x";

protected override IHasText CreateText() => text = new ArgonCounterTextComponent(Anchor.TopLeft, "COMBO")
protected override IHasText CreateText() => text = new ArgonCounterTextComponent(Anchor.TopLeft, MatchesStrings.MatchScoreStatsCombo.ToUpper())
{
WireframeOpacity = { BindTarget = WireframeOpacity },
ShowLabel = { BindTarget = ShowLabel },
};
}
}
4 changes: 3 additions & 1 deletion osu.Game/Screens/Play/HUD/ArgonCounterTextComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public partial class ArgonCounterTextComponent : CompositeDrawable, IHasText

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; }

Expand Down Expand Up @@ -56,7 +57,7 @@ public ArgonCounterTextComponent(Anchor anchor, LocalisableString? label = null)
{
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 },
Expand Down Expand Up @@ -114,6 +115,7 @@ protected override void LoadComplete()
{
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
Expand Down
8 changes: 7 additions & 1 deletion osu.Game/Screens/Play/HUD/ArgonScoreCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
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
Expand All @@ -24,14 +26,18 @@ public partial class ArgonScoreCounter : GameplayScoreCounter, ISerialisableDraw
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 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
Expand Down
5 changes: 4 additions & 1 deletion osu.Game/Skinning/ArgonSkin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,10 @@ public ArgonSkin(SkinInfo skin, IStorageResourceProvider resources)
Size = new Vector2(380, 72),
Position = new Vector2(4, 5)
},
new ArgonScoreCounter(),
new ArgonScoreCounter
{
ShowLabel = { Value = false },
},
new ArgonHealthDisplay(),
new BoxElement
{
Expand Down

0 comments on commit 0a8ede6

Please sign in to comment.