Пример #1
0
 /// <summary>
 /// Creates a new TileDialog to represent an already-created Tile
 /// </summary>
 /// <param name="parent">The MainForm that created the dialog</param>
 /// <param name="imageDirectory">The directory to start looking for our tile images in</param>
 /// <param name="tileContent">The tileContent corresponding to the tile we are representing</param>
 public TileDialog(MainForm parent, string imageDirectory, TileContent tileContent)
     : this(parent, imageDirectory)
 {
     this.FileName = tileContent.Image.Filename;
     textBoxName.Text = tileContent.Name;
     pictureBox1.ImageLocation = this.FileName;
     Tile = new Tile();
     comboBoxType.SelectedItem = tileContent.TileType;
 }
Пример #2
0
        /// <summary>
        /// Event handler for importing a tile palette.  This method
        /// appends the tiles from the imported tile palette to the 
        /// existing tile palette - effectively combining the two sets.
        /// </summary>
        void ImportTilePalette(Object obj, EventArgs e)
        {
            // Create a OpenFileDialog to find our file
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.InitialDirectory = tilePalettePath;
            ofd.DefaultExt = ".tpal";
            ofd.Filter = "tile palette files (*.tpal)|*.tpal";
            ofd.RestoreDirectory = true;

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                Cursor = Cursors.WaitCursor;

                using (XmlReader reader = XmlReader.Create(ofd.FileName))
                {
                    List<TileContent> importTilePalette = IntermediateSerializer.Deserialize<List<TileContent>>(reader, null);

                    foreach (TileContent tileContent in importTilePalette)
                    {
                        // Create the equivalent Tile and append it to our tilemap's palette
                        Tile tile = new Tile();
                        tile.Name = tileContent.Name;
                        tile.Image = LoadTexture(tileContent.Image.Filename);
                        tilemap.TilePalette.Add(tile);

                        // Append the tileContent to our tile palette
                        tilePalette.Add(tileContent);

                        // Append the new tile to the tileListView
                        tileListView.Items.Add(tileContent.Name, tileImageList.Images.Count);

                        // Append the new tile image to our tileImageList
                        tileImageList.Images.Add(Bitmap.FromFile(tileContent.Image.Filename));
                    }
                }

                Cursor = Cursors.Arrow;
            }
        }
Пример #3
0
        /// <summary>
        /// Event handler that loads a new texture for our tile 
        /// </summary>
        private void buttonLoadImage_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();

            fileDialog.InitialDirectory = directory;
            fileDialog.Title = "Load Tile Image";
            fileDialog.Filter = "Image Files (*.png;*.bmp;*.jpg)|*.png;*.bmp;*.jpg;*.jpeg";

            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                // Store the filename
                FileName = fileDialog.FileName;

                // Load an image preview
                pictureBox1.ImageLocation = fileDialog.FileName;

                // Create the tile
                Tile = new Tile();
                Tile.Image = parent.LoadTexture(fileDialog.FileName);
                Tile.Name = textBoxName.Text;
            }
        }
Пример #4
0
        /// <summary>
        /// Event handler for when the "Load Map" menu item is clicked
        /// </summary>
        void LoadMapClicked(Object obj, EventArgs e)
        {
            // Make sure the current map is saved, or intentionally being discarded
            if (mapDirty)
            {
                string message = "The current tilemap has not been saved - opening a new one will lose any changes you made.  Are you sure you want to continue?";
                if (DialogResult.Yes != MessageBox.Show(message, "Warning", MessageBoxButtons.YesNo))
                    return;
            }

            // Create a OpenFileDialog to find our file
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.InitialDirectory = tilemapPath;
            ofd.DefaultExt = ".tmap";
            ofd.Filter = "tilemap files (*.tmap)|*.tmap";
            ofd.RestoreDirectory = true;

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                Cursor = Cursors.WaitCursor;

                using (XmlReader reader = XmlReader.Create(ofd.FileName))
                {
                    TilemapContent tilemapContent = IntermediateSerializer.Deserialize<TilemapContent>(reader, null);

                    // Create a tilemap with the same size as our loaded one
                    tilemap = new Tilemap(tilemapContent.Name, tilemapContent.Layers.Count, tilemapContent.Width, tilemapContent.Height, tilemapContent.TileHeight, tilemapContent.TileWidth);

                    // Clear our old lists
                    tileImageList.Images.Clear();
                    tileListView.Items.Clear();
                    tilePalette.Clear();

                    // Create the tiles
                    foreach (TileContent tileContent in tilemapContent.TilePalette)
                    {
                        // Load the texture through the content pipline so we can render it
                        // in our XNA controls
                        Texture2D texture = LoadTexture(tileContent.Image.Filename);

                        // Create an instance of the tile and add it to the palette
                        Tile tile = new Tile(){
                            Name = tileContent.Name,
                            Image = texture
                        };
                        tilemap.TilePalette.Add(tile);

                        // Add the new tile image to the tileListView, and assign it a new image
                        tileListView.Items.Add(tileContent.Name, tileImageList.Images.Count);

                        // Load the new image representing our new tile
                        tileImageList.Images.Add(Bitmap.FromFile(tileContent.Image.Filename));

                        // Add the TileContent to our TilePalette
                        tilePalette.Add(tileContent);
                    }

                    // Create the layers
                    tilemap.Layers.Clear();
                    listBoxLayers.Items.Clear();
                    foreach (TilemapLayerContent layerContent in tilemapContent.Layers)
                    {
                        // Create a corresponding TilemapLayer
                        TilemapLayer layer = new TilemapLayer(layerContent.Name, layerContent.Width, layerContent.Height, layerContent.TileWidth, layerContent.TileHeight);
                        layer.TileData = layerContent.TileData;

                        // Add the layer to our tilemap
                        tilemap.Layers.Add(layer);

                        // Add the layer to our layer GUI list
                        listBoxLayers.Items.Add(layer.Name);
                    }

                    // Deselect the selected tile index on the mapViewer
                    mapViewerControl.SelectedTileIndex = -1;
                }

                Cursor = Cursors.Arrow;
            }
        }