Skip to content
Snippets Groups Projects
Commit a6a508e2 authored by bionic85's avatar bionic85
Browse files

started working on file settings stuff

parent 6c7a6a4a
No related branches found
No related tags found
No related merge requests found
......@@ -8,18 +8,81 @@ using System.Windows.Forms;
namespace PuzzlePlayer_Namespace
{
// struct for saving settings
internal struct Settings(Theme t, string fName, int fSize)
{
public Theme theme = t;
public string fontName = fName;
public int fontSize = fSize;
public override string ToString()
{
return $"SETTINGS|{fontName}|{fontSize}|{theme.ToString()}";
}
public static Settings FromString(string s)
{
string[] split = s.Split('|');
if (split[0] != "SETTINGS")
throw new Exception("Invallid input string in FromString methode from Settings struct");
string themeString = "";
for (int i = 3; i < split.Length; i++) // add everything after the fontsize to the themestring
{
themeString += split[i];
}
return new Settings(Theme.FromString(themeString), split[1], int.Parse(split[2]));
}
}
// struct for saving themes
internal struct Theme(string s, Color col1, Color col2, Color col3)
{
public string name = s;
public Color primaryColor = col1;
public Color secondaryColor = col2;
public Color tertiaryColor = col3;
public override string ToString()
{
return $"THEME|{name}|{primaryColor.ToArgb()}|{secondaryColor.ToArgb()}|{tertiaryColor.ToArgb()}|";
}
public static Theme FromString(string s)
{
string[] split = s.Split('|');
if (split[0] != "THEME")
throw new Exception("Invallid input string in FromString methode from Theme struct");
Color c1 = Color.FromArgb(int.Parse(split[2]));
Color c2 = Color.FromArgb(int.Parse(split[3]));
Color c3 = Color.FromArgb(int.Parse(split[4]));
return new Theme(split[1],c1,c2,c3);
}
}
internal class SettingForm : Form
{
// Public variables for all settings
// Currently they are set to their default values
public static Color primaryColor = Color.FromArgb(66, 69, 73);
public static Color secondaryColor = Color.FromArgb(54, 57, 62);
public static Color tertiaryColor = Color.FromArgb(0, 0, 0);
public static int fontSize = 16;
public static Font mainFont = new Font("Gotham", fontSize);
public static string mainFontName = "Gotham";
public static Font mainFont = new Font(mainFontName, fontSize);
public static FlowLayoutPanel settingsPanel;
// For storing user settings
private Settings settings;
private static string filePath = "Settings.txt";
public SettingForm()
{
settings = GetUserSettings();
SetUpUi();
this.BackColor = primaryColor;
......@@ -31,6 +94,36 @@ namespace PuzzlePlayer_Namespace
Invalidate();
}
private Settings GetUserSettings()
{
StreamReader reader = new StreamReader(System.IO.File.OpenRead(filePath));
Settings? newSettings = null;
string s = "";
while ((s = reader.ReadLine()) != null)
{
if(s.StartsWith("SETTINGS"))
{
newSettings = Settings.FromString(s);
break;
}
}
reader.Dispose();
if (newSettings != null)
return (Settings)newSettings;
else
MakeNewSettingsFile(); // if the settings could not be read then a new file must be made
return GetUserSettings(); // after the new file is made it is save to call getUserSettings again
}
private void MakeNewSettingsFile()
{
FileStream fs = File.Create(filePath);
StreamReader reader = new StreamReader(fs);
throw new NotImplementedException();
}
private void SetUpUi()
{
this.ClientSize = new Size(1115, 755);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment