1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-28 20:47:22 +08:00

Merge pull request #14068 from Game4all/localise-rankings

Localise rankings overlay
This commit is contained in:
Bartłomiej Dach 2021-07-31 08:51:01 +02:00 committed by GitHub
commit df02ce7c93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 106 additions and 45 deletions

View File

@ -5,6 +5,9 @@ using osu.Framework.Graphics;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Users; using osu.Game.Users;
using osu.Game.Resources.Localisation.Web;
using osu.Framework.Localisation;
using System;
namespace osu.Game.Overlays.Rankings namespace osu.Game.Overlays.Rankings
{ {
@ -29,13 +32,14 @@ namespace osu.Game.Overlays.Rankings
{ {
public RankingsTitle() public RankingsTitle()
{ {
Title = "ranking"; Title = PageTitleStrings.MainRankingControllerDefault;
Description = "find out who's the best right now"; Description = "find out who's the best right now";
IconTexture = "Icons/Hexacons/rankings"; IconTexture = "Icons/Hexacons/rankings";
} }
} }
} }
[LocalisableEnum(typeof(RankingsScopeEnumLocalisationMapper))]
public enum RankingsScope public enum RankingsScope
{ {
Performance, Performance,
@ -43,4 +47,28 @@ namespace osu.Game.Overlays.Rankings
Score, Score,
Country Country
} }
public class RankingsScopeEnumLocalisationMapper : EnumLocalisationMapper<RankingsScope>
{
public override LocalisableString Map(RankingsScope value)
{
switch (value)
{
case RankingsScope.Performance:
return RankingsStrings.TypePerformance;
case RankingsScope.Spotlights:
return RankingsStrings.TypeCharts;
case RankingsScope.Score:
return RankingsStrings.TypeScore;
case RankingsScope.Country:
return RankingsStrings.TypeCountry;
default:
throw new ArgumentOutOfRangeException(nameof(value), value, null);
}
}
}
} }

View File

@ -1,19 +1,43 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Extensions.LocalisationExtensions;
using osu.Framework.Localisation;
using osu.Game.Resources.Localisation.Web;
namespace osu.Game.Overlays.Rankings namespace osu.Game.Overlays.Rankings
{ {
public class RankingsSortTabControl : OverlaySortTabControl<RankingsSortCriteria> public class RankingsSortTabControl : OverlaySortTabControl<RankingsSortCriteria>
{ {
public RankingsSortTabControl() public RankingsSortTabControl()
{ {
Title = "Show"; Title = RankingsStrings.FilterTitle.ToUpper();
} }
} }
[LocalisableEnum(typeof(RankingsSortCriteriaEnumLocalisationMapper))]
public enum RankingsSortCriteria public enum RankingsSortCriteria
{ {
All, All,
Friends Friends
} }
public class RankingsSortCriteriaEnumLocalisationMapper : EnumLocalisationMapper<RankingsSortCriteria>
{
public override LocalisableString Map(RankingsSortCriteria value)
{
switch (value)
{
case RankingsSortCriteria.All:
return SortStrings.All;
case RankingsSortCriteria.Friends:
return SortStrings.Friends;
default:
throw new ArgumentOutOfRangeException(nameof(value), value, null);
}
}
}
} }

View File

@ -16,6 +16,8 @@ using System.Collections.Generic;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Localisation;
using osu.Game.Resources.Localisation.Web;
namespace osu.Game.Overlays.Rankings namespace osu.Game.Overlays.Rankings
{ {
@ -92,10 +94,10 @@ namespace osu.Game.Overlays.Rankings
Margin = new MarginPadding { Bottom = 5 }, Margin = new MarginPadding { Bottom = 5 },
Children = new Drawable[] Children = new Drawable[]
{ {
startDateColumn = new InfoColumn(@"Start Date"), startDateColumn = new InfoColumn(RankingsStrings.SpotlightStartDate),
endDateColumn = new InfoColumn(@"End Date"), endDateColumn = new InfoColumn(RankingsStrings.SpotlightEndDate),
mapCountColumn = new InfoColumn(@"Map Count"), mapCountColumn = new InfoColumn(RankingsStrings.SpotlightMapCount),
participantsColumn = new InfoColumn(@"Participants") participantsColumn = new InfoColumn(RankingsStrings.SpotlightParticipants)
} }
}, },
new RankingsSortTabControl new RankingsSortTabControl
@ -122,22 +124,22 @@ namespace osu.Game.Overlays.Rankings
{ {
startDateColumn.Value = dateToString(response.Spotlight.StartDate); startDateColumn.Value = dateToString(response.Spotlight.StartDate);
endDateColumn.Value = dateToString(response.Spotlight.EndDate); endDateColumn.Value = dateToString(response.Spotlight.EndDate);
mapCountColumn.Value = response.BeatmapSets.Count.ToString(); mapCountColumn.Value = response.BeatmapSets.Count.ToLocalisableString(@"N0");
participantsColumn.Value = response.Spotlight.Participants?.ToString("N0"); participantsColumn.Value = response.Spotlight.Participants?.ToLocalisableString(@"N0");
} }
private string dateToString(DateTimeOffset date) => date.ToString("yyyy-MM-dd"); private LocalisableString dateToString(DateTimeOffset date) => date.ToLocalisableString(@"yyyy-MM-dd");
private class InfoColumn : FillFlowContainer private class InfoColumn : FillFlowContainer
{ {
public string Value public LocalisableString Value
{ {
set => valueText.Text = value; set => valueText.Text = value;
} }
private readonly OsuSpriteText valueText; private readonly OsuSpriteText valueText;
public InfoColumn(string name) public InfoColumn(LocalisableString name)
{ {
AutoSizeAxes = Axes.Both; AutoSizeAxes = Axes.Both;
Direction = FillDirection.Vertical; Direction = FillDirection.Vertical;

View File

@ -9,6 +9,8 @@ using osu.Game.Graphics;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Game.Resources.Localisation.Web;
using osu.Framework.Localisation;
namespace osu.Game.Overlays.Rankings.Tables namespace osu.Game.Overlays.Rankings.Tables
{ {
@ -21,12 +23,12 @@ namespace osu.Game.Overlays.Rankings.Tables
protected override RankingsTableColumn[] CreateAdditionalHeaders() => new[] protected override RankingsTableColumn[] CreateAdditionalHeaders() => new[]
{ {
new RankingsTableColumn("Active Users", Anchor.Centre, new Dimension(GridSizeMode.AutoSize)), new RankingsTableColumn(RankingsStrings.StatActiveUsers, Anchor.Centre, new Dimension(GridSizeMode.AutoSize)),
new RankingsTableColumn("Play Count", Anchor.Centre, new Dimension(GridSizeMode.AutoSize)), new RankingsTableColumn(RankingsStrings.StatPlayCount, Anchor.Centre, new Dimension(GridSizeMode.AutoSize)),
new RankingsTableColumn("Ranked Score", Anchor.Centre, new Dimension(GridSizeMode.AutoSize)), new RankingsTableColumn(RankingsStrings.StatRankedScore, Anchor.Centre, new Dimension(GridSizeMode.AutoSize)),
new RankingsTableColumn("Avg. Score", Anchor.Centre, new Dimension(GridSizeMode.AutoSize)), new RankingsTableColumn(RankingsStrings.StatAverageScore, Anchor.Centre, new Dimension(GridSizeMode.AutoSize)),
new RankingsTableColumn("Performance", Anchor.Centre, new Dimension(GridSizeMode.AutoSize), true), new RankingsTableColumn(RankingsStrings.StatPerformance, Anchor.Centre, new Dimension(GridSizeMode.AutoSize), true),
new RankingsTableColumn("Avg. Perf.", Anchor.Centre, new Dimension(GridSizeMode.AutoSize)), new RankingsTableColumn(RankingsStrings.StatAveragePerformance, Anchor.Centre, new Dimension(GridSizeMode.AutoSize)),
}; };
protected override Country GetCountry(CountryStatistics item) => item.Country; protected override Country GetCountry(CountryStatistics item) => item.Country;
@ -35,29 +37,29 @@ namespace osu.Game.Overlays.Rankings.Tables
protected override Drawable[] CreateAdditionalContent(CountryStatistics item) => new Drawable[] protected override Drawable[] CreateAdditionalContent(CountryStatistics item) => new Drawable[]
{ {
new ColoredRowText new ColouredRowText
{ {
Text = $@"{item.ActiveUsers:N0}", Text = item.ActiveUsers.ToLocalisableString(@"N0")
}, },
new ColoredRowText new ColouredRowText
{ {
Text = $@"{item.PlayCount:N0}", Text = item.PlayCount.ToLocalisableString(@"N0")
}, },
new ColoredRowText new ColouredRowText
{ {
Text = $@"{item.RankedScore:N0}", Text = item.RankedScore.ToLocalisableString(@"N0")
}, },
new ColoredRowText new ColouredRowText
{ {
Text = $@"{item.RankedScore / Math.Max(item.ActiveUsers, 1):N0}", Text = (item.RankedScore / Math.Max(item.ActiveUsers, 1)).ToLocalisableString(@"N0")
}, },
new RowText new RowText
{ {
Text = $@"{item.Performance:N0}", Text = item.Performance.ToLocalisableString(@"N0")
}, },
new ColoredRowText new ColouredRowText
{ {
Text = $@"{item.Performance / Math.Max(item.ActiveUsers, 1):N0}", Text = (item.Performance / Math.Max(item.ActiveUsers, 1)).ToLocalisableString(@"N0")
} }
}; };

View File

@ -4,6 +4,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Localisation;
using osu.Game.Resources.Localisation.Web;
using osu.Game.Users; using osu.Game.Users;
namespace osu.Game.Overlays.Rankings.Tables namespace osu.Game.Overlays.Rankings.Tables
@ -17,12 +19,12 @@ namespace osu.Game.Overlays.Rankings.Tables
protected override RankingsTableColumn[] CreateUniqueHeaders() => new[] protected override RankingsTableColumn[] CreateUniqueHeaders() => new[]
{ {
new RankingsTableColumn("Performance", Anchor.Centre, new Dimension(GridSizeMode.AutoSize), true), new RankingsTableColumn(RankingsStrings.StatPerformance, Anchor.Centre, new Dimension(GridSizeMode.AutoSize), true),
}; };
protected override Drawable[] CreateUniqueContent(UserStatistics item) => new Drawable[] protected override Drawable[] CreateUniqueContent(UserStatistics item) => new Drawable[]
{ {
new RowText { Text = $@"{item.PP:N0}", } new RowText { Text = item.PP.ToLocalisableString(@"N0"), }
}; };
} }
} }

View File

@ -80,7 +80,7 @@ namespace osu.Game.Overlays.Rankings.Tables
private OsuSpriteText createIndexDrawable(int index) => new RowText private OsuSpriteText createIndexDrawable(int index) => new RowText
{ {
Text = $"#{index + 1}", Text = (index + 1).ToLocalisableString(@"\##"),
Font = OsuFont.GetFont(size: TEXT_SIZE, weight: FontWeight.SemiBold) Font = OsuFont.GetFont(size: TEXT_SIZE, weight: FontWeight.SemiBold)
}; };
@ -144,7 +144,7 @@ namespace osu.Game.Overlays.Rankings.Tables
} }
} }
protected class ColoredRowText : RowText protected class ColouredRowText : RowText
{ {
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider) private void load(OverlayColourProvider colourProvider)

View File

@ -4,6 +4,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Localisation;
using osu.Game.Resources.Localisation.Web;
using osu.Game.Users; using osu.Game.Users;
namespace osu.Game.Overlays.Rankings.Tables namespace osu.Game.Overlays.Rankings.Tables
@ -17,19 +19,19 @@ namespace osu.Game.Overlays.Rankings.Tables
protected override RankingsTableColumn[] CreateUniqueHeaders() => new[] protected override RankingsTableColumn[] CreateUniqueHeaders() => new[]
{ {
new RankingsTableColumn("Total Score", Anchor.Centre, new Dimension(GridSizeMode.AutoSize)), new RankingsTableColumn(RankingsStrings.StatTotalScore, Anchor.Centre, new Dimension(GridSizeMode.AutoSize)),
new RankingsTableColumn("Ranked Score", Anchor.Centre, new Dimension(GridSizeMode.AutoSize), true) new RankingsTableColumn(RankingsStrings.StatRankedScore, Anchor.Centre, new Dimension(GridSizeMode.AutoSize), true)
}; };
protected override Drawable[] CreateUniqueContent(UserStatistics item) => new Drawable[] protected override Drawable[] CreateUniqueContent(UserStatistics item) => new Drawable[]
{ {
new ColoredRowText new ColouredRowText
{ {
Text = $@"{item.TotalScore:N0}", Text = item.TotalScore.ToLocalisableString(@"N0"),
}, },
new RowText new RowText
{ {
Text = $@"{item.RankedScore:N0}", Text = item.RankedScore.ToLocalisableString(@"N0")
} }
}; };
} }

View File

@ -10,6 +10,7 @@ using osu.Game.Graphics.Containers;
using osu.Game.Users; using osu.Game.Users;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Framework.Localisation; using osu.Framework.Localisation;
using osu.Game.Resources.Localisation.Web;
namespace osu.Game.Overlays.Rankings.Tables namespace osu.Game.Overlays.Rankings.Tables
{ {
@ -20,12 +21,12 @@ namespace osu.Game.Overlays.Rankings.Tables
{ {
} }
protected virtual IEnumerable<string> GradeColumns => new List<string> { "SS", "S", "A" }; protected virtual IEnumerable<LocalisableString> GradeColumns => new List<LocalisableString> { RankingsStrings.Statss, RankingsStrings.Stats, RankingsStrings.Stata };
protected override RankingsTableColumn[] CreateAdditionalHeaders() => new[] protected override RankingsTableColumn[] CreateAdditionalHeaders() => new[]
{ {
new RankingsTableColumn("Accuracy", Anchor.Centre, new Dimension(GridSizeMode.AutoSize)), new RankingsTableColumn(RankingsStrings.StatAccuracy, Anchor.Centre, new Dimension(GridSizeMode.AutoSize)),
new RankingsTableColumn("Play Count", Anchor.Centre, new Dimension(GridSizeMode.AutoSize)), new RankingsTableColumn(RankingsStrings.StatPlayCount, Anchor.Centre, new Dimension(GridSizeMode.AutoSize)),
}.Concat(CreateUniqueHeaders()) }.Concat(CreateUniqueHeaders())
.Concat(GradeColumns.Select(grade => new GradeTableColumn(grade, Anchor.Centre, new Dimension(GridSizeMode.AutoSize)))) .Concat(GradeColumns.Select(grade => new GradeTableColumn(grade, Anchor.Centre, new Dimension(GridSizeMode.AutoSize))))
.ToArray(); .ToArray();
@ -46,13 +47,13 @@ namespace osu.Game.Overlays.Rankings.Tables
protected sealed override Drawable[] CreateAdditionalContent(UserStatistics item) => new[] protected sealed override Drawable[] CreateAdditionalContent(UserStatistics item) => new[]
{ {
new ColoredRowText { Text = item.DisplayAccuracy, }, new ColouredRowText { Text = item.DisplayAccuracy, },
new ColoredRowText { Text = $@"{item.PlayCount:N0}", }, new ColouredRowText { Text = item.PlayCount.ToLocalisableString(@"N0") },
}.Concat(CreateUniqueContent(item)).Concat(new[] }.Concat(CreateUniqueContent(item)).Concat(new[]
{ {
new ColoredRowText { Text = $@"{item.GradesCount[ScoreRank.XH] + item.GradesCount[ScoreRank.X]:N0}", }, new ColouredRowText { Text = (item.GradesCount[ScoreRank.XH] + item.GradesCount[ScoreRank.X]).ToLocalisableString(@"N0"), },
new ColoredRowText { Text = $@"{item.GradesCount[ScoreRank.SH] + item.GradesCount[ScoreRank.S]:N0}", }, new ColouredRowText { Text = (item.GradesCount[ScoreRank.SH] + item.GradesCount[ScoreRank.S]).ToLocalisableString(@"N0"), },
new ColoredRowText { Text = $@"{item.GradesCount[ScoreRank.A]:N0}", } new ColouredRowText { Text = item.GradesCount[ScoreRank.A].ToLocalisableString(@"N0"), }
}).ToArray(); }).ToArray();
protected abstract RankingsTableColumn[] CreateUniqueHeaders(); protected abstract RankingsTableColumn[] CreateUniqueHeaders();