Skip to content

Commit

Permalink
Merge pull request #24406 from Joehuu/fix-break-info-decimal-separator
Browse files Browse the repository at this point in the history
Fix accuracy break info decimal separator being incorrect in certain languages
  • Loading branch information
bdach authored Aug 8, 2023
2 parents e13eb75 + 500a136 commit c56ca40
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 40 deletions.
51 changes: 19 additions & 32 deletions osu.Game/Screens/Play/Break/BreakInfoLine.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// 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.

#nullable disable

using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
Expand All @@ -23,69 +21,58 @@ public partial class BreakInfoLine<T> : Container

public Bindable<T> Current = new Bindable<T>();

private readonly OsuSpriteText text;
private readonly OsuSpriteText valueText;
private readonly LocalisableString name;

private readonly string prefix;
private OsuSpriteText valueText = null!;

public BreakInfoLine(LocalisableString name, string prefix = @"")
public BreakInfoLine(LocalisableString name)
{
this.prefix = prefix;
this.name = name;

AutoSizeAxes = Axes.Y;
}

[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Children = new Drawable[]
{
text = new OsuSpriteText
new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.CentreRight,
Text = name,
Font = OsuFont.GetFont(size: 17),
Margin = new MarginPadding { Right = margin }
Margin = new MarginPadding { Right = margin },
Colour = colours.Yellow,
},
valueText = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.CentreLeft,
Text = prefix + @"-",
Text = @"-",
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 17),
Margin = new MarginPadding { Left = margin }
Margin = new MarginPadding { Left = margin },
Colour = colours.YellowLight,
}
};

Current.ValueChanged += currentValueChanged;
}

private void currentValueChanged(ValueChangedEvent<T> e)
{
string newText = prefix + Format(e.NewValue);

if (valueText.Text == newText)
return;

valueText.Text = newText;
Current.BindValueChanged(text => valueText.Text = Format(text.NewValue));
}

protected virtual LocalisableString Format(T count)
{
if (count is Enum countEnum)
return countEnum.GetDescription();

return count.ToString();
}

[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
text.Colour = colours.Yellow;
valueText.Colour = colours.YellowLight;
return count.ToString() ?? string.Empty;
}
}

public partial class PercentageBreakInfoLine : BreakInfoLine<double>
{
public PercentageBreakInfoLine(LocalisableString name, string prefix = "")
: base(name, prefix)
public PercentageBreakInfoLine(LocalisableString name)
: base(name)
{
}

Expand Down
17 changes: 9 additions & 8 deletions osu.Game/Screens/Play/BreakOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ public IReadOnlyList<BreakPeriod> Breaks
private readonly Container remainingTimeBox;
private readonly RemainingTimeCounter remainingTimeCounter;
private readonly BreakArrows breakArrows;
private readonly ScoreProcessor scoreProcessor;
private readonly BreakInfo info;

public BreakOverlay(bool letterboxing, ScoreProcessor scoreProcessor)
{
this.scoreProcessor = scoreProcessor;
RelativeSizeAxes = Axes.Both;

BreakInfo info;

Child = fadeContainer = new Container
{
Alpha = 0,
Expand Down Expand Up @@ -102,18 +103,18 @@ public BreakOverlay(bool letterboxing, ScoreProcessor scoreProcessor)
}
}
};

if (scoreProcessor != null)
{
info.AccuracyDisplay.Current.BindTo(scoreProcessor.Accuracy);
info.GradeDisplay.Current.BindTo(scoreProcessor.Rank);
}
}

protected override void LoadComplete()
{
base.LoadComplete();
initializeBreaks();

if (scoreProcessor != null)
{
info.AccuracyDisplay.Current.BindTo(scoreProcessor.Accuracy);
info.GradeDisplay.Current.BindTo(scoreProcessor.Rank);
}
}

private void initializeBreaks()
Expand Down

0 comments on commit c56ca40

Please sign in to comment.