private void pnlTileMap_MouseClick(object sender, MouseEventArgs e) { Rectangle mapRect = new Rectangle(0, 0, pnlTileMap.Width, pnlTileMap.Height); if (e.Button == MouseButtons.Left) { Point offset = e.Location; offset.X -= pnlTileMap.AutoScrollPosition.X; offset.Y -= pnlTileMap.AutoScrollPosition.Y; int tempIndexX, tempIndexY; tempIndexX = offset.X / tileSize.Width; tempIndexY = offset.Y / tileSize.Height; int mapTile = (tempIndexY * mapSize.Width) + tempIndexX; if (layerMap == 'm') { if (tempIndexX < mapSize.Width && tempIndexY < mapSize.Height && mapRect.Contains(e.Location)) { if (paintMode == 'p') map[tempIndexX, tempIndexY].TileID = selectedTile; else if (paintMode == 'e') map[tempIndexX, tempIndexY].TileID = 0; else if (paintMode == 'f') { tileFill(tempIndexX, tempIndexY, map[tempIndexX, tempIndexY].TileID); } } } else if (layerMap == 'c') { if (tempIndexX < mapSize.Width && tempIndexY < mapSize.Height && mapRect.Contains(e.Location)) { map[tempIndexX, tempIndexY].CollisionID = (int)numCollisionIDS.Value; } } else if (layerMap == 'e') { if (tempIndexX < mapSize.Width && tempIndexY < mapSize.Height && mapRect.Contains(e.Location)) { if (eventMode == 'a') { if (EID == null) { EID = new EventDialog(this, tempIndexX, tempIndexY); EID.FormClosed += EID_FormClosed; EID.Show(this); } } else if (eventMode == 'r') { map[tempIndexX, tempIndexY].EventID = "none"; } } } else if (layerMap == 'o') { if (tempIndexX < mapSize.Width && tempIndexY < mapSize.Height && mapRect.Contains(e.Location)) { if (objectMode == 'o') { if (map[tempIndexX, tempIndexY].ObjectID == '0') { if (cmbObjects.SelectedItem.ToString() == "Player" && !playerSpawned) { playerSpawned = true; map[tempIndexX, tempIndexY].ObjectID = 'p'; placeHolder = new ObjectStruct("Player"); placeHolder.WaypointTiles.Add(mapTile); lstWaypoints.Items.Add(mapTile); levelObjects.Add(placeHolder); map[tempIndexX, tempIndexY].ObjectNumber = objectCount; lstObjects.Items.Add(placeHolder.Name); lstObjects.SelectedIndex = objectCount; ++objectCount; } else if (cmbObjects.SelectedItem.ToString() == "Guard") { map[tempIndexX, tempIndexY].ObjectID = 'g'; placeHolder = new ObjectStruct("Guard"); placeHolder.WaypointTiles.Add(mapTile); lstWaypoints.Items.Add(mapTile); levelObjects.Add(placeHolder); map[tempIndexX, tempIndexY].ObjectNumber = objectCount; lstObjects.Items.Add(placeHolder.Name); lstObjects.SelectedIndex = objectCount; ++objectCount; } } } else if (objectMode == 'j') { if (map[tempIndexX, tempIndexY].ObjectID == 'p') playerSpawned = false; if (map[tempIndexX, tempIndexY].ObjectID == 'p' || map[tempIndexX, tempIndexY].ObjectID == 'g') { objectRemoved = true; levelObjects.RemoveAt(map[tempIndexX, tempIndexY].ObjectNumber); lstObjects.Items.RemoveAt(map[tempIndexX, tempIndexY].ObjectNumber); objectIndexAbove = map[tempIndexX, tempIndexY].ObjectNumber; --objectCount; lstWaypoints.Items.Clear(); } map[tempIndexX, tempIndexY].ObjectID = '0'; } else if (objectMode == 'w') { if (!levelObjects[lstObjects.SelectedIndex].WaypointTiles.Contains(mapTile)) { levelObjects[lstObjects.SelectedIndex].WaypointTiles.Add(mapTile); lstWaypoints.Items.Add(levelObjects[lstObjects.SelectedIndex].WaypointTiles[levelObjects[lstObjects.SelectedIndex].WaypointTiles.Count - 1]); } } else if (objectMode == 'd') { for (int i = 0; i < levelObjects[lstObjects.SelectedIndex].WaypointTiles.Count; ++i) { if (mapTile == levelObjects[lstObjects.SelectedIndex].WaypointTiles[i]) { levelObjects[lstObjects.SelectedIndex].WaypointTiles.RemoveAt(i); lstWaypoints.Items.RemoveAt(i); } } } } } if (over != null) over.Render(); } else if (e.Button == MouseButtons.Right) { Point offset = e.Location; offset.X -= pnlTileMap.AutoScrollPosition.X; offset.Y -= pnlTileMap.AutoScrollPosition.Y; int tempIndexX, tempIndexY; tempIndexX = offset.X / tileSize.Width; tempIndexY = offset.Y / tileSize.Height; if (tempIndexX < mapSize.Width && tempIndexY < mapSize.Height && mapRect.Contains(e.Location)) { tipMap.ToolTipTitle = "Tile Info"; string caption = "Tile ID: " + map[tempIndexX, tempIndexY].TileID.ToString() + "\nTile Collision: " + map[tempIndexX, tempIndexY].CollisionID.ToString() + "\nEvent: " + map[tempIndexX, tempIndexY].EventID + "\nObject ID: " + map[tempIndexX, tempIndexY].ObjectID; tipMap.Show(caption, pnlTileMap, 5000); } } }
void EID_FormClosed(object sender, FormClosedEventArgs e) { EID = null; }