Ejemplo n.º 1
0
 /// <summary>
 /// Constructs a new ResizeDialog for resizing a TilemapLayer 
 /// </summary>
 public ResizeDialog(TilemapLayer layer)
 {
     InitializeComponent();
     Layer = layer;
     textBoxWidth.Text = layer.Width.ToString();
     textBoxHeight.Text = layer.Height.ToString();
     resizeAnchor = ResizeAnchor.TopRight;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new dialog exposing the properties of a TilemapLayer
        /// </summary>
        /// <param name="layer">The TilemapLayer to edit</param>
        public LayerDialog(TilemapLayer layer)
        {
            Layer = layer;

            InitializeComponent();

            textBoxName.Text = layer.Name;

            textBoxRed.Text = layer.Color.R.ToString();
            trackBarRed.Value = layer.Color.R;
            textBoxGreen.Text = layer.Color.G.ToString();
            trackBarGreen.Value = layer.Color.G;
            textBoxBlue.Text = layer.Color.B.ToString();
            trackBarBlue.Value = layer.Color.B;
            textBoxOpacity.Text = layer.Color.A.ToString();
            trackBarOpacity.Value = layer.Color.A;

            checkBoxVisible.Checked = layer.Visible;
        }
Ejemplo n.º 3
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;
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Recursive method for filling a space with a particular tile.
 /// </summary>
 /// <param name="x">The X position of the tile to fill</param>
 /// <param name="y">The y position of the tile to fill</param>
 /// <param name="oldIndex">The index we are replacing</param>
 /// <param name="newIndex">The index we are replacing with</param>
 protected void Flood(TilemapLayer layer, int x, int y, int oldIndex, int newIndex)
 {
     if (x >= 0 && x < layer.Width && y >= 0 && y < layer.Height && layer.TileData[x + y * layer.Width] == oldIndex)
     {
         layer.TileData[x + y * layer.Width] = newIndex;
         Flood(layer, x + 1, y, oldIndex, newIndex);
         Flood(layer, x - 1, y, oldIndex, newIndex);
         Flood(layer, x, y + 1, oldIndex, newIndex);
         Flood(layer, x, y - 1, oldIndex, newIndex);
     }
 }