diff --git a/TouchyTickets/Content/Localization/Localization.json b/TouchyTickets/Content/Localization/Localization.json index 3677be1..b34ce54 100644 --- a/TouchyTickets/Content/Localization/Localization.json +++ b/TouchyTickets/Content/Localization/Localization.json @@ -9,6 +9,8 @@ "Okay": "Okay", "RequiresTickets": "{0} for 1. Maximum {1}.", "AppliedUpgrades": "Active Upgrades", + "Options": "Options", + "RainingTicketLimit": "Max Raining Tickets", "----- 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/GameImpl.cs b/TouchyTickets/GameImpl.cs index dc0f377..6ad99b8 100644 --- a/TouchyTickets/GameImpl.cs +++ b/TouchyTickets/GameImpl.cs @@ -31,7 +31,8 @@ namespace TouchyTickets { protected override void LoadContent() { base.LoadContent(); - + Options.Load(); + // start the load sequence Ui.SetupUiSystem(this.UiSystem); CoroutineHandler.Start(Ui.DisplaySplash(this.LoadGame)); diff --git a/TouchyTickets/Options.cs b/TouchyTickets/Options.cs new file mode 100644 index 0000000..0222b1b --- /dev/null +++ b/TouchyTickets/Options.cs @@ -0,0 +1,35 @@ +using System.IO; +using System.Runtime.Serialization; +using Newtonsoft.Json; + +namespace TouchyTickets { + [DataContract] + public class Options { + + public static Options Instance { get; private set; } + + [DataMember] + public int RainingTicketLimit = 300; + + public static void Save() { + var file = GetOptionsFile(true); + using (var stream = new JsonTextWriter(file.CreateText())) + SaveHandler.Serializer.Serialize(stream, Instance); + } + + public static void Load() { + var file = GetOptionsFile(false); + if (file.Exists) { + using (var stream = new JsonTextReader(file.OpenText())) + Instance = SaveHandler.Serializer.Deserialize(stream); + } else { + Instance = new Options(); + } + } + + private static FileInfo GetOptionsFile(bool create) { + return new FileInfo(Path.Combine(SaveHandler.GetGameDirectory(create).FullName, "Options")); + } + + } +} \ No newline at end of file diff --git a/TouchyTickets/TouchyTickets.csproj b/TouchyTickets/TouchyTickets.csproj index faa1d0b..403a6b2 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 a948649..84e1deb 100644 --- a/TouchyTickets/Ui.cs +++ b/TouchyTickets/Ui.cs @@ -41,7 +41,7 @@ namespace TouchyTickets { if (rainingTickets[i].Update()) rainingTickets.RemoveAt(i); } - while (rainingTickets.Count < Math.Min(GameImpl.Instance.Map.TicketsPerSecond / 20, 300)) + while (rainingTickets.Count < Math.Min(GameImpl.Instance.Map.TicketsPerSecond / 30, Options.Instance.RainingTicketLimit)) rainingTickets.Add(new RainingTicket()); }, OnDrawn = (e, time, batch, alpha) => { @@ -318,12 +318,33 @@ namespace TouchyTickets { PopulateUpgradeList(upgradeList); this.uiSystem.Add("Upgrade", upgradeUi); - this.swipeRelations = new Element[] {upgradeUi, main, buyUi, modifierUi}; + // options ui + var optionsUi = new Group(Anchor.TopLeft, Vector2.One, false) { + IsHidden = true, + OnDrawn = (e, time, batch, alpha) => batch.Draw(batch.GetBlankTexture(), e.DisplayArea, ColorExtensions.FromHex(0xff86bccf) * alpha) + }; + optionsUi.AddChild(new Paragraph(Anchor.AutoCenter, 1, Localization.Get("Options"), true) {TextScale = 0.2F}); + var optionList = optionsUi.AddChild(new Panel(Anchor.AutoLeft, new Vector2(1), Vector2.Zero, false, true, new Point(10, 30), false) { + ChildPadding = new Padding(5, 15, 5, 5), + PreventParentSpill = true + }); + optionList.AddChild(new Paragraph(Anchor.AutoLeft, 1, p => Localization.Get("RainingTicketLimit") + ": " + Options.Instance.RainingTicketLimit)); + optionList.AddChild(new Slider(Anchor.AutoLeft, new Vector2(1, 20), 10, 500) { + PositionOffset = new Vector2(0, 1), + CurrentValue = Options.Instance.RainingTicketLimit, + OnValueChanged = (s, v) => { + Options.Instance.RainingTicketLimit = (int) v; + Options.Save(); + } + }); + this.uiSystem.Add("Options", optionsUi); + + this.swipeRelations = new Element[] {optionsUi, upgradeUi, main, buyUi, modifierUi}; } public void Update(GameTime time) { // swiping between tabs - if (!this.currentUi.IsHidden && this.uiSystem.Controls.HandleTouch) { + if (!this.currentUi.IsHidden && this.uiSystem.Controls.HandleTouch && !this.currentUi.GetChildren(c => c.Horizontal && c.IsBeingScrolled, true).Any()) { if (MlemGame.Input.GetGesture(GestureType.HorizontalDrag, out var gesture)) { this.swipeProgress -= gesture.Delta.X / this.currentUi.DisplayArea.Width; } else if (!this.finishingSwipe && this.swipeProgress != 0 && !MlemGame.Input.TouchState.Any()) {