2015-06-02 17:52:22 -06:00
|
|
|
|
using System;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
2015-06-16 21:32:07 -04:00
|
|
|
|
namespace TrueCraft.Core
|
2015-06-02 17:52:22 -06:00
|
|
|
|
{
|
|
|
|
|
public class UserSettings
|
|
|
|
|
{
|
|
|
|
|
public static UserSettings Local { get; set; }
|
|
|
|
|
|
2015-06-02 18:40:53 -06:00
|
|
|
|
public static string SettingsPath
|
2015-06-02 17:52:22 -06:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2015-06-02 18:40:53 -06:00
|
|
|
|
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
|
|
|
|
|
".truecraft", "settings.json");
|
2015-06-02 17:52:22 -06:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool AutoLogin { get; set; }
|
|
|
|
|
public string Username { get; set; }
|
|
|
|
|
public string Password { get; set; }
|
2015-06-02 18:40:53 -06:00
|
|
|
|
public string LastIP { get; set; }
|
2015-06-16 21:32:07 -04:00
|
|
|
|
public string SelectedTexturePack { get; set; }
|
2015-06-02 18:40:53 -06:00
|
|
|
|
public FavoriteServer[] FavoriteServers { get; set; }
|
2015-06-17 15:03:06 -04:00
|
|
|
|
public bool IsFullscreen { get; set; }
|
2015-06-17 14:23:46 -04:00
|
|
|
|
public WindowResolution WindowResolution { get; set; }
|
2015-06-02 17:52:22 -06:00
|
|
|
|
|
|
|
|
|
public UserSettings()
|
|
|
|
|
{
|
|
|
|
|
AutoLogin = false;
|
|
|
|
|
Username = "";
|
|
|
|
|
Password = "";
|
2015-06-02 18:40:53 -06:00
|
|
|
|
LastIP = "";
|
2015-06-17 09:10:42 -04:00
|
|
|
|
SelectedTexturePack = TexturePack.Default.Name;
|
2015-06-02 20:31:43 -06:00
|
|
|
|
FavoriteServers = new FavoriteServer[0];
|
2015-06-17 15:03:06 -04:00
|
|
|
|
IsFullscreen = false;
|
2015-06-17 14:23:46 -04:00
|
|
|
|
WindowResolution = new WindowResolution()
|
|
|
|
|
{
|
|
|
|
|
Width = 1280,
|
|
|
|
|
Height = 720
|
|
|
|
|
};
|
2015-06-02 17:52:22 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Load()
|
|
|
|
|
{
|
|
|
|
|
if (File.Exists(SettingsPath))
|
|
|
|
|
JsonConvert.PopulateObject(File.ReadAllText(SettingsPath), this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Save()
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(Path.GetDirectoryName(SettingsPath));
|
2015-06-02 18:40:53 -06:00
|
|
|
|
File.WriteAllText(SettingsPath, JsonConvert.SerializeObject(this, Formatting.Indented));
|
2015-06-02 17:52:22 -06:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-06-02 18:40:53 -06:00
|
|
|
|
|
|
|
|
|
public class FavoriteServer
|
|
|
|
|
{
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
public string Address { get; set; }
|
|
|
|
|
}
|
2015-06-17 10:02:06 -04:00
|
|
|
|
|
2015-06-17 14:23:46 -04:00
|
|
|
|
public class WindowResolution
|
2015-06-17 10:02:06 -04:00
|
|
|
|
{
|
2015-06-17 14:23:46 -04:00
|
|
|
|
public static readonly WindowResolution[] Defaults =
|
|
|
|
|
new WindowResolution[]
|
|
|
|
|
{
|
2015-06-17 15:03:06 -04:00
|
|
|
|
// (from Wikipedia/other)
|
2015-06-17 14:23:46 -04:00
|
|
|
|
WindowResolution.FromString("800 x 600"), // SVGA
|
|
|
|
|
WindowResolution.FromString("960 x 640"), // DVGA
|
|
|
|
|
WindowResolution.FromString("1024 x 600"), // WSVGA
|
|
|
|
|
WindowResolution.FromString("1024 x 768"), // XGA
|
|
|
|
|
WindowResolution.FromString("1280 x 1024"), // SXGA
|
|
|
|
|
WindowResolution.FromString("1600 x 1200"), // UXGA
|
2015-06-17 15:03:06 -04:00
|
|
|
|
WindowResolution.FromString("1920 x 1080"), // big
|
|
|
|
|
WindowResolution.FromString("1920 x 1200"), // really big
|
|
|
|
|
WindowResolution.FromString("4096 x 2160"), // huge
|
2015-06-17 14:23:46 -04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public static WindowResolution FromString(string str)
|
|
|
|
|
{
|
|
|
|
|
var tmp = str.Split('x');
|
|
|
|
|
return new WindowResolution()
|
|
|
|
|
{
|
|
|
|
|
Width = int.Parse(tmp[0].Trim()),
|
|
|
|
|
Height = int.Parse(tmp[1].Trim())
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-17 10:02:06 -04:00
|
|
|
|
public int Width { get; set; }
|
|
|
|
|
public int Height { get; set; }
|
2015-06-17 14:23:46 -04:00
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return string.Format("{0} x {1}", Width, Height);
|
|
|
|
|
}
|
2015-06-17 10:02:06 -04:00
|
|
|
|
}
|
2015-06-02 17:52:22 -06:00
|
|
|
|
}
|