/*************************************************************MOUSE EVENTS*/ /*************************************************************MOUSE EVENTS*/ /*************************************************************MOUSE EVENTS*/ // Click event for the FLOOR select button. private void loadImageButton_Click(object sender, EventArgs e) { // Set erasing to off. isErasing = false; // Open the image select diaglog box and check if the user selected "OK" if (selectImageDialog.ShowDialog() == DialogResult.OK) { try { // Load the image Bitmap newImage = new Bitmap(Image.FromFile(selectImageDialog.FileName), ImagePalette.IMAGE_SIZE, ImagePalette.IMAGE_SIZE); // Add it to the image palette map.GetImagePalette().AddNewImage(selectImageDialog.FileName, newImage); // Set the current image to paint. map.GetImagePalette().SetCurrentImage(selectImageDialog.FileName); } catch (Exception ex) { MessageBox.Show("Could not load image: " + selectImageDialog.FileName); Console.WriteLine("Could not load image: " + selectImageDialog.FileName); Console.WriteLine(ex.ToString()); } } UpdateCurrentImagePreview(); }
// Method for creating a new blank map. public void CreateNewMap(int x, int y) { map = new Map(x, y); map.RebuildMap(); map.GetImagePalette().PrintImageList(); Refresh(); }
/********************************INPUT*/ /********************************INPUT*/ /********************************INPUT*/ /********************************INPUT*/ // Returns a new map object based on the settings in the passed map path name. public static Map LoadMap(String map) { // Create a new map to build from a local file. Map newMap = new Map(0, 0); // Placeholder for the line being currently ready from file. String line; // Create a file from the supplied map name/file path. System.IO.StreamReader file = new System.IO.StreamReader(map); // Go through each line of the map file and process each command appropriately. while ((line = file.ReadLine()) != null) { /*************************************FILE END*/ if (line.StartsWith(MapIO.CLOSE_FILE)) { break; } /*************************************COMMENTS*/ if (line.StartsWith(MapIO.COMMENT)) { continue; } /************************************LOAD IMAGES*/ if (line.StartsWith(MapIO.IMAGE_LOAD)) { // Cycle to the next line line = file.ReadLine(); // Keep loading each line as an image until you reach the end. while (line != MapIO.IMAGE_CLOSE) { try { Bitmap image = new Bitmap(Image.FromFile(line), ImagePalette.IMAGE_SIZE, ImagePalette.IMAGE_SIZE); newMap.GetImagePalette().AddNewImage(line, image); } catch (Exception e) { Console.WriteLine("Could not load image: " + line); Console.WriteLine("" + e.ToString()); } // Make sure you cycle to the next line in the file before you restart the loop. line = file.ReadLine(); } continue; } /************************************LOAD MAP*/ if (line.StartsWith(MapIO.MAP_LOAD)) { // Cycle to the next line, which is the beginning of the map attributes. line = file.ReadLine(); // Get the map dimentions from the file into local variables. int colomns = Int32.Parse(line); line = file.ReadLine(); int rows = Int32.Parse(line); line = file.ReadLine(); // Set the map dimentions. newMap.SetColumns(colomns); newMap.SetRows(rows); newMap.RebuildMap(); // Loop through every tile and set its images. while (line != MapIO.MAP_CLOSE) { for (int i = 0; i < newMap.GetColumns(); i++) { for (int j = 0; j < newMap.GetRows(); j++) { // Read the tile coordinates and advance the line reader as necessary. int x = Int32.Parse(line); line = file.ReadLine(); int y = Int32.Parse(line); line = file.ReadLine(); // Loop through each layer of the tile and set its image. for (int n = 0; n < Map.NUMBER_OF_LAYERS; n++) { newMap.GetTiles()[x, y].SetTileImage((Map.LAYER)n, line); line = file.ReadLine(); } } } } continue; } } // Shut the door. file.Close(); return(newMap); }
/********************************INPUT*/ /********************************INPUT*/ /********************************INPUT*/ /********************************INPUT*/ // Returns a new map object based on the settings in the passed map path name. public static Map LoadMap(String map) { // Create a new map to build from a local file. Map newMap = new Map(0, 0); // Placeholder for the line being currently ready from file. String line; // Create a file from the supplied map name/file path. System.IO.StreamReader file = new System.IO.StreamReader(map); // Go through each line of the map file and process each command appropriately. while ((line = file.ReadLine()) != null) { /*************************************FILE END*/ if (line.StartsWith(MapIO.CLOSE_FILE)) break; /*************************************COMMENTS*/ if (line.StartsWith(MapIO.COMMENT)) continue; /************************************LOAD IMAGES*/ if(line.StartsWith(MapIO.IMAGE_LOAD)) { // Cycle to the next line line = file.ReadLine(); // Keep loading each line as an image until you reach the end. while (line != MapIO.IMAGE_CLOSE) { try { Bitmap image = new Bitmap(Image.FromFile(line), ImagePalette.IMAGE_SIZE, ImagePalette.IMAGE_SIZE); newMap.GetImagePalette().AddNewImage(line, image); } catch (Exception e) { Console.WriteLine("Could not load image: " + line); Console.WriteLine("" + e.ToString()); } // Make sure you cycle to the next line in the file before you restart the loop. line = file.ReadLine(); } continue; } /************************************LOAD MAP*/ if (line.StartsWith(MapIO.MAP_LOAD)) { // Cycle to the next line, which is the beginning of the map attributes. line = file.ReadLine(); // Get the map dimentions from the file into local variables. int colomns = Int32.Parse(line); line = file.ReadLine(); int rows = Int32.Parse(line); line = file.ReadLine(); // Set the map dimentions. newMap.SetColumns(colomns); newMap.SetRows(rows); newMap.RebuildMap(); // Loop through every tile and set its images. while (line != MapIO.MAP_CLOSE) { for (int i = 0; i < newMap.GetColumns(); i++) { for (int j = 0; j < newMap.GetRows(); j++) { // Read the tile coordinates and advance the line reader as necessary. int x = Int32.Parse(line); line = file.ReadLine(); int y = Int32.Parse(line); line = file.ReadLine(); // Loop through each layer of the tile and set its image. for (int n = 0; n < Map.NUMBER_OF_LAYERS; n++) { newMap.GetTiles()[x, y].SetTileImage((Map.LAYER)n, line); line = file.ReadLine(); } } } } continue; } } // Shut the door. file.Close(); return newMap; }