1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 20:32:55 +08:00

Merge pull request #13911 from kj415j45/localisation-base

Add support for localising breadcrumb controls
This commit is contained in:
Dean Herbert 2021-07-19 02:09:11 +09:00 committed by GitHub
commit 4aa0e62673
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 8 deletions

View File

@ -7,6 +7,7 @@ using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Localisation;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Overlays.Wiki; using osu.Game.Overlays.Wiki;
@ -96,7 +97,7 @@ namespace osu.Game.Tests.Visual.Online
private class TestHeader : WikiHeader private class TestHeader : WikiHeader
{ {
public IReadOnlyList<string> TabControlItems => TabControl.Items; public IReadOnlyList<LocalisableString?> TabControlItems => TabControl.Items;
} }
} }
} }

View File

@ -14,6 +14,7 @@ using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
@ -153,6 +154,27 @@ namespace osu.Game.Graphics.UserInterface
AutoSizeAxes = Axes.X; AutoSizeAxes = Axes.X;
RelativeSizeAxes = Axes.Y; RelativeSizeAxes = Axes.Y;
LocalisableString text;
switch (value)
{
case IHasDescription hasDescription:
text = hasDescription.GetDescription();
break;
case Enum e:
text = e.GetLocalisableDescription();
break;
case LocalisableString l:
text = l;
break;
default:
text = value.ToString();
break;
}
Children = new Drawable[] Children = new Drawable[]
{ {
Text = new OsuSpriteText Text = new OsuSpriteText
@ -160,7 +182,7 @@ namespace osu.Game.Graphics.UserInterface
Margin = new MarginPadding { Top = 5, Bottom = 5 }, Margin = new MarginPadding { Top = 5, Bottom = 5 },
Origin = Anchor.BottomLeft, Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft, Anchor = Anchor.BottomLeft,
Text = (value as IHasDescription)?.Description ?? (value as Enum)?.GetLocalisableDescription() ?? value.ToString(), Text = text,
Font = OsuFont.GetFont(size: 14) Font = OsuFont.GetFont(size: 14)
}, },
Bar = new Box Bar = new Box

View File

@ -4,15 +4,16 @@
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Framework.Localisation;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
namespace osu.Game.Overlays namespace osu.Game.Overlays
{ {
public abstract class BreadcrumbControlOverlayHeader : TabControlOverlayHeader<string> public abstract class BreadcrumbControlOverlayHeader : TabControlOverlayHeader<LocalisableString?>
{ {
protected override OsuTabControl<string> CreateTabControl() => new OverlayHeaderBreadcrumbControl(); protected override OsuTabControl<LocalisableString?> CreateTabControl() => new OverlayHeaderBreadcrumbControl();
public class OverlayHeaderBreadcrumbControl : BreadcrumbControl<string> public class OverlayHeaderBreadcrumbControl : BreadcrumbControl<LocalisableString?>
{ {
public OverlayHeaderBreadcrumbControl() public OverlayHeaderBreadcrumbControl()
{ {
@ -26,7 +27,7 @@ namespace osu.Game.Overlays
AccentColour = colourProvider.Light2; AccentColour = colourProvider.Light2;
} }
protected override TabItem<string> CreateTabItem(string value) => new ControlTabItem(value) protected override TabItem<LocalisableString?> CreateTabItem(LocalisableString? value) => new ControlTabItem(value)
{ {
AccentColour = AccentColour, AccentColour = AccentColour,
}; };
@ -35,7 +36,7 @@ namespace osu.Game.Overlays
{ {
protected override float ChevronSize => 8; protected override float ChevronSize => 8;
public ControlTabItem(string value) public ControlTabItem(LocalisableString? value)
: base(value) : base(value)
{ {
RelativeSizeAxes = Axes.Y; RelativeSizeAxes = Axes.Y;

View File

@ -5,6 +5,7 @@ using System;
using System.Linq; using System.Linq;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Localisation;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
namespace osu.Game.Overlays.Wiki namespace osu.Game.Overlays.Wiki
@ -51,7 +52,7 @@ namespace osu.Game.Overlays.Wiki
Current.Value = e.NewValue.Title; Current.Value = e.NewValue.Title;
} }
private void onCurrentChange(ValueChangedEvent<string> e) private void onCurrentChange(ValueChangedEvent<LocalisableString?> e)
{ {
if (e.NewValue == TabControl.Items.LastOrDefault()) if (e.NewValue == TabControl.Items.LastOrDefault())
return; return;