-
DamianKomdeur authored
Sudoku Generator + Manual placement + Small settings fixes (Now all menu items change color correctly and the settings are accessible from a puzzleform)
DamianKomdeur authoredSudoku Generator + Manual placement + Small settings fixes (Now all menu items change color correctly and the settings are accessible from a puzzleform)
PuzzlePlayer.cs 5.51 KiB
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
namespace PuzzlePlayer_Namespace
{
internal class Program
{
internal static void Main(string[] args)
{
Application.Run(new MainForm()); //nnew PuzzleForm(new Maze())
}
}
internal class MainForm : Form
{
List<PuzzleForm> puzzleForms = new List<PuzzleForm>();
public MainForm()
{
SetUpPuzzleForms();
SetUpUI();
}
private void SetUpPuzzleForms()
{
puzzleForms.Clear();
puzzleForms.Add(new PuzzleForm(new Binary()));
puzzleForms.Add(new PuzzleForm(new Maze()));
puzzleForms.Add(new PuzzleForm(new Sudoku()));
}
private void SetUpUI()
{
// -- 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}";
Image normalImage = Image.FromFile(image + ".jpg");
Image grayImage = Image.FromFile(image + "Gray.jpg");
// Set the name of the button
RoundedButton button = new RoundedButton
{
Text = puzzleForms[i].puzzleType,
Margin = new Padding(10),
Height = 345,
Width = 345,
Image = normalImage,
FlatStyle = FlatStyle.Flat,
Font = SettingForm.mainFont,
Name = i.ToString()
};
button.MouseEnter += (object o, EventArgs e) =>
{
button.Image = grayImage;
};
button.MouseLeave += (object o, EventArgs e) =>
{
button.Image = normalImage;
};
button.MouseClick += (object o, MouseEventArgs e) =>
{
this.Hide();
RoundedButton rb = (RoundedButton) o;
PuzzleForm puzzleForm = puzzleForms[int.Parse(rb.Name)];
puzzleForm.FormClosed += (object o, FormClosedEventArgs fcea) =>
{
this.BackColor = SettingForm.primaryColor;
this.ForeColor = SettingForm.tertiaryColor;
foreach (Control control in this.Controls)
{
SettingForm.UpdateSettings(control);
}
this.Show();
};
puzzleForm.Show();
SetUpPuzzleForms(); //cheeky dwdw
};
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();
}
}
}