Fixed the bug where some files would not work, and now you can click on the tiles
This commit is contained in:
+58
-7
@@ -12,9 +12,10 @@ namespace NonoGramme
|
||||
{
|
||||
internal class Grid
|
||||
{
|
||||
private readonly Color DEFAULT_FULL_COLOR = Color.Black;
|
||||
private readonly Color DEFAULT_FULL_COLOR = Color.Red;
|
||||
private readonly Color DEFAULT_EMPTY_COLOR = Color.LightGray;
|
||||
private readonly Color DEBUG_UNDISCOVERED_COLOR = Color.DarkOliveGreen;
|
||||
private readonly Color DEFAULT_UNDISCOVERED_COLOR = Color.DarkOliveGreen;
|
||||
private readonly Color DEFAULT_DISCOVERED_COLOR = Color.Black;
|
||||
private readonly Color DEFAULT_BORDER_COLOR = Color.Pink;
|
||||
private readonly Color DEFAULT_ERROR_COLOR = Color.Purple;
|
||||
|
||||
@@ -22,21 +23,49 @@ namespace NonoGramme
|
||||
private Line[] _horizontalLines;
|
||||
private Line[] _verticalLines;
|
||||
|
||||
private Point _gridOffset;
|
||||
private Size _drawedBlocSize;
|
||||
|
||||
public Size GridSize { get => _gridSize; set => _gridSize = value; }
|
||||
internal Line[] HorizontalLines { get => _horizontalLines; set => _horizontalLines = value; }
|
||||
internal Line[] VerticalLines { get => _verticalLines; set => _verticalLines = value; }
|
||||
public Line[] HorizontalLines { get => _horizontalLines; set => _horizontalLines = value; }
|
||||
public Line[] VerticalLines { get => _verticalLines; set => _verticalLines = value; }
|
||||
public Point GridOffset
|
||||
{
|
||||
get { return _gridOffset; }
|
||||
set { if (value.X >= 0 && value.Y >= 0) { _gridOffset = value; } else { _gridOffset = new Point(-1, -1); }}
|
||||
}
|
||||
|
||||
public Size DrawedBlocSize { get => _drawedBlocSize; set => _drawedBlocSize = value; }
|
||||
|
||||
public Grid(Size size)
|
||||
{
|
||||
GridSize = size;
|
||||
HorizontalLines = new Line[size.Height];
|
||||
VerticalLines = new Line[size.Width];
|
||||
GridOffset = new Point(-1,-1);
|
||||
Populate();
|
||||
}
|
||||
public Grid(string filePath)
|
||||
{
|
||||
ImportFromFile(filePath);
|
||||
}
|
||||
public void Click(Point position)
|
||||
{
|
||||
//MessageBox.Show(position.ToString());
|
||||
if (GridOffset != new Point(-1, -1))
|
||||
{
|
||||
//The Grid has been Drawned and has a valid offset
|
||||
if (position.X >= GridOffset.X && position.Y >= GridOffset.Y)
|
||||
{
|
||||
//The click is on the grid
|
||||
Point relativePoint = new Point(position.X-GridOffset.X, position.Y-GridOffset.Y);
|
||||
Point reducedIndex = new Point(relativePoint.X / DrawedBlocSize.Width,relativePoint.Y / DrawedBlocSize.Height);
|
||||
//int flatIndex = position.Y * HorizontalLines.Count() + position.X;
|
||||
HorizontalLines[reducedIndex.Y].Click(reducedIndex.X);
|
||||
VerticalLines[reducedIndex.X].Click(reducedIndex.Y);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void ImportFromFile(string filePath)
|
||||
{
|
||||
//GridSize = size;
|
||||
@@ -91,15 +120,34 @@ namespace NonoGramme
|
||||
license = matches[0].Groups[1].Value;
|
||||
}
|
||||
|
||||
/*
|
||||
rx = new Regex(@"^height (?<height>[0-9]+)\nwidth (?<width>[0-9]+)", RegexOptions.Multiline | RegexOptions.IgnoreCase);
|
||||
matches = rx.Matches(fileContent);
|
||||
if (matches.Count > 0 && matches[0].Groups.Count > 0)
|
||||
{
|
||||
size =new Size(Convert.ToInt32(matches[0].Groups["width"].Value), Convert.ToInt32(matches[0].Groups["height"].Value));
|
||||
}
|
||||
*/
|
||||
|
||||
string TEST = "";
|
||||
int height = 0;
|
||||
int width = 0;
|
||||
|
||||
rx = new Regex(@"^height (?<height>[0-9]+)", RegexOptions.Multiline | RegexOptions.IgnoreCase);
|
||||
matches = rx.Matches(fileContent);
|
||||
if (matches.Count > 0 && matches[0].Groups.Count > 0)
|
||||
{
|
||||
height = Convert.ToInt32(matches[0].Groups[1].Value);
|
||||
}
|
||||
rx = new Regex(@"^width (?<height>[0-9]+)", RegexOptions.Multiline | RegexOptions.IgnoreCase);
|
||||
matches = rx.Matches(fileContent);
|
||||
if (matches.Count > 0 && matches[0].Groups.Count > 0)
|
||||
{
|
||||
width = Convert.ToInt32(matches[0].Groups[1].Value);
|
||||
}
|
||||
|
||||
size = new Size(width,height);
|
||||
|
||||
//string TEST = "";
|
||||
rows = new List<int>[size.Height];
|
||||
rx = new Regex(@"^rows\n(?<row>[0-9,]+\r?\n)+", RegexOptions.Multiline);
|
||||
matches = rx.Matches(fileContent);
|
||||
@@ -209,6 +257,9 @@ namespace NonoGramme
|
||||
Size actualSize = new Size(UI.Width - offset.X, UI.Height - offset.Y);
|
||||
Size blocSize = new Size(actualSize.Width/GridSize.Width,actualSize.Height/GridSize.Height);
|
||||
|
||||
DrawedBlocSize = blocSize;
|
||||
GridOffset = offset;
|
||||
|
||||
using (Graphics g = Graphics.FromImage(UI))
|
||||
{
|
||||
//Drawing the rows Text
|
||||
@@ -248,10 +299,10 @@ namespace NonoGramme
|
||||
g.FillRectangle(new SolidBrush(DEFAULT_EMPTY_COLOR), new Rectangle(position, blocSize));
|
||||
break;
|
||||
case Tile.State.Discovered:
|
||||
g.FillRectangle(new SolidBrush(DEFAULT_EMPTY_COLOR), new Rectangle(position, blocSize));
|
||||
g.FillRectangle(new SolidBrush(DEFAULT_DISCOVERED_COLOR), new Rectangle(position, blocSize));
|
||||
break;
|
||||
case Tile.State.Undiscovered:
|
||||
g.FillRectangle(new SolidBrush(DEBUG_UNDISCOVERED_COLOR), new Rectangle(position, blocSize));
|
||||
g.FillRectangle(new SolidBrush(DEFAULT_UNDISCOVERED_COLOR), new Rectangle(position, blocSize));
|
||||
break;
|
||||
default:
|
||||
g.FillRectangle(new SolidBrush(DEFAULT_ERROR_COLOR), new Rectangle(position, blocSize));
|
||||
|
||||
Reference in New Issue
Block a user