diff --git a/PuzzlePlayer/PuzzlePlayer.cs b/PuzzlePlayer/PuzzlePlayer.cs index b7b74b7cf727f93d666cd8af4836c0ea2fa0840b..865952b8349b0cc1494fd6a7fc6d8e734e58cb77 100644 --- a/PuzzlePlayer/PuzzlePlayer.cs +++ b/PuzzlePlayer/PuzzlePlayer.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Drawing; using System.Windows.Forms; +using static System.Windows.Forms.DataFormats; namespace PuzzlePlayer_Namespace { @@ -9,7 +11,7 @@ namespace PuzzlePlayer_Namespace { internal static void Main(string[] args) { - Application.Run(new PuzzleForm(new Binary(6))); + Application.Run(new MainForm()); } } @@ -17,33 +19,123 @@ namespace PuzzlePlayer_Namespace { List<PuzzleForm> puzzleForms = new List<PuzzleForm>(); - public Panel buttonsPanel; - public Button[] buttons; - - public MainForm() { - this.ClientSize = new Size(1000, 500); - - SetUpPuzzleForms(); SetUpUI(); } - private void SetUpPuzzleForms() { - puzzleForms.Add(new PuzzleForm(new Binary())); + for (int i = 0; i < 5; i++) + { + puzzleForms.Add(new PuzzleForm(new Binair())); + } + puzzleForms.Add(new PuzzleForm(new Binair())); } private void SetUpUI() { - buttons = new Button[puzzleForms.Count]; - - //binair. + // -- List<RoundedButton> buttons = new List<RoundedButton>(); + + this.ClientSize = new Size(1115, 755); + this.BackColor = SettingForm.primaryColor; + this.Text = "PuzzlePlayer"; + + MenuStrip menuStrip = new MenuStrip + { + BackColor = SettingForm.secondaryColor, + ForeColor = SettingForm.secondaryColor, + Name = "Main menu", + Text = "Main Menu", + Dock = DockStyle.Top, + Font = SettingForm.mainFont, + }; + + ToolStripMenuItem menuSettings = new ToolStripMenuItem + { + BackColor = Color.FromArgb(54, 57, 62), + ForeColor = Color.Black, + Text = "Settings", + TextAlign = ContentAlignment.BottomRight, + Font = SettingForm.mainFont, + }; + + menuSettings.Click += (object o, EventArgs e) => + { + this.Hide(); + SettingForm settingForm = new SettingForm(); + + settingForm.FormClosed += (object s, FormClosedEventArgs args) => + { + this.BackColor = SettingForm.primaryColor; + this.ForeColor = SettingForm.tertiaryColor; + + foreach (Control control in this.Controls) + { + SettingForm.UpdateSettings(control); + } + + this.Show(); + }; + + settingForm.Show(); + }; + + // Create a flow layout panel that automatically sorts the buttons when the window is resized + FlowLayoutPanel buttonsPanel = new FlowLayoutPanel + { + Location = new Point(0, menuStrip.Height), + Size = new Size(ClientSize.Width, ClientSize.Height - menuStrip.Height), + Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom, + FlowDirection = FlowDirection.LeftToRight, + // Add another row if there are more buttons than that fit in the window horizontally + WrapContents = true, + // Add a scroll bar in case the buttons don't fit on the window vertically + AutoScroll = true, + }; + + // Add a button for each puzzle type + for (int i = 0; i < puzzleForms.Count; i++) + { + string image = "../../..//Resources/" + $"{puzzleForms[i].puzzleType}"; + + // Set the name of the button + RoundedButton button = new RoundedButton + { + Text = puzzleForms[i].puzzleType, + Margin = new Padding(10), + Height = 345, + Width = 345, + Image = Image.FromFile(image + ".jpg"), + FlatStyle = FlatStyle.Flat, + Font = SettingForm.mainFont, + }; + + button.MouseEnter += (object o, EventArgs e) => + { + button.Image = Image.FromFile(image + "Gray.jpg"); + }; + + button.MouseLeave += (object o, EventArgs e) => + { + button.Image = Image.FromFile(image + ".jpg"); + }; + + buttonsPanel.Controls.Add(button); + // -- buttons.Add(button); + + if (i == 0) + { + this.MinimumSize = new Size(button.Width + 56, button.Height + 83); + } + } + this.Controls.Add(menuStrip); + this.Controls.Add(buttonsPanel); + + menuStrip.Items.Add(menuSettings); + menuStrip.BringToFront(); } } - - } diff --git a/PuzzlePlayer/PuzzlePlayer.csproj.user b/PuzzlePlayer/PuzzlePlayer.csproj.user index 48013b939b6a83ea7bdd00433587cd1640c51226..dfd866b260ac6e27afb88adc82aa59c2a1d77174 100644 --- a/PuzzlePlayer/PuzzlePlayer.csproj.user +++ b/PuzzlePlayer/PuzzlePlayer.csproj.user @@ -5,5 +5,11 @@ <Compile Update="PuzzleForm.cs"> <SubType>Form</SubType> </Compile> + <Compile Update="RoundedButton.cs"> + <SubType>Component</SubType> + </Compile> + <Compile Update="SettingForm.cs"> + <SubType>Form</SubType> + </Compile> </ItemGroup> </Project> \ No newline at end of file diff --git a/PuzzlePlayer/Resources/Binair.jpg b/PuzzlePlayer/Resources/Binair.jpg new file mode 100644 index 0000000000000000000000000000000000000000..ae6a6745eb6b859ed91eb45598e2c0d6bf342d84 Binary files /dev/null and b/PuzzlePlayer/Resources/Binair.jpg differ diff --git a/PuzzlePlayer/Resources/BinairGray.jpg b/PuzzlePlayer/Resources/BinairGray.jpg new file mode 100644 index 0000000000000000000000000000000000000000..033ef24f68d8cedcb98a1389a0662edf349f2df0 Binary files /dev/null and b/PuzzlePlayer/Resources/BinairGray.jpg differ diff --git a/PuzzlePlayer/RoundedButton.cs b/PuzzlePlayer/RoundedButton.cs new file mode 100644 index 0000000000000000000000000000000000000000..84637ffc4ca69838553afcf32deede2bdb65777b --- /dev/null +++ b/PuzzlePlayer/RoundedButton.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Drawing.Drawing2D; +using System.Drawing; +using System.Windows.Forms; + +namespace PuzzlePlayer_Namespace +{ + class RoundedButton : Button + { + GraphicsPath GetRoundPath(RectangleF Rect, int radius) + { + float r2 = radius / 2f; + GraphicsPath GraphPath = new GraphicsPath(); + GraphPath.AddArc(Rect.X, Rect.Y, radius, radius, 180, 90); + GraphPath.AddLine(Rect.X + r2, Rect.Y, Rect.Width - r2, Rect.Y); + GraphPath.AddArc(Rect.X + Rect.Width - radius, Rect.Y, radius, radius, 270, 90); + GraphPath.AddLine(Rect.Width, Rect.Y + r2, Rect.Width, Rect.Height - r2); + GraphPath.AddArc(Rect.X + Rect.Width - radius, + Rect.Y + Rect.Height - radius, radius, radius, 0, 90); + GraphPath.AddLine(Rect.Width - r2, Rect.Height, Rect.X + r2, Rect.Height); + GraphPath.AddArc(Rect.X, Rect.Y + Rect.Height - radius, radius, radius, 90, 90); + GraphPath.AddLine(Rect.X, Rect.Height - r2, Rect.X, Rect.Y + r2); + GraphPath.CloseFigure(); + return GraphPath; + } + + protected override void OnPaint(PaintEventArgs e) + { + base.OnPaint(e); + RectangleF Rect = new RectangleF(0, 0, this.Width, this.Height); + using (GraphicsPath GraphPath = GetRoundPath(Rect, 50)) + { + this.Region = new Region(GraphPath); + using (Pen pen = new Pen(Color.Black, 1.75f)) + { + pen.Alignment = PenAlignment.Inset; + e.Graphics.DrawPath(pen, GraphPath); + } + } + } + } +} diff --git a/PuzzlePlayer/SettingForm.cs b/PuzzlePlayer/SettingForm.cs new file mode 100644 index 0000000000000000000000000000000000000000..1030962d8b24c369fd39dc6f8d8455644fb84baa --- /dev/null +++ b/PuzzlePlayer/SettingForm.cs @@ -0,0 +1,198 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Drawing; +using System.Windows.Forms; + +namespace PuzzlePlayer_Namespace +{ + internal class SettingForm : Form + { + // Public variables for all settings + public static Color primaryColor = Color.FromArgb(66, 69, 73); + public static Color secondaryColor = Color.FromArgb(54, 57, 62); + public static Color tertiaryColor = Color.FromArgb(66, 69, 73); + public static int fontSize = 16; + public static Font mainFont = new Font("Gotham", fontSize); + + public SettingForm() + { + SetUpUi(); + + this.BackColor = primaryColor; + + foreach (Control control in Controls) + { + UpdateSettings(control); + } + Invalidate(); + } + + private void SetUpUi() + { + this.ClientSize = new Size(1115, 755); + this.BackColor = SettingForm.primaryColor; + this.Text = "PuzzlePlayer"; + + MenuStrip menuStrip = new MenuStrip + { + BackColor = secondaryColor, + ForeColor = secondaryColor, + Name = "Main menu", + Text = "Main Menu", + Dock = DockStyle.Top + }; + + ToolStripMenuItem menuBack = new ToolStripMenuItem + { + BackColor = secondaryColor, + ForeColor = Color.Black, + Text = "Back", + TextAlign = ContentAlignment.BottomRight + }; + + menuBack.Click += (object o, EventArgs e) => + { + this.Close(); + }; + + // + ComboBox themeSelector = new ComboBox + { + Text = "Theme", + Name = "Theme", + Height = 25, + Width = 250, + BackColor = SettingForm.secondaryColor, + ForeColor = Color.Black, + Margin = new Padding(20) + }; + themeSelector.Items.Add("Dark"); + themeSelector.Items.Add("Light"); + + themeSelector.SelectedIndexChanged += (object o, EventArgs e) => + { + 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; + } + }; + + 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"); + + sizeSelector.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); + }; + + FlowLayoutPanel settingsPanel = new FlowLayoutPanel + { + Location = new Point(0, menuStrip.Height), + Size = new Size(ClientSize.Width, ClientSize.Height - menuStrip.Height - 100), + Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom, + FlowDirection = FlowDirection.TopDown, + WrapContents = true, + AutoScroll = true, + }; + + // + RoundedButton saveButton = new RoundedButton + { + Text = "Save", + Name = "Save", + Height = 100, + Width = 350, + BackColor = SettingForm.secondaryColor, + ForeColor = Color.Black, + Location = new Point(10, ClientSize.Height - 110), + Anchor = AnchorStyles.Left | AnchorStyles.Bottom, + FlatStyle = FlatStyle.Flat, + Margin = new Padding(10) + }; + + saveButton.Click += (object o, EventArgs e) => + { + this.BackColor = primaryColor; + + foreach (Control control in Controls) + { + UpdateSettings(control); + } + + settingsPanel.BackColor = primaryColor; + Invalidate(); + }; + + // + this.Controls.Add(menuStrip); + this.Controls.Add(settingsPanel); + this.Controls.Add(saveButton); + + settingsPanel.Controls.Add(themeSelector); + settingsPanel.Controls.Add(sizeSelector); + + menuStrip.Items.Add(menuBack); + + menuStrip.BringToFront(); + themeSelector.BringToFront(); + saveButton.BringToFront(); + } + + public static void UpdateSettings(Control control) + { + if (control is not FlowLayoutPanel) + { + control.BackColor = secondaryColor; + control.ForeColor = tertiaryColor; + } + else + { + control.BackColor = primaryColor; + } + + try + { + control.Font = mainFont; + } + catch (Exception ex) { } + + foreach (Control childControl in control.Controls) + { + UpdateSettings(childControl); + } + } + } +}