Skip to content

Commit 1741b02

Browse files
authored
Merge pull request #33698 from frenzibyte/difficulty-slider-localisation
Add localisation support to difficulty range slider
2 parents baab447 + 977c26d commit 1741b02

File tree

5 files changed

+38
-26
lines changed

5 files changed

+38
-26
lines changed

osu.Game.Tests/Visual/SongSelectV2/TestSceneDifficultyRangeSlider.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ protected override void LoadComplete()
5959
Scale = new Vector2(1),
6060
LowerBound = customStart,
6161
UpperBound = customEnd,
62-
TooltipSuffix = "suffix",
6362
NubWidth = 32,
6463
MinRange = 0.1f,
6564
}

osu.Game.Tests/Visual/UserInterface/TestSceneShearedRangeSlider.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ protected override void LoadComplete()
6464
Scale = new Vector2(1),
6565
LowerBound = customStart,
6666
UpperBound = customEnd,
67-
TooltipSuffix = "suffix",
6867
NubWidth = 32,
6968
DefaultStringLowerBound = "0.0",
7069
DefaultStringUpperBound = "∞",

osu.Game/Graphics/UserInterface/ShearedRangeSlider.cs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using osu.Framework.Allocation;
66
using osu.Framework.Bindables;
77
using osu.Framework.Extensions.Color4Extensions;
8+
using osu.Framework.Extensions.LocalisationExtensions;
89
using osu.Framework.Graphics;
910
using osu.Framework.Graphics.Containers;
1011
using osu.Framework.Graphics.Shapes;
@@ -54,20 +55,14 @@ public float MinRange
5455
}
5556

5657
/// <summary>
57-
/// Lower bound display for when it is set to its default value.
58+
/// Lower bound display for when it is set to its default value, or null to display the value directly.
5859
/// </summary>
59-
public string DefaultStringLowerBound { get; init; } = string.Empty;
60+
public LocalisableString? DefaultStringLowerBound { get; init; }
6061

6162
/// <summary>
62-
/// Upper bound display for when it is set to its default value.
63+
/// Upper bound display for when it is set to its default value, or null to display the value directly.
6364
/// </summary>
64-
public string DefaultStringUpperBound { get; init; } = string.Empty;
65-
66-
public LocalisableString DefaultTooltipLowerBound { get; init; } = string.Empty;
67-
68-
public LocalisableString DefaultTooltipUpperBound { get; init; } = string.Empty;
69-
70-
public string TooltipSuffix { get; init; } = string.Empty;
65+
public LocalisableString? DefaultStringUpperBound { get; init; }
7166

7267
private float minRange = 0.1f;
7368

@@ -144,19 +139,15 @@ private void load(OverlayColourProvider colourProvider)
144139
{
145140
d.KeyboardStep = 0.1f;
146141
d.RelativeSizeAxes = Axes.X;
147-
d.TooltipSuffix = TooltipSuffix;
148142
d.DefaultString = DefaultStringUpperBound;
149-
d.DefaultTooltip = DefaultTooltipUpperBound;
150143
d.NubWidth = NubWidth;
151144
d.Current = upperBound;
152145
}),
153146
LowerBoundSlider = CreateBoundSlider(false).With(d =>
154147
{
155148
d.KeyboardStep = 0.1f;
156149
d.RelativeSizeAxes = Axes.X;
157-
d.TooltipSuffix = TooltipSuffix;
158150
d.DefaultString = DefaultStringLowerBound;
159-
d.DefaultTooltip = DefaultTooltipLowerBound;
160151
d.NubWidth = NubWidth;
161152
d.Current = lowerBound;
162153
}),
@@ -188,14 +179,20 @@ protected partial class BoundSliderBar : ShearedSliderBar<double>
188179

189180
public new ShearedNub Nub => base.Nub;
190181

191-
public string? DefaultString;
192-
public LocalisableString? DefaultTooltip;
193-
public string? TooltipSuffix;
182+
public LocalisableString? DefaultString;
194183

195184
public float NubWidth { get; set; } = ShearedNub.HEIGHT;
196185

197-
public override LocalisableString TooltipText =>
198-
(Current.IsDefault ? DefaultTooltip : Current.Value.ToString($@"0.## {TooltipSuffix}")) ?? Current.Value.ToString($@"0.## {TooltipSuffix}");
186+
public override LocalisableString TooltipText
187+
{
188+
get
189+
{
190+
if (Current.IsDefault)
191+
return string.Empty;
192+
193+
return Current.Value.ToLocalisableString(@"N1");
194+
}
195+
}
199196

200197
protected OsuSpriteText NubText { get; private set; } = null!;
201198

@@ -245,8 +242,10 @@ protected override void LoadComplete()
245242

246243
protected virtual void UpdateDisplay(double value)
247244
{
248-
string defaultString = DefaultString ?? value.ToString("N1");
249-
NubText.Text = Current.IsDefault ? defaultString : value.ToString("N1");
245+
if (Current.IsDefault && DefaultString != null)
246+
NubText.Text = DefaultString.Value;
247+
else
248+
NubText.Text = value.ToLocalisableString(@"N1");
250249
}
251250

252251
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos)

osu.Game/Localisation/SongSelectStrings.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public static class SongSelectStrings
5454
/// </summary>
5555
public static LocalisableString EditBeatmap => new TranslatableString(getKey(@"edit_beatmap"), @"Edit beatmap");
5656

57+
/// <summary>
58+
/// "{0} stars"
59+
/// </summary>
60+
public static LocalisableString Stars(LocalisableString value) => new TranslatableString(getKey(@"stars"), @"{0} stars", value);
61+
5762
private static string getKey(string key) => $@"{prefix}:{key}";
5863
}
5964
}

osu.Game/Screens/SelectV2/FilterControl_DifficultyRangeSlider.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
using System.Linq;
66
using osu.Framework.Allocation;
77
using osu.Framework.Extensions.Color4Extensions;
8+
using osu.Framework.Extensions.LocalisationExtensions;
89
using osu.Framework.Graphics;
910
using osu.Framework.Graphics.Colour;
1011
using osu.Framework.Graphics.Containers;
1112
using osu.Framework.Graphics.Shapes;
1213
using osu.Framework.Layout;
14+
using osu.Framework.Localisation;
1315
using osu.Game.Graphics;
1416
using osu.Game.Graphics.UserInterface;
1517
using osu.Game.Localisation;
@@ -35,10 +37,7 @@ public DifficultyRangeSlider()
3537
: base("Star Rating")
3638
{
3739
NubWidth = ShearedNub.HEIGHT * 1.16f;
38-
TooltipSuffix = "stars";
39-
DefaultStringLowerBound = "0.0";
4040
DefaultStringUpperBound = "∞";
41-
DefaultTooltipUpperBound = UserInterfaceStrings.NoLimit;
4241

4342
AddLayout(drawSizeLayout);
4443
}
@@ -125,6 +124,17 @@ private partial class DifficultyBoundSliderBar : BoundSliderBar
125124

126125
protected override bool FocusIndicator => false;
127126

127+
public override LocalisableString TooltipText
128+
{
129+
get
130+
{
131+
if (Current.IsDefault && isUpper)
132+
return UserInterfaceStrings.NoLimit;
133+
134+
return SongSelectStrings.Stars(Current.Value.ToLocalisableString(@"0.##"));
135+
}
136+
}
137+
128138
public DifficultyBoundSliderBar(ShearedRangeSlider slider, bool isUpper)
129139
: base(slider, isUpper)
130140
{

0 commit comments

Comments
 (0)