Merge pull request #23640 from 17steen/make_pause_menu_translatable

Make GameplayMenuOverlay translatable
This commit is contained in:
Dean Herbert 2023-05-30 09:36:19 +09:00 committed by GitHub
commit 61d9b50993
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 66 additions and 11 deletions

View File

@ -0,0 +1,49 @@
// 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.
using osu.Framework.Localisation;
namespace osu.Game.Localisation
{
public static class GameplayMenuOverlayStrings
{
private const string prefix = @"osu.Game.Resources.Localisation.GameplayMenuOverlay";
/// <summary>
/// "Continue"
/// </summary>
public static LocalisableString Continue => new TranslatableString(getKey(@"continue"), @"Continue");
/// <summary>
/// "Retry"
/// </summary>
public static LocalisableString Retry => new TranslatableString(getKey(@"retry"), @"Retry");
/// <summary>
/// "Quit"
/// </summary>
public static LocalisableString Quit => new TranslatableString(getKey(@"quit"), @"Quit");
/// <summary>
/// "failed"
/// </summary>
public static LocalisableString FailedHeader => new TranslatableString(getKey(@"failed_header"), @"failed");
/// <summary>
/// "paused"
/// </summary>
public static LocalisableString PausedHeader => new TranslatableString(getKey(@"paused_header"), @"paused");
/// <summary>
/// "Retry count: "
/// </summary>
public static LocalisableString RetryCount => new TranslatableString(getKey(@"retry_count"), @"Retry count: ");
/// <summary>
/// "Song progress: "
/// </summary>
public static LocalisableString SongProgress => new TranslatableString(getKey(@"song_progress"), @"Song progress: ");
private static string getKey(string key) => $@"{prefix}:{key}";
}
}

View File

@ -15,6 +15,8 @@ using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Localisation;
using osu.Game.Localisation;
namespace osu.Game.Screens.Play namespace osu.Game.Screens.Play
{ {
@ -22,13 +24,13 @@ namespace osu.Game.Screens.Play
{ {
public Func<Task<ScoreInfo>> SaveReplay; public Func<Task<ScoreInfo>> SaveReplay;
public override string Header => "failed"; public override LocalisableString Header => GameplayMenuOverlayStrings.FailedHeader;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours)
{ {
AddButton("Retry", colours.YellowDark, () => OnRetry?.Invoke()); AddButton(GameplayMenuOverlayStrings.Retry, colours.YellowDark, () => OnRetry?.Invoke());
AddButton("Quit", new Color4(170, 27, 39, 255), () => OnQuit?.Invoke()); AddButton(GameplayMenuOverlayStrings.Quit, new Color4(170, 27, 39, 255), () => OnQuit?.Invoke());
// from #10339 maybe this is a better visual effect // from #10339 maybe this is a better visual effect
Add(new Container Add(new Container
{ {

View File

@ -12,6 +12,7 @@ using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
@ -20,6 +21,7 @@ using osu.Game.Graphics.UserInterface;
using osu.Game.Input.Bindings; using osu.Game.Input.Bindings;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
using osu.Game.Localisation;
namespace osu.Game.Screens.Play namespace osu.Game.Screens.Play
{ {
@ -49,7 +51,7 @@ namespace osu.Game.Screens.Play
/// </summary> /// </summary>
protected virtual Action SelectAction => () => InternalButtons.Selected?.TriggerClick(); protected virtual Action SelectAction => () => InternalButtons.Selected?.TriggerClick();
public abstract string Header { get; } public abstract LocalisableString Header { get; }
protected SelectionCycleFillFlowContainer<DialogButton> InternalButtons = null!; protected SelectionCycleFillFlowContainer<DialogButton> InternalButtons = null!;
public IReadOnlyList<DialogButton> Buttons => InternalButtons; public IReadOnlyList<DialogButton> Buttons => InternalButtons;
@ -153,7 +155,7 @@ namespace osu.Game.Screens.Play
protected override bool OnMouseMove(MouseMoveEvent e) => true; protected override bool OnMouseMove(MouseMoveEvent e) => true;
protected void AddButton(string text, Color4 colour, Action? action) protected void AddButton(LocalisableString text, Color4 colour, Action? action)
{ {
var button = new Button var button = new Button
{ {
@ -209,13 +211,13 @@ namespace osu.Game.Screens.Play
private void updateInfoText() private void updateInfoText()
{ {
playInfoText.Clear(); playInfoText.Clear();
playInfoText.AddText("Retry count: "); playInfoText.AddText(GameplayMenuOverlayStrings.RetryCount);
playInfoText.AddText(retries.ToString(), cp => cp.Font = cp.Font.With(weight: FontWeight.Bold)); playInfoText.AddText(retries.ToString(), cp => cp.Font = cp.Font.With(weight: FontWeight.Bold));
if (getSongProgress() is int progress) if (getSongProgress() is int progress)
{ {
playInfoText.NewLine(); playInfoText.NewLine();
playInfoText.AddText("Song progress: "); playInfoText.AddText(GameplayMenuOverlayStrings.SongProgress);
playInfoText.AddText($"{progress}%", cp => cp.Font = cp.Font.With(weight: FontWeight.Bold)); playInfoText.AddText($"{progress}%", cp => cp.Font = cp.Font.With(weight: FontWeight.Bold));
} }
} }

View File

@ -9,9 +9,11 @@ using osu.Framework.Allocation;
using osu.Framework.Audio; using osu.Framework.Audio;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Game.Audio; using osu.Game.Audio;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Input.Bindings; using osu.Game.Input.Bindings;
using osu.Game.Localisation;
using osu.Game.Skinning; using osu.Game.Skinning;
using osuTK.Graphics; using osuTK.Graphics;
@ -23,7 +25,7 @@ namespace osu.Game.Screens.Play
public override bool IsPresent => base.IsPresent || pauseLoop.IsPlaying; public override bool IsPresent => base.IsPresent || pauseLoop.IsPlaying;
public override string Header => "paused"; public override LocalisableString Header => GameplayMenuOverlayStrings.PausedHeader;
private SkinnableSound pauseLoop; private SkinnableSound pauseLoop;
@ -32,9 +34,9 @@ namespace osu.Game.Screens.Play
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours)
{ {
AddButton("Continue", colours.Green, () => OnResume?.Invoke()); AddButton(GameplayMenuOverlayStrings.Continue, colours.Green, () => OnResume?.Invoke());
AddButton("Retry", colours.YellowDark, () => OnRetry?.Invoke()); AddButton(GameplayMenuOverlayStrings.Retry, colours.YellowDark, () => OnRetry?.Invoke());
AddButton("Quit", new Color4(170, 27, 39, 255), () => OnQuit?.Invoke()); AddButton(GameplayMenuOverlayStrings.Quit, new Color4(170, 27, 39, 255), () => OnQuit?.Invoke());
AddInternal(pauseLoop = new SkinnableSound(new SampleInfo("Gameplay/pause-loop")) AddInternal(pauseLoop = new SkinnableSound(new SampleInfo("Gameplay/pause-loop"))
{ {