110 lines
3.0 KiB
C#
110 lines
3.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace NonoGramme
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
const int UI_BORDER = 30;
|
|
|
|
string selectedFolder;
|
|
string selectedNonoGram;
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
private void NewGame()
|
|
{
|
|
nonogramme1.NewRandomGame(new Size(5, 5));
|
|
RefreshUi();
|
|
}
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
{
|
|
//ScaleUi();
|
|
NewGame();
|
|
}
|
|
|
|
private void Form1_Resize(object sender, EventArgs e)
|
|
{
|
|
//ScaleUi();
|
|
}
|
|
private void ScaleUi()
|
|
{
|
|
if (ClientSize.Width > ClientSize.Height)
|
|
{
|
|
nonogramme1.Size = new Size(ClientSize.Height, ClientSize.Height - UI_BORDER);
|
|
}
|
|
else
|
|
{
|
|
nonogramme1.Size = new Size(ClientSize.Width - UI_BORDER, ClientSize.Width);
|
|
}
|
|
RefreshUi();
|
|
}
|
|
private void RefreshUi()
|
|
{
|
|
nonogramme1.Refresh();
|
|
//ScaleUi();
|
|
}
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
FolderBrowserDialog dialog = new FolderBrowserDialog();
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
selectedFolder = dialog.SelectedPath;
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("Ooops... Could not retrieve folder informations :(");
|
|
}
|
|
|
|
if (Directory.Exists(selectedFolder))
|
|
{
|
|
lsbFiles.Items.Clear();
|
|
string[] nonFiles = Directory.GetFiles(selectedFolder, "*.non");
|
|
|
|
foreach (string file in nonFiles)
|
|
{
|
|
lsbFiles.Items.Add(Path.GetFileName(file));
|
|
}
|
|
}
|
|
}
|
|
|
|
private void lsbFiles_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
string selectedFile = selectedFolder + "\\" + lsbFiles.Items[lsbFiles.SelectedIndex];
|
|
if (Directory.Exists(selectedFolder) && File.Exists(selectedFile))
|
|
{
|
|
selectedNonoGram = selectedFile;
|
|
nonogramme1.LoadNewGame(selectedNonoGram);
|
|
RefreshUi();
|
|
}
|
|
}
|
|
|
|
private void nonogramme1_Click(object sender, EventArgs e)
|
|
{
|
|
//The problem with click is that it is called 2 times because it detects mouse down AND ouse up
|
|
}
|
|
|
|
private void nonogramme1_MouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
nonogramme1.CursorClick(nonogramme1.PointToClient(MousePosition));
|
|
RefreshUi();
|
|
}
|
|
|
|
private void btnShow_Click(object sender, EventArgs e)
|
|
{
|
|
nonogramme1.ToggleSolution();
|
|
RefreshUi();
|
|
}
|
|
}
|
|
}
|