diff --git a/PuzzlePlayer/App.config b/PuzzlePlayer/App.config index 8a5320fcdfcc94db92f70c5732d6da1dc95e7aa7..78b587e0706738df81be63599c2a42d4832dfdbc 100644 --- a/PuzzlePlayer/App.config +++ b/PuzzlePlayer/App.config @@ -13,9 +13,6 @@ <setting name="FontName" serializeAs="String"> <value>Gotham</value> </setting> - <setting name="FontSize" serializeAs="String"> - <value>16</value> - </setting> <setting name="Money" serializeAs="String"> <value>100</value> </setting> diff --git a/PuzzlePlayer/Properties/Settings.Designer.cs b/PuzzlePlayer/Properties/Settings.Designer.cs index b26524e43b077bd93d1ad8f057d94ea1cd624251..c36b6676858d0cdbb9576454b0a89ba88763991d 100644 --- a/PuzzlePlayer/Properties/Settings.Designer.cs +++ b/PuzzlePlayer/Properties/Settings.Designer.cs @@ -47,18 +47,6 @@ namespace PuzzlePlayer_Namespace.Properties { } } - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("16")] - public int FontSize { - get { - return ((int)(this["FontSize"])); - } - set { - this["FontSize"] = value; - } - } - [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("100")] diff --git a/PuzzlePlayer/Properties/Settings.settings b/PuzzlePlayer/Properties/Settings.settings index 62db88e96dd30039fae7321052d389872b46768a..5b860f4fdcb5afb4cc560d86eed93a9fe2bffb1c 100644 --- a/PuzzlePlayer/Properties/Settings.settings +++ b/PuzzlePlayer/Properties/Settings.settings @@ -8,9 +8,6 @@ <Setting Name="FontName" Type="System.String" Scope="User"> <Value Profile="(Default)">Gotham</Value> </Setting> - <Setting Name="FontSize" Type="System.Int32" Scope="User"> - <Value Profile="(Default)">16</Value> - </Setting> <Setting Name="Money" Type="System.Int32" Scope="User"> <Value Profile="(Default)">100</Value> </Setting> diff --git a/PuzzlePlayer/PuzzleForm.cs b/PuzzlePlayer/PuzzleForm.cs index 8a9957de2f6cd680112408ee79dcdef23be73be4..fa2cdb824d62569a14663c125531ecb5ace56925 100644 --- a/PuzzlePlayer/PuzzleForm.cs +++ b/PuzzlePlayer/PuzzleForm.cs @@ -12,8 +12,6 @@ namespace PuzzlePlayer_Namespace { internal class PuzzleForm : Form { - public UserDataManager UserDataManager; - private readonly Button solvebutton; private readonly Button hintbutton; private readonly Button generatebutton; @@ -39,13 +37,11 @@ namespace PuzzlePlayer_Namespace public PuzzleForm(Board b, Size s = default) //takes Board and Size parameter and sets up the PuzzleForm window. { - UserDataManager = new UserDataManager(); - puzzleType = b.GetType().Name; if (s == default) s = new Size(700, 420); this.Size = this.MinimumSize = s; this.WindowState = FormWindowState.Maximized; - this.BackColor = SettingForm.primaryColor; + this.BackColor = UserDataManager.Theme.primaryColor; this.Text = "PuzzlePlayer"; bufferedGraphics = BufferedGraphicsManager.Current.Allocate(this.CreateGraphics(), this.DisplayRectangle); bufferedGraphics.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; @@ -86,12 +82,12 @@ namespace PuzzlePlayer_Namespace { MenuStrip menuStrip = new MenuStrip { - BackColor = SettingForm.secondaryColor, - ForeColor = SettingForm.secondaryColor, + BackColor = UserDataManager.Theme.secondaryColor, + ForeColor = UserDataManager.Theme.secondaryColor, Name = "Main menu", Text = "Main Menu", Dock = DockStyle.Top, - Font = SettingForm.mainFont, + Font = UserDataManager.MainFont, }; ToolStripMenuItem menuSettings = new ToolStripMenuItem { @@ -99,7 +95,7 @@ namespace PuzzlePlayer_Namespace ForeColor = Color.Black, Text = "Settings", TextAlign = ContentAlignment.BottomRight, - Font = SettingForm.mainFont, + Font = UserDataManager.MainFont, }; menuStrip.Items.Add(menuSettings); this.Controls.Add(menuStrip); @@ -111,8 +107,8 @@ namespace PuzzlePlayer_Namespace settingForm.FormClosed += (object s, FormClosedEventArgs args) => { - this.BackColor = SettingForm.primaryColor; - this.ForeColor = SettingForm.tertiaryColor; + this.BackColor = UserDataManager.Theme.primaryColor; + this.ForeColor = UserDataManager.Theme.tertiaryColor; foreach (Control control in this.Controls) { @@ -191,8 +187,8 @@ namespace PuzzlePlayer_Namespace informationbox.Text = board.description; informationbox.Font = new Font("Verdana", 10); - this.BackColor = SettingForm.primaryColor; - this.ForeColor = SettingForm.tertiaryColor; + this.BackColor = UserDataManager.Theme.primaryColor; + this.ForeColor = UserDataManager.Theme.tertiaryColor; UpdateUI(); } diff --git a/PuzzlePlayer/PuzzlePlayer.cs b/PuzzlePlayer/PuzzlePlayer.cs index 3db438eb095ff58db1b49dcc9439d888bd1ecab4..7f0170712ef9982e8dec14201f44110ff4734adc 100644 --- a/PuzzlePlayer/PuzzlePlayer.cs +++ b/PuzzlePlayer/PuzzlePlayer.cs @@ -34,20 +34,18 @@ namespace PuzzlePlayer_Namespace private void SetUpUI() { - // -- List<RoundedButton> buttons = new List<RoundedButton>(); - this.ClientSize = new Size(1115, 755); - this.BackColor = SettingForm.primaryColor; + this.BackColor = UserDataManager.Theme.primaryColor; this.Text = "PuzzlePlayer"; MenuStrip menuStrip = new MenuStrip { - BackColor = SettingForm.secondaryColor, - ForeColor = SettingForm.secondaryColor, + BackColor = UserDataManager.Theme.secondaryColor, + ForeColor = UserDataManager.Theme.secondaryColor, Name = "Main menu", Text = "Main Menu", Dock = DockStyle.Top, - Font = SettingForm.mainFont, + Font = UserDataManager.MainFont, }; ToolStripMenuItem menuSettings = new ToolStripMenuItem @@ -56,7 +54,7 @@ namespace PuzzlePlayer_Namespace ForeColor = Color.Black, Text = "Settings", TextAlign = ContentAlignment.BottomRight, - Font = SettingForm.mainFont, + Font = UserDataManager.MainFont, }; menuSettings.Click += (object o, EventArgs e) => @@ -66,8 +64,8 @@ namespace PuzzlePlayer_Namespace settingForm.FormClosed += (object s, FormClosedEventArgs args) => { - this.BackColor = SettingForm.primaryColor; - this.ForeColor = SettingForm.tertiaryColor; + this.BackColor = UserDataManager.Theme.primaryColor; + this.ForeColor = UserDataManager.Theme.tertiaryColor; foreach (Control control in this.Controls) { @@ -98,7 +96,7 @@ namespace PuzzlePlayer_Namespace { string image = puzzleForms[i].puzzleType; - Image normalImage = SettingForm.GetEmbeddedImage(image + ".jpg"); // Image.FromFile(image + ".jpg"); + Image normalImage = SettingForm.GetEmbeddedImage(image + ".jpg"); Image grayImage = SettingForm.GetEmbeddedImage(image + "Gray.jpg"); // Set the name of the button @@ -110,7 +108,7 @@ namespace PuzzlePlayer_Namespace Width = 345, Image = normalImage, FlatStyle = FlatStyle.Flat, - Font = SettingForm.mainFont, + Font = new Font(UserDataManager.MainFont.Name, UserDataManager.MainFont.Size * 2), Name = i.ToString() }; @@ -132,8 +130,8 @@ namespace PuzzlePlayer_Namespace PuzzleForm puzzleForm = puzzleForms[int.Parse(rb.Name)]; puzzleForm.FormClosed += (object o, FormClosedEventArgs fcea) => { - this.BackColor = SettingForm.primaryColor; - this.ForeColor = SettingForm.tertiaryColor; + this.BackColor = UserDataManager.Theme.primaryColor; + this.ForeColor = UserDataManager.Theme.tertiaryColor; foreach (Control control in this.Controls) { @@ -174,14 +172,14 @@ namespace PuzzlePlayer_Namespace blackJackButton.Width = 345; blackJackButton.Image = SettingForm.GetEmbeddedImage("bj.jpg"); blackJackButton.FlatStyle = FlatStyle.Flat; - blackJackButton.Font = SettingForm.mainFont; + blackJackButton.Font = UserDataManager.MainFont; blackJackButton.Click += (object o, EventArgs e) => { this.Hide(); bj.FormClosed += (object o, FormClosedEventArgs fcea) => { - this.BackColor = SettingForm.primaryColor; - this.ForeColor = SettingForm.tertiaryColor; + this.BackColor = UserDataManager.Theme.primaryColor; + this.ForeColor = UserDataManager.Theme.tertiaryColor; foreach (Control control in this.Controls) { diff --git a/PuzzlePlayer/SettingForm.cs b/PuzzlePlayer/SettingForm.cs index 06f4075719ba1106a371836db0a974bdc0ae6ae1..40fcb081f62516170256e2479fb714cdf63067ac 100644 --- a/PuzzlePlayer/SettingForm.cs +++ b/PuzzlePlayer/SettingForm.cs @@ -13,39 +13,35 @@ namespace PuzzlePlayer_Namespace { // 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 string mainFontName = "Gotham"; - public static Font mainFont = new Font(mainFontName, fontSize); + //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 string mainFontName = "Gotham"; + //public static Font mainFont = new Font(mainFontName, fontSize); public static FlowLayoutPanel settingsPanel; - - // hardcoded default settings - public static UserData defaultSettings = new UserData("Dark", mainFontName, fontSize); - - // For storing user settings - private UserData settings; public SettingForm() { - // TODO OF ZOIETS HELP - SetUpUI(); + this.ClientSize = new Size(1115, 755); + this.BackColor = UserDataManager.Theme.primaryColor; + this.Text = "PuzzlePlayer"; - this.BackColor = primaryColor; + SetUpUI(); foreach (Control control in Controls) { - UpdateControl(control); + UpdateControl(control); //cheeky dw } Invalidate(); } private void SetUpUI() { - this.ClientSize = new Size(1115, 755); - this.BackColor = SettingForm.primaryColor; - this.Text = "PuzzlePlayer"; + Theme theme = UserDataManager.Theme; + Color primaryColor = theme.primaryColor; + Color secondaryColor = theme.secondaryColor; + Color tertiaryColor = theme.tertiaryColor; MenuStrip menuStrip = new MenuStrip { @@ -76,66 +72,20 @@ namespace PuzzlePlayer_Namespace Name = "Theme", Height = 25, Width = 250, - BackColor = SettingForm.secondaryColor, + BackColor = secondaryColor, ForeColor = Color.Black, Margin = new Padding(20) }; - themeSelector.Items.Add("Dark"); - themeSelector.Items.Add("Light"); - themeSelector.Items.Add("Pink"); - themeSelector.SelectedIndexChanged += (object o, EventArgs e) => + List<Theme> themeList = UserDataManager.GetThemes(); + foreach(Theme t in themeList) { - switch (themeSelector.Text) - { - case "Dark": - SettingForm.primaryColor = Color.FromArgb(66, 69, 73); - SettingForm.secondaryColor = Color.FromArgb(54, 57, 62); - SettingForm.tertiaryColor = Color.FromArgb(0, 0, 0); - break; - case "Light": - SettingForm.primaryColor = Color.FromArgb(228, 229, 241); - SettingForm.secondaryColor = Color.FromArgb(210, 211, 219); - SettingForm.tertiaryColor = Color.FromArgb(72, 75, 106); - break; - case "Pink": - SettingForm.primaryColor = Color.FromArgb(255, 209, 220); - SettingForm.secondaryColor = Color.FromArgb(252, 178, 197); - SettingForm.tertiaryColor = Color.FromArgb(251, 199, 255); - break; - } - }; - - ComboBox sizeSelector = new ComboBox - { - Text = "Size", - Name = "Size", - Height = 25, - Width = 250, - BackColor = SettingForm.secondaryColor, - ForeColor = Color.Black, - Margin = new Padding(20), - }; - sizeSelector.Items.Add("Small"); - sizeSelector.Items.Add("Medium"); - sizeSelector.Items.Add("Large"); + themeSelector.Items.Add(t.name); + } - sizeSelector.SelectedIndexChanged += (object o, EventArgs e) => + themeSelector.SelectedIndexChanged += (object o, EventArgs e) => { - switch (sizeSelector.Text) - { - case "Small": - fontSize = 8; - break; - case "Medium": - fontSize = 16; - break; - case "Large": - fontSize = 24; - break; - } - mainFont = new Font("Gotham", fontSize); - settingsPanel.PerformLayout(); + UserDataManager.SetCurrentTheme(themeSelector.Text); }; settingsPanel = new FlowLayoutPanel @@ -156,7 +106,7 @@ namespace PuzzlePlayer_Namespace Name = "Save", Height = 100, Width = 350, - BackColor = SettingForm.secondaryColor, + BackColor = secondaryColor, ForeColor = Color.Black, Location = new Point(10, ClientSize.Height - 110), Anchor = AnchorStyles.Left | AnchorStyles.Bottom, @@ -166,14 +116,14 @@ namespace PuzzlePlayer_Namespace saveButton.Click += (object o, EventArgs e) => { - this.BackColor = primaryColor; + this.BackColor = UserDataManager.Theme.primaryColor; foreach (Control control in Controls) { UpdateControl(control); } - settingsPanel.BackColor = primaryColor; + settingsPanel.BackColor = UserDataManager.Theme.primaryColor; Invalidate(); }; @@ -183,7 +133,6 @@ namespace PuzzlePlayer_Namespace this.Controls.Add(saveButton); settingsPanel.Controls.Add(themeSelector); - settingsPanel.Controls.Add(sizeSelector); menuStrip.Items.Add(menuBack); @@ -194,6 +143,11 @@ namespace PuzzlePlayer_Namespace public static void UpdateControl(Control control) { + Theme theme = UserDataManager.Theme; + Color primaryColor = theme.primaryColor; + Color secondaryColor = theme.secondaryColor; + Color tertiaryColor = theme.tertiaryColor; + if (control is not FlowLayoutPanel) { control.BackColor = secondaryColor; @@ -204,7 +158,7 @@ namespace PuzzlePlayer_Namespace control.BackColor = primaryColor; } - control.Font = mainFont; + control.Font = UserDataManager.MainFont; foreach (Control childControl in control.Controls) { @@ -222,9 +176,14 @@ namespace PuzzlePlayer_Namespace public static void UpdateToolStripSettings(ToolStripItem item) { + Theme theme = UserDataManager.Theme; + Color primaryColor = theme.primaryColor; + Color secondaryColor = theme.secondaryColor; + Color tertiaryColor = theme.tertiaryColor; + item.BackColor = secondaryColor; item.ForeColor = tertiaryColor; - item.Font = mainFont; + item.Font = UserDataManager.MainFont; if (item is ToolStripMenuItem menuItem) { diff --git a/PuzzlePlayer/UserDataManager.cs b/PuzzlePlayer/UserDataManager.cs index cefa35482a4f497c56b4d735851e0d91b231538d..e48d021196698cb9a79e8ee1098fe4fd8f722d34 100644 --- a/PuzzlePlayer/UserDataManager.cs +++ b/PuzzlePlayer/UserDataManager.cs @@ -48,23 +48,20 @@ namespace PuzzlePlayer_Namespace } // Class for managing and storing user data - internal class UserDataManager + static internal class UserDataManager { // properties for getting various settings - public int Money { get { return Settings.Default.Money; } set { SetMoney(value); } } - public Font MainFont { get { return GetMainFont(); } } - public Theme Theme { get { return GetCurrentTheme(); } } + static public int Money { get { return Settings.Default.Money; } set { SetMoney(value); } } + static public Font MainFont { get { return GetMainFont(); } } + static public Theme Theme { get { return GetCurrentTheme(); } } - private List<Theme> allThemes; + static private List<Theme> allThemes = GetThemes(); private const string themeFilePath = "PuzzlePlayer_Namespace.Resources.Themes.txt"; - public UserDataManager() - { - allThemes = GetThemes(); - } + public const int FONTSIZE = 16; - private List<Theme> GetThemes() + static public List<Theme> GetThemes() { List<Theme> result = new List<Theme>(); @@ -85,7 +82,7 @@ namespace PuzzlePlayer_Namespace return result; } - private void SetMoney(int newValue) + static private void SetMoney(int newValue) { if (newValue < 0) return; @@ -94,22 +91,20 @@ namespace PuzzlePlayer_Namespace Settings.Default.Save(); } - private Font GetMainFont() + static private Font GetMainFont() { string fontName = Settings.Default.FontName; - int fontSize = Settings.Default.FontSize; - return new Font(fontName, fontSize); + return new Font(fontName, FONTSIZE); } - public void SetMainFont(string fontName, int fontSize) + static public void SetMainFont(string fontName) { Settings.Default.FontName = fontName; - Settings.Default.FontSize = fontSize; Settings.Default.Save(); } - private Theme GetCurrentTheme() + static private Theme GetCurrentTheme() { string currentThemeName = Settings.Default.ThemeName; foreach (Theme t in allThemes) @@ -120,7 +115,7 @@ namespace PuzzlePlayer_Namespace throw new Exception("can't find the selected theme in unlocked themes"); } - public void SetCurrentTheme(string newThemeName) + static public void SetCurrentTheme(string newThemeName) { foreach (Theme t in allThemes) { @@ -133,7 +128,7 @@ namespace PuzzlePlayer_Namespace } } - public void UnlockTheme(string ThemeToUnlock) + static public void UnlockTheme(string ThemeToUnlock) { // update the unlockedThemes list for (int i = 0; i < allThemes.Count; i++)