public void Click(Vector2 cursorLoc, Map tileMap, Texture2D tileSheet)
{
KeyboardState keyState = Keyboard.GetState();
int x = (int)(cursorLoc.X + 2) / size; //Why the +2? Because cursorLoc is modified by -2. Duh.
int y = (int)(cursorLoc.Y + 2) / size; //Same goes for this.
int tsWidth = tileSheet.Width / size; //The width of the tilesheet in tiles
if (drag)
editorPanel = new Vector2(x, y); //If dragging the editor panel, set its location to cursor location
else
{
if ((x >= (int)editorPanel.X && x <= (int)editorPanel.X + tsWidth) && //Uhhmm...well basically this is checking if the crosshair
(y >= (int)editorPanel.Y && y <= (int)editorPanel.Y + tileSheet.Height / size) && //is within the editor panel, and the
keyState.IsKeyDown(Keys.Space)) //spacebar is pressed
{
currentTile = ((y - (int)editorPanel.Y) * tsWidth) + (x - (int)editorPanel.X); //Sets the current tile as a function of its location on the tilesheet (focus if you want to understand this one)
}
else if ((x >= (int)editorPanel.X && x <= (int)editorPanel.X + tsWidth) && //Same as the last one, only simpler. If the
(y == (int)editorPanel.Y - 1) && keyState.IsKeyDown(Keys.Space)) //crosshair is on the top of the editor window, allow user to drag
{
drag = true;
}
else //User wants to change the tile
{
Rectangle clip = new Rectangle(currentTile%3*size,currentTile/3*size,size,size);
tileMap.Set(y, x, new Tile(tileSheet,clip,Tile.SOLID_BLOCK));
}
}
}