From 9aeb8f5265dcbe368ec47a5e1654b3a203141bcd Mon Sep 17 00:00:00 2001
From: bionic85 <144353436+bionic85@users.noreply.github.com>
Date: Wed, 8 Jan 2025 13:31:12 +0100
Subject: [PATCH] Integraded UserDAtaManager into whole project. also removed
 the text size option

---
 PuzzlePlayer/App.config                      |   3 -
 PuzzlePlayer/Properties/Settings.Designer.cs |  12 --
 PuzzlePlayer/Properties/Settings.settings    |   3 -
 PuzzlePlayer/PuzzleForm.cs                   |  22 ++--
 PuzzlePlayer/PuzzlePlayer.cs                 |  30 +++--
 PuzzlePlayer/SettingForm.cs                  | 115 ++++++-------------
 PuzzlePlayer/UserDataManager.cs              |  33 +++---
 7 files changed, 74 insertions(+), 144 deletions(-)

diff --git a/PuzzlePlayer/App.config b/PuzzlePlayer/App.config
index 8a5320f..78b587e 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 b26524e..c36b667 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 62db88e..5b860f4 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 8a9957d..fa2cdb8 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 3db438e..7f01707 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 06f4075..40fcb08 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 cefa354..e48d021 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++)
-- 
GitLab