From bb0fd547132a72d0ccf7f5c549b4f68064bb96bf Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 25 Jun 2020 14:18:57 +0200 Subject: [PATCH] better number formatting --- TouchyTickets/Content/Content.mgcb | 6 +++++ .../Content/Localization/Localization.de.json | 1 + .../Content/Localization/Localization.json | 1 + .../Localization/NumberFormat.de.json5 | 14 ++++++++++ .../Content/Localization/NumberFormat.json5 | 14 ++++++++++ TouchyTickets/Localization.cs | 5 ++-- TouchyTickets/Ui.cs | 26 +++++++------------ 7 files changed, 48 insertions(+), 19 deletions(-) create mode 100644 TouchyTickets/Content/Localization/NumberFormat.de.json5 create mode 100644 TouchyTickets/Content/Localization/NumberFormat.json5 diff --git a/TouchyTickets/Content/Content.mgcb b/TouchyTickets/Content/Content.mgcb index 0c924d0..ac46eec 100644 --- a/TouchyTickets/Content/Content.mgcb +++ b/TouchyTickets/Content/Content.mgcb @@ -86,3 +86,9 @@ /processorParam:TextureFormat=Color /build:Textures/Ui.png +#begin Localization/NumberFormat.de.json5 +/copy:Localization/NumberFormat.de.json5 + +#begin Localization/NumberFormat.json5 +/copy:Localization/NumberFormat.json5 + diff --git a/TouchyTickets/Content/Localization/Localization.de.json b/TouchyTickets/Content/Localization/Localization.de.json index 87e514b..c6e8f33 100644 --- a/TouchyTickets/Content/Localization/Localization.de.json +++ b/TouchyTickets/Content/Localization/Localization.de.json @@ -12,6 +12,7 @@ "Options": "Optionen", "RainingTicketLimit": "Max. Fallende Tickets", "SoundVolume": "Lautstärke", + "AGameByEllpeck": "Ein Spiel von Ellpeck", "----- Tutorial -----": "", "Tutorial1": "Hi! Willkommen zu Touchy Tickets. Um das Spiel zu starten, tippe einfach den Ticket-Laden an, um ein zu verkaufen. Verkaufe erstmal 50!", "Tutorial2": "Super! Jetzt kannst du deine erste Attraktion kaufen. Wechsel durch Wischen zum rechten Menü und kaufe ein Karussell.", diff --git a/TouchyTickets/Content/Localization/Localization.json b/TouchyTickets/Content/Localization/Localization.json index add9802..8e7e44d 100644 --- a/TouchyTickets/Content/Localization/Localization.json +++ b/TouchyTickets/Content/Localization/Localization.json @@ -12,6 +12,7 @@ "Options": "Options", "RainingTicketLimit": "Max Raining Tickets", "SoundVolume": "Sound Volume", + "AGameByEllpeck":"A game by Ellpeck", "----- Tutorial -----": "", "Tutorial1": "Hi! Welcome to Touchy Tickets. To start the game, simply tap the ticket booth to sell a . Start by racking up 50!", "Tutorial2": "Great! Now, you can buy your first attraction. Access the menu on the right by swiping and purchase a carousel.", diff --git a/TouchyTickets/Content/Localization/NumberFormat.de.json5 b/TouchyTickets/Content/Localization/NumberFormat.de.json5 new file mode 100644 index 0000000..b7286aa --- /dev/null +++ b/TouchyTickets/Content/Localization/NumberFormat.de.json5 @@ -0,0 +1,14 @@ +[ + "0", // Hundert + "0,.##t", // Tausend + "0,,.##M", // Millionen + "0,,,.##Mr", // Milliarden + "0,,,,.##B", // Billionen + "0,,,,,.##Br", // Billiarden + "0,,,,,,.##T", // Trillionen + "0,,,,,,,.##Tr", // Trilliarden + "0,,,,,,,,.##Q", // Quadrillionen + "0,,,,,,,,,.##Qr", // Quadrilliarden + "0,,,,,,,,,,.##Qi", // Quintillionen + "0,,,,,,,,,,,.##Qir", // Quintilliarden +] \ No newline at end of file diff --git a/TouchyTickets/Content/Localization/NumberFormat.json5 b/TouchyTickets/Content/Localization/NumberFormat.json5 new file mode 100644 index 0000000..91041da --- /dev/null +++ b/TouchyTickets/Content/Localization/NumberFormat.json5 @@ -0,0 +1,14 @@ +[ + "0", // hundreds + "0,.##K", // thousands + "0,,.##M", // millions + "0,,,.##B", // billions + "0,,,,.##T", // trillions + "0,,,,,.##Q", // quadrillions + "0,,,,,,.##Qi", // quintillions + "0,,,,,,,.##S", // sextillions + "0,,,,,,,,.##Sp", // septillions + "0,,,,,,,,,.##O", // octillions + "0,,,,,,,,,,.##N", // nonillions + "0,,,,,,,,,,,.##D", // decillions +] \ No newline at end of file diff --git a/TouchyTickets/Localization.cs b/TouchyTickets/Localization.cs index 620a874..9b17eaa 100644 --- a/TouchyTickets/Localization.cs +++ b/TouchyTickets/Localization.cs @@ -10,6 +10,7 @@ using Newtonsoft.Json; namespace TouchyTickets { public static class Localization { + public static readonly List NumberFormat = LoadLocalized>("NumberFormat", "json5"); private static readonly Dictionary Strings = LoadLocalized>("Localization"); private static readonly List News = LoadLocalized>("News"); private static readonly Random Random = new Random(); @@ -22,10 +23,10 @@ namespace TouchyTickets { return News[Random.Next(News.Count)]; } - private static T LoadLocalized(string name) { + private static T LoadLocalized(string name, string extension = "json") { var location = GameImpl.Instance.Content.RootDirectory + "/Localization/" + name; var culture = CultureInfo.CurrentCulture.TwoLetterISOLanguageName; - foreach (var path in new[] {$"{location}.{culture}.json", $"{location}.json"}) { + foreach (var path in new[] {$"{location}.{culture}.{extension}", $"{location}.{extension}"}) { try { using (var reader = new JsonTextReader(new StreamReader(TitleContainer.OpenStream(path)))) return SaveHandler.Serializer.Deserialize(reader); diff --git a/TouchyTickets/Ui.cs b/TouchyTickets/Ui.cs index 4b22c8b..4e164c2 100644 --- a/TouchyTickets/Ui.cs +++ b/TouchyTickets/Ui.cs @@ -460,7 +460,7 @@ namespace TouchyTickets { }; var center = splash.AddChild(new Group(Anchor.Center, new Vector2(0.5F, 0.5F), false) {DrawAlpha = 0}); center.AddChild(new Image(Anchor.AutoCenter, new Vector2(1, -1), Texture[4, 0])); - center.AddChild(new Paragraph(Anchor.AutoCenter, 10000, "A game by Ellpeck", true)); + center.AddChild(new Paragraph(Anchor.AutoCenter, 10000, Localization.Get("AGameByEllpeck"), true)); GameImpl.Instance.UiSystem.Add("Splash", splash).Priority = 100000; while (center.DrawAlpha < 1) { center.DrawAlpha += 0.015F; @@ -584,7 +584,8 @@ namespace TouchyTickets { }); var right = button.AddChild(new Group(Anchor.TopRight, new Vector2(0.8F, 1)) {CanBeMoused = false}); right.AddChild(new Paragraph(Anchor.TopLeft, 1, Localization.Get(upgrade.Name), true)); - right.AddChild(new Paragraph(Anchor.TopRight, 1, p => upgrade.Price + "", true)); + if (!reachedActive) + right.AddChild(new Paragraph(Anchor.TopRight, 1, p => upgrade.Price + "", true)); right.AddChild(new Paragraph(Anchor.AutoLeft, 1, Localization.Get(upgrade.Name + "Description"), true) {TextScale = 0.08F}); } } @@ -600,21 +601,12 @@ namespace TouchyTickets { } private static string PrettyPrintNumber(BigInteger number) { - if (number < 1000) - return number.ToString(); - // thousands - if (number < 1000000) - return number.ToString("0,.##K"); - // millions - if (number < 1000000000) - return number.ToString("0,,.##M"); - // billions - if (number < 1000000000000) - return number.ToString("0,,,.##B"); - // trillions - if (number < 1000000000000000) - return number.ToString("0,,,,.##T"); - return number.ToString("0,,,,,.##Q"); + for (var i = 0; i < Localization.NumberFormat.Count; i++) { + if (number < BigInteger.Pow(1000, i + 1)) + return number.ToString(Localization.NumberFormat[i]); + } + // if the number is too large, just return the highest possible + return number.ToString(Localization.NumberFormat.Last()); } }