From 4aee76456f8cdb8bade6d037d1a9bb02af125ee8 Mon Sep 17 00:00:00 2001 From: Robin Avery Date: Sun, 6 Jun 2021 05:34:32 -0400 Subject: [PATCH] Replace localised strings with static English --- osu.Game/Localisation/SkinEditorStrings.cs | 74 ------------- .../Skinning/Editor/SkinSelectionHandler.cs | 101 +++++++----------- 2 files changed, 36 insertions(+), 139 deletions(-) delete mode 100644 osu.Game/Localisation/SkinEditorStrings.cs diff --git a/osu.Game/Localisation/SkinEditorStrings.cs b/osu.Game/Localisation/SkinEditorStrings.cs deleted file mode 100644 index 24a077963f..0000000000 --- a/osu.Game/Localisation/SkinEditorStrings.cs +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (c) ppy Pty Ltd . 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 SkinEditorStrings - { - private const string prefix = "osu.Game.Localisation.SkinEditor"; - - /// - /// "anchor" - /// - public static LocalisableString Anchor => new TranslatableString(getKey("anchor"), "anchor"); - - /// - /// "origin" - /// - public static LocalisableString Origin => new TranslatableString(getKey("origin"), "origin"); - - /// - /// "top-left" - /// - public static LocalisableString TopLeft => new TranslatableString(getKey("top_left"), "top-left"); - - /// - /// "top-centre" - /// - public static LocalisableString TopCentre => new TranslatableString(getKey("top_centre"), "top-centre"); - - /// - /// "top-right" - /// - public static LocalisableString TopRight => new TranslatableString(getKey("top_right"), "top-right"); - - /// - /// "centre-left" - /// - public static LocalisableString CentreLeft => new TranslatableString(getKey("centre_left"), "centre-left"); - - /// - /// "centre" - /// - public static LocalisableString Centre => new TranslatableString(getKey("centre"), "centre"); - - /// - /// "centre-right" - /// - public static LocalisableString CentreRight => new TranslatableString(getKey("centre_right"), "centre-right"); - - /// - /// "bottom-left" - /// - public static LocalisableString BottomLeft => new TranslatableString(getKey("bottom_left"), "bottom-left"); - - /// - /// "bottom-centre" - /// - public static LocalisableString BottomCentre => new TranslatableString(getKey("bottom_centre"), "bottom-centre"); - - /// - /// "bottom-right" - /// - public static LocalisableString BottomRight => new TranslatableString(getKey("bottom_right"), "bottom-right"); - - /// - /// "closest" - /// - public static LocalisableString Closest => new TranslatableString(getKey("closest"), "closest"); - - private static string getKey(string key) => $"{prefix}:{key}"; - } -} diff --git a/osu.Game/Skinning/Editor/SkinSelectionHandler.cs b/osu.Game/Skinning/Editor/SkinSelectionHandler.cs index 956f6c79f9..fbe7cc6d91 100644 --- a/osu.Game/Skinning/Editor/SkinSelectionHandler.cs +++ b/osu.Game/Skinning/Editor/SkinSelectionHandler.cs @@ -11,15 +11,12 @@ using osu.Framework.Extensions.EnumExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.UserInterface; -using osu.Framework.Localisation; using osu.Framework.Utils; using osu.Game.Extensions; using osu.Game.Graphics.UserInterface; using osu.Game.Rulesets.Edit; using osu.Game.Screens.Edit.Compose.Components; using osuTK; -using Humanizer; -using osu.Game.Localisation; namespace osu.Game.Skinning.Editor { @@ -28,7 +25,7 @@ namespace osu.Game.Skinning.Editor /// ///

Keeps track of whether a is using the closest anchor point within its parent, /// or whether the user is overriding its anchor point.

- ///

Each key is either a direct cast of an Anchor value, or it is equal to . This is done + ///

Each key is either a direct cast of an Anchor value, or it is equal to . This is done /// because the "Closest" menu item is not a valid anchor, so something other than an anchor must be used.

///

Each value is a . If the is , the user has /// overridden the anchor point. @@ -42,62 +39,39 @@ namespace osu.Game.Skinning.Editor /// private readonly ConditionalWeakTable isDrawableUsingClosestAnchorLookup = new ConditionalWeakTable(); + private const string closest_text = @"Closest"; + ///

/// The hash code of the "Closest" menu item in the anchor point context menu. /// - /// This does not need to change with locale; it need only be constant and distinct from any values. - private static readonly int hash_of_closest_anchor_menu_item = @"Closest".GetHashCode(); + /// Needs only be constant and distinct from any values. + private static readonly int closest_text_hash = closest_text.GetHashCode(); - /// Used by to populate and . - private static readonly LocalisableString[] unbound_anchor_menu_items = + private static readonly Dictionary anchor_menu_items; + private static readonly Dictionary origin_menu_items; + + static SkinSelectionHandler() { - SkinEditorStrings.Closest, - SkinEditorStrings.TopLeft, - SkinEditorStrings.TopCentre, - SkinEditorStrings.TopRight, - SkinEditorStrings.CentreLeft, - SkinEditorStrings.Centre, - SkinEditorStrings.CentreRight, - SkinEditorStrings.BottomLeft, - SkinEditorStrings.BottomCentre, - SkinEditorStrings.BottomRight, - }; + var anchorMenuSubset = new[] + { + Anchor.TopLeft, + Anchor.TopCentre, + Anchor.TopRight, + Anchor.CentreLeft, + Anchor.Centre, + Anchor.CentreRight, + Anchor.BottomLeft, + Anchor.BottomCentre, + Anchor.BottomRight, + }; - /// Used by to populate and . - private static readonly int[] anchor_menu_hashes = - new[] - { - Anchor.TopLeft, - Anchor.TopCentre, - Anchor.TopRight, - Anchor.CentreLeft, - Anchor.Centre, - Anchor.CentreRight, - Anchor.BottomLeft, - Anchor.BottomCentre, - Anchor.BottomRight, - } - .Cast() - .Prepend(hash_of_closest_anchor_menu_item) - .ToArray(); + var texts = anchorMenuSubset.Select(a => a.ToString()).Prepend(closest_text).ToArray(); + var hashes = anchorMenuSubset.Cast().Prepend(closest_text_hash).ToArray(); - private Dictionary localisedAnchorMenuItems; - private Dictionary localisedOriginMenuItems; - private ILocalisedBindableString localisedAnchor; - private ILocalisedBindableString localisedOrigin; - - [BackgroundDependencyLoader] - private void load(LocalisationManager localisation) - { - localisedAnchor = localisation.GetLocalisedString(SkinEditorStrings.Anchor); - localisedOrigin = localisation.GetLocalisedString(SkinEditorStrings.Origin); - - var boundAnchorMenuItems = unbound_anchor_menu_items.Select(localisation.GetLocalisedString).ToArray(); - - var anchorPairs = anchor_menu_hashes.Zip(boundAnchorMenuItems, (k, v) => new KeyValuePair(k, v)).ToArray(); - localisedAnchorMenuItems = new Dictionary(anchorPairs); - var originPairs = anchorPairs.Where(pair => pair.Key != hash_of_closest_anchor_menu_item); - localisedOriginMenuItems = new Dictionary(originPairs); + var anchorPairs = hashes.Zip(texts, (k, v) => new KeyValuePair(k, v)).ToArray(); + anchor_menu_items = new Dictionary(anchorPairs); + var originPairs = anchorPairs.Where(pair => pair.Key != closest_text_hash); + origin_menu_items = new Dictionary(originPairs); } private Anchor getClosestAnchorForDrawable(Drawable drawable) @@ -147,9 +121,6 @@ namespace osu.Game.Skinning.Editor /// Defaults to , meaning anchors are closest by default. private BindableBool isDrawableUsingClosestAnchor(Drawable drawable) => isDrawableUsingClosestAnchorLookup.GetValue(drawable, _ => new BindableBool(true)); - // There may be a more generalised form of this somewhere in the codebase. If so, use that. - private static string getSentenceCaseLocalisedString(ILocalisedBindableString ls) => ls.Value.Transform(To.SentenceCase); - [Resolved] private SkinEditor skinEditor { get; set; } @@ -316,29 +287,29 @@ namespace osu.Game.Skinning.Editor { int checkAnchor(Drawable drawable) => isDrawableUsingClosestAnchor(drawable).Value - ? hash_of_closest_anchor_menu_item + ? closest_text_hash : (int)drawable.Anchor; - yield return new OsuMenuItem(getSentenceCaseLocalisedString(localisedAnchor)) + yield return new OsuMenuItem(nameof(Anchor)) { - Items = createAnchorItems(localisedAnchorMenuItems, checkAnchor, applyAnchor).ToArray() + Items = createAnchorItems(anchor_menu_items, checkAnchor, applyAnchor).ToArray() }; - yield return new OsuMenuItem(getSentenceCaseLocalisedString(localisedOrigin)) + yield return new OsuMenuItem(nameof(Origin)) { // Origins can't be "closest" so we just cast to int - Items = createAnchorItems(localisedOriginMenuItems, d => (int)d.Origin, applyOrigin).ToArray() + Items = createAnchorItems(origin_menu_items, d => (int)d.Origin, applyOrigin).ToArray() }; foreach (var item in base.GetContextMenuItemsForSelection(selection)) yield return item; - IEnumerable createAnchorItems(IDictionary items, Func checkFunction, Action applyFunction) => + IEnumerable createAnchorItems(IDictionary items, Func checkFunction, Action applyFunction) => items.Select(pair => { - var (hash, ls) = pair; + var (hash, text) = pair; - return new TernaryStateRadioMenuItem(getSentenceCaseLocalisedString(ls), MenuItemType.Standard, _ => applyFunction(hash)) + return new TernaryStateRadioMenuItem(text, MenuItemType.Standard, _ => applyFunction(hash)) { State = { Value = GetStateFromSelection(selection, c => checkFunction((Drawable)c.Item) == hash) } }; @@ -397,7 +368,7 @@ namespace osu.Game.Skinning.Editor { var isUsingClosestAnchor = isDrawableUsingClosestAnchor(drawable); - if (hash == hash_of_closest_anchor_menu_item) + if (hash == closest_text_hash) { isUsingClosestAnchor.Value = true; return getClosestAnchorForDrawable(drawable);