added options

This commit is contained in:
Ellpeck 2020-06-16 23:17:18 +02:00
parent 87006f0b1c
commit d394f5d761
5 changed files with 64 additions and 5 deletions

View file

@ -9,6 +9,8 @@
"Okay": "Okay",
"RequiresTickets": "{0}<i ticket> for 1<i star>. 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 <i ticket>. Start by racking up 50<i ticket>!",
"Tutorial2": "Great! Now, you can buy your first attraction. Access the menu on the right by swiping and purchase a carousel.",

View file

@ -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));

35
TouchyTickets/Options.cs Normal file
View file

@ -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<Options>(stream);
} else {
Instance = new Options();
}
}
private static FileInfo GetOptionsFile(bool create) {
return new FileInfo(Path.Combine(SaveHandler.GetGameDirectory(create).FullName, "Options"));
}
}
}

View file

@ -6,7 +6,7 @@
<ItemGroup>
<PackageReference Include="Coroutine" Version="2.0.0" />
<PackageReference Include="MLEM.Startup" Version="3.3.3-204" />
<PackageReference Include="MLEM.Startup" Version="4.0.0-214" />
<PackageReference Include="MonoGame.Framework.Portable" Version="3.7.1.189">
<PrivateAssets>all</PrivateAssets>
</PackageReference>

View file

@ -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<ScrollBar>(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()) {