Save settings
This commit is contained in:
parent
ccec3490d9
commit
9b48653122
|
@ -0,0 +1,17 @@
|
|||
using System.Globalization;
|
||||
|
||||
namespace Lemonade
|
||||
{
|
||||
public static class DollarConv
|
||||
{
|
||||
public static string ToDollar(this int cents)
|
||||
{
|
||||
string tmp = $"${(cents / 100f).ToString(CultureInfo.InvariantCulture)}";
|
||||
if (tmp.Length > 1 && tmp[1] == '-')
|
||||
tmp = "-$" + tmp.Substring(2);
|
||||
if (tmp.Contains('.') && tmp.Split('.')[1].Length < 2)
|
||||
tmp += '0';
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using System.Drawing;
|
||||
using CC_Functions.Commandline;
|
||||
using CC_Functions.Commandline.TUI;
|
||||
using static System.Environment;
|
||||
|
||||
namespace Lemonade
|
||||
{
|
||||
|
@ -32,22 +33,22 @@ namespace Lemonade
|
|||
lab.Content = "Lightning struck your table while you were setting it up. Nothing was sold";
|
||||
else
|
||||
lab.Content = $"The weather was {weather}. Nothing out of the ordinary happened";
|
||||
lab.Content += Environment.NewLine + players.ToStringTable(
|
||||
lab.Content += NewLine + NewLine + players.ToStringTable(
|
||||
new[]
|
||||
{
|
||||
"Player", "Glasses made", "Earnings per glass", "Glasses sold", "Signs made",
|
||||
"Income", "Expenses",
|
||||
"Profit", "Budget"
|
||||
"Player", "Glasses made", "Earnings per glass",
|
||||
"Glasses sold", "Signs made", "Income",
|
||||
"Expenses", "Profit", "Budget"
|
||||
},
|
||||
s => s.Number,
|
||||
s => s.Glasses,
|
||||
s => s.GlassPrice,
|
||||
s => s.GlassPrice.ToDollar(),
|
||||
s => s.Sales,
|
||||
s => s.Signs,
|
||||
s => s.Earnings,
|
||||
s => s.Expenses,
|
||||
s => s.Earnings - s.Expenses,
|
||||
s => s.Budget);
|
||||
s => s.Earnings.ToDollar(),
|
||||
s => s.Expenses.ToDollar(),
|
||||
s => (s.Earnings - s.Expenses).ToDollar(),
|
||||
s => s.Budget.ToDollar());
|
||||
lab.Render();
|
||||
ActualSize = new Size(lab.Size.Width, lab.Size.Height);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Xml.Linq;
|
||||
using CC_Functions.Commandline.TUI;
|
||||
|
||||
namespace Lemonade
|
||||
|
@ -12,7 +16,10 @@ namespace Lemonade
|
|||
Configure();
|
||||
}
|
||||
|
||||
public bool Color { get; private set; } = true;
|
||||
private static string Settingsfile =
|
||||
Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Settings.xml");
|
||||
|
||||
public bool Color { get; private set; }
|
||||
public int PlayerCount { get; private set; }
|
||||
public float DifficultyFactor { get; private set; }
|
||||
|
||||
|
@ -64,6 +71,15 @@ namespace Lemonade
|
|||
okButton.Click += (screen, args) => visible = false;
|
||||
settingsScreen.Close += (screen, args) => visible = false;
|
||||
|
||||
if (!File.Exists(Settingsfile)) GenDef();
|
||||
try {
|
||||
XElement conf = XElement.Parse(File.ReadAllText(Settingsfile));
|
||||
playerSlider.Value = int.Parse(conf.Element("Players").Value);
|
||||
difficulty.Value = int.Parse(conf.Element("Difficulty").Value);
|
||||
colorBox.Checked = bool.Parse(conf.Element("Color").Value);
|
||||
settingsScreen.Color = colorBox.Checked;
|
||||
} catch { Debug.Fail("Failed to load settings"); }
|
||||
|
||||
settingsScreen.Render();
|
||||
while (visible)
|
||||
{
|
||||
|
@ -73,6 +89,21 @@ namespace Lemonade
|
|||
PlayerCount = playerSlider.Value;
|
||||
DifficultyFactor = difficulty.Value / 10f;
|
||||
Color = colorBox.Checked;
|
||||
try
|
||||
{
|
||||
Gen(PlayerCount, difficulty.Value, Color);
|
||||
}
|
||||
catch {Debug.Fail("Failed to save settings");}
|
||||
}
|
||||
|
||||
private static XElement GenDef() => Gen(2, 5, true);
|
||||
|
||||
private static XElement Gen(int players, int difficulty, bool color)
|
||||
{
|
||||
XElement tmp = new XElement("Settings", new XElement("Players", players), new XElement("Difficulty", difficulty),
|
||||
new XElement("Color", color));
|
||||
tmp.Save(Settingsfile);
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -63,10 +63,10 @@ namespace Lemonade
|
|||
|
||||
Button okButton = new Button("OK");
|
||||
okButton.Point = new Point(ContentPanel.Size.Width / 2 - okButton.Size.Width / 2, 16);
|
||||
okButton.Click += (sender, e) => Ok?.Invoke(_glasses.Value, 10, 0);
|
||||
okButton.Click += (sender, e) => Ok?.Invoke(_glasses.Value, _price.Value, _signs.Value);
|
||||
ContentPanel.Controls.Add(okButton);
|
||||
|
||||
Close += (screen, args) => Ok?.Invoke(_glasses.Value, 10, 0);
|
||||
Close += (screen, args) => Ok?.Invoke(_glasses.Value, _price.Value, _signs.Value);
|
||||
}
|
||||
|
||||
public event OkDelegate Ok;
|
||||
|
@ -101,7 +101,7 @@ namespace Lemonade
|
|||
_glasses.MaxValue = (int) Math.Floor(leftover / (double) _lemonadeCost) + _glasses.Value;
|
||||
_price.MaxValue = 200;
|
||||
_signs.MaxValue = (int) Math.Floor(leftover / (double) _signCost) + _signs.Value;
|
||||
_infoLabelBottom.Content = $"Leftover: ${leftover / 100f}/${_player.Budget / 100f}";
|
||||
_infoLabelBottom.Content = $"Leftover: {leftover.ToDollar()}/{_player.Budget.ToDollar()}";
|
||||
_infoLabelBottom.Point = new Point(ContentPanel.Size.Width / 2 - _infoLabelBottom.Content.Length / 2, 14);
|
||||
}
|
||||
|
||||
|
|
Reference in New Issue