From 50768791da38d004f06028e633b570e86190b7e1 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 4 Jun 2020 21:43:11 +0200 Subject: [PATCH] added news ticker --- TouchyTickets/Content/Content.mgcb | 3 ++ .../Content/Localization/Localization.json | 2 +- TouchyTickets/Content/Localization/News.json | 23 +++++++++++ TouchyTickets/Localization.cs | 41 ++++++++++--------- TouchyTickets/TouchyTickets.csproj | 2 +- TouchyTickets/Ui.cs | 13 +++++- 6 files changed, 62 insertions(+), 22 deletions(-) create mode 100644 TouchyTickets/Content/Localization/News.json diff --git a/TouchyTickets/Content/Content.mgcb b/TouchyTickets/Content/Content.mgcb index a96a753..e7077e8 100644 --- a/TouchyTickets/Content/Content.mgcb +++ b/TouchyTickets/Content/Content.mgcb @@ -43,3 +43,6 @@ #begin Localization/Localization.json /copy:Localization/Localization.json +#begin Localization/News.json +/copy:Localization/News.json + diff --git a/TouchyTickets/Content/Localization/Localization.json b/TouchyTickets/Content/Localization/Localization.json index 34d2646..8a921a9 100644 --- a/TouchyTickets/Content/Localization/Localization.json +++ b/TouchyTickets/Content/Localization/Localization.json @@ -44,5 +44,5 @@ "ManualRideModifier": "Push and Shove", "ManualRideModifierDescription": "Increases the amount of people allowed on manual (walking-based) rides, tripling their ticket sales.", "SpiralSlideModifier": "Sightseeing", - "SpiralSlideModifierDescription": "Spiral slide visitors are given binoculars to look at adjacent rides, doubling their ticket sales." + "SpiralSlideModifierDescription": "New binoculars allow spiral slide visitors to check out adjacent rides whose ticket sales are doubled as a result." } \ No newline at end of file diff --git a/TouchyTickets/Content/Localization/News.json b/TouchyTickets/Content/Localization/News.json new file mode 100644 index 0000000..f5f4944 --- /dev/null +++ b/TouchyTickets/Content/Localization/News.json @@ -0,0 +1,23 @@ +[ + "Carousel 7 broke down, but there is no mechanic available", + "Popular park now features \"buy seventeen, get one free\" ticket sale", + "Speed of ferris wheel set too high, causing whiplash", + "New park constructs never-before-seen \"log flume\" ride", + "Visitors allegedly getting lost in park due to too many paths that lead nowhere", + "Performance artist locks themselves in ferris wheel pod for eight weeks", + "Newspaper declares log flume high risk ride due to \"too many splinters\"", + "Newspaper declares log flume high risk ride due to them being \"too wet\"", + "Children excited by food stalls, saying \"soda soda soda soda soda\"", + "Ride ran in reverse accidentally, making passengers younger", + "Cotton candy reported missing after log flume ride", + "Umbrellas sold at half price due to passengers throwing up onto parkgoers", + "75% of population's colds caused by log flumes, scientists say", + "Height limit lifted for wooden coaster, making children happy", + "Pants in high demand at gift shop, allegedly due to house of horrors", + "Violinist linked to coaster crash blossoms", + "Log flume photos terrible due to water on lens", + "Park visitor out of money, starts selling souvenirs to continue riding", + "Uncomortable benches at food court causing visitors to eat lunch in bumper cars", + "Carousel \"too scary\" according to four year old child", + "Tall person mistaken for park performer on stilts" +] \ No newline at end of file diff --git a/TouchyTickets/Localization.cs b/TouchyTickets/Localization.cs index 60f80e1..620a874 100644 --- a/TouchyTickets/Localization.cs +++ b/TouchyTickets/Localization.cs @@ -3,35 +3,38 @@ using System.Collections.Generic; using System.Globalization; using System.IO; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; using MLEM.Startup; using Newtonsoft.Json; namespace TouchyTickets { public static class Localization { - private static readonly Dictionary Strings; - - static Localization() { - var location = GameImpl.Instance.Content.RootDirectory + "/Localization/Localization"; - var culture = CultureInfo.CurrentCulture.TwoLetterISOLanguageName; - foreach (var path in new[] {$"{location}.{culture}.json", $"{location}.json"}) { - try { - using (var reader = new JsonTextReader(new StreamReader(TitleContainer.OpenStream(path)))) { - var ret = SaveHandler.Serializer.Deserialize>(reader); - if (ret == null) - continue; - Strings = ret; - break; - } - } catch (Exception) { - // move on to the next path - } - } - } + private static readonly Dictionary Strings = LoadLocalized>("Localization"); + private static readonly List News = LoadLocalized>("News"); + private static readonly Random Random = new Random(); public static string Get(string key) { return Strings.TryGetValue(key, out var ret) ? ret : $"?{key}?"; } + public static string GetRandomNews() { + return News[Random.Next(News.Count)]; + } + + private static T LoadLocalized(string name) { + var location = GameImpl.Instance.Content.RootDirectory + "/Localization/" + name; + var culture = CultureInfo.CurrentCulture.TwoLetterISOLanguageName; + foreach (var path in new[] {$"{location}.{culture}.json", $"{location}.json"}) { + try { + using (var reader = new JsonTextReader(new StreamReader(TitleContainer.OpenStream(path)))) + return SaveHandler.Serializer.Deserialize(reader); + } catch (Exception) { + // move on to the next path + } + } + throw new ContentLoadException(); + } + } } \ No newline at end of file diff --git a/TouchyTickets/TouchyTickets.csproj b/TouchyTickets/TouchyTickets.csproj index d291856..3eb455f 100644 --- a/TouchyTickets/TouchyTickets.csproj +++ b/TouchyTickets/TouchyTickets.csproj @@ -6,7 +6,7 @@ - + all diff --git a/TouchyTickets/Ui.cs b/TouchyTickets/Ui.cs index 0d2bcc3..74394d2 100644 --- a/TouchyTickets/Ui.cs +++ b/TouchyTickets/Ui.cs @@ -57,6 +57,17 @@ namespace TouchyTickets { ticket.Draw(batch, e.DisplayArea.Size, e.Scale, Color.White * alpha); } }; + var currentNews = Localization.GetRandomNews(); + var newsTicker = main.AddChild(new Panel(Anchor.AutoCenter, new Vector2(1, 0.05F), Vector2.Zero)); + newsTicker.AddChild(new Paragraph(Anchor.CenterLeft, float.MaxValue, p => currentNews, true) { + OnUpdated = (e, time) => { + e.PositionOffset -= new Vector2(1, 0); + if (e.PositionOffset.X <= -e.DisplayArea.Width / e.Scale - 20) { + e.PositionOffset = new Vector2(e.Parent.DisplayArea.Width / e.Scale + 20, 0); + currentNews = Localization.GetRandomNews(); + } + } + }); var ticketGroup = main.AddChild(new Group(Anchor.AutoCenter, new Vector2(1, 0.15F), false)); ticketGroup.AddChild(new Paragraph(Anchor.AutoCenter, 10000, p => PrettyPrintNumber(GameImpl.Instance.Tickets) + "", true) { TextScale = 0.3F @@ -66,7 +77,7 @@ namespace TouchyTickets { }); BigInteger lastTickets = 0; ActiveCoroutine storeWobble = null; - var storeGroup = main.AddChild(new CustomDrawGroup(Anchor.AutoCenter, new Vector2(1, 0.5F), null, null, false) { + var storeGroup = main.AddChild(new CustomDrawGroup(Anchor.AutoCenter, new Vector2(1, 0.45F), null, null, false) { OnUpdated = (e, time) => { if (lastTickets != GameImpl.Instance.Tickets) { lastTickets = GameImpl.Instance.Tickets;