1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 17:23:22 +08:00

Make GameplayMenuOverlay translatable

This allows translator to translate the pause and failed in game menus
This commit is contained in:
Robin Oger 2023-05-23 19:21:44 +02:00
parent e467791d0b
commit 0ea3eea8d6
4 changed files with 66 additions and 12 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>
/// "you're dead, try again?"
/// </summary>
public static LocalisableString FailedDescription => new TranslatableString(getKey(@"failed_description"), @"you're dead, try again?");
/// <summary>
/// "you're not going to do what i think you're going to do, are ya?"
/// </summary>
public static LocalisableString PausedDescription => new TranslatableString(getKey(@"paused_description"), @"you're not going to do what i think you're going to do, are ya?");
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.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Localisation;
using osu.Game.Localisation;
namespace osu.Game.Screens.Play
{
@ -22,14 +24,14 @@ namespace osu.Game.Screens.Play
{
public Func<Task<ScoreInfo>> SaveReplay;
public override string Header => "failed";
public override string Description => "you're dead, try again?";
public override LocalisableString Header => GameplayMenuOverlayStrings.FailedHeader;
public override LocalisableString Description => GameplayMenuOverlayStrings.FailedDescription;
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
AddButton("Retry", colours.YellowDark, () => OnRetry?.Invoke());
AddButton("Quit", new Color4(170, 27, 39, 255), () => OnQuit?.Invoke());
AddButton(GameplayMenuOverlayStrings.Retry, colours.YellowDark, () => OnRetry?.Invoke());
AddButton(GameplayMenuOverlayStrings.Quit, new Color4(170, 27, 39, 255), () => OnQuit?.Invoke());
// from #10339 maybe this is a better visual effect
Add(new Container
{

View File

@ -15,6 +15,7 @@ using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
@ -51,9 +52,9 @@ namespace osu.Game.Screens.Play
/// </summary>
protected virtual Action SelectAction => () => InternalButtons.Selected?.TriggerClick();
public abstract string Header { get; }
public abstract LocalisableString Header { get; }
public abstract string Description { get; }
public abstract LocalisableString Description { get; }
protected SelectionCycleFillFlowContainer<DialogButton> InternalButtons;
public IReadOnlyList<DialogButton> Buttons => InternalButtons;
@ -170,7 +171,7 @@ namespace osu.Game.Screens.Play
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
{

View File

@ -9,9 +9,11 @@ using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Graphics;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Game.Audio;
using osu.Game.Graphics;
using osu.Game.Input.Bindings;
using osu.Game.Localisation;
using osu.Game.Skinning;
using osuTK.Graphics;
@ -23,8 +25,8 @@ namespace osu.Game.Screens.Play
public override bool IsPresent => base.IsPresent || pauseLoop.IsPlaying;
public override string Header => "paused";
public override string Description => "you're not going to do what i think you're going to do, are ya?";
public override LocalisableString Header => GameplayMenuOverlayStrings.PausedHeader;
public override LocalisableString Description => GameplayMenuOverlayStrings.PausedDescription;
private SkinnableSound pauseLoop;
@ -33,9 +35,9 @@ namespace osu.Game.Screens.Play
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
AddButton("Continue", colours.Green, () => OnResume?.Invoke());
AddButton("Retry", colours.YellowDark, () => OnRetry?.Invoke());
AddButton("Quit", new Color4(170, 27, 39, 255), () => OnQuit?.Invoke());
AddButton(GameplayMenuOverlayStrings.Continue, colours.Green, () => OnResume?.Invoke());
AddButton(GameplayMenuOverlayStrings.Retry, colours.YellowDark, () => OnRetry?.Invoke());
AddButton(GameplayMenuOverlayStrings.Quit, new Color4(170, 27, 39, 255), () => OnQuit?.Invoke());
AddInternal(pauseLoop = new SkinnableSound(new SampleInfo("Gameplay/pause-loop"))
{