Beispiel #1
0
        void btnOK_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(tbLayerName.Text))
            {
                MessageBox.Show("You must enter a name for the layer.", "Missing Layer Name");
                return;
            }

            if (cbFill.Checked)
            {
                mapLayerData = new MapLayerData(
                    tbLayerName.Text,
                    LayerWidth,
                    LayerHeight,
                    (int)nudTile.Value,
                    (int)nudTileset.Value);
            }
            else
            {
                mapLayerData = new MapLayerData(
                    tbLayerName.Text,
                    LayerWidth,
                    LayerHeight);
            }

            okPressed = true;
            this.Close();
        }
Beispiel #2
0
        public static MapLayer FromMapLayerData(MapLayerData data)
        {
            MapLayer layer = new MapLayer(data.Width, data.Height);

            for (int y = 0; y < data.Height; y++)
            {
                for (int x = 0; x < data.Width; x++)
                {
                    layer.SetTile(x, y, data.GetTile(x, y).TileIndex, data.GetTile(x, y).TileSetIndex);
                }
            }

            return layer;
        }
Beispiel #3
0
        void saveLevelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (map == null)
                return;

            List<MapLayerData> mapLayerData = new List<MapLayerData>();

            for (int i = 0; i < clbLayers.Items.Count; i++)
            {
                if (layers[i] is MapLayer)
                {
                    MapLayerData data = new MapLayerData(
                        clbLayers.Items[i].ToString(),
                        ((MapLayer)layers[i]).Width,
                        ((MapLayer)layers[i]).Height);

                    for (int y = 0; y < ((MapLayer)layers[i]).Height; y++)
                        for (int x = 0; x < ((MapLayer)layers[i]).Width; x++)
                            data.SetTile(x, y, ((MapLayer)layers[i]).GetTile(x, y).TileIndex, ((MapLayer)layers[i]).GetTile(x, y).Tileset);

                    mapLayerData.Add(data);
                }
            }

            MapData mapData = new MapData(levelData.MapName, tileSetData, mapLayerData);

            FolderBrowserDialog fbDialog = new FolderBrowserDialog();

            fbDialog.Description = "Select Game Folder";
            fbDialog.SelectedPath = Application.StartupPath;

            DialogResult result = fbDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                if (!File.Exists(fbDialog.SelectedPath + @"\Game.xml"))
                {
                    MessageBox.Show("Game not found", "Error");
                    return;
                }

                string LevelPath = Path.Combine(fbDialog.SelectedPath, @"Levels\");
                string MapPath = Path.Combine(LevelPath, @"Maps\");

                if (!Directory.Exists(LevelPath))
                    Directory.CreateDirectory(LevelPath);

                if (!Directory.Exists(MapPath))
                    Directory.CreateDirectory(MapPath);

                XnaSerializer.Serialize<LevelData>(LevelPath + levelData.LevelName + ".xml", levelData);
                XnaSerializer.Serialize<MapData>(MapPath + mapData.MapName + ".xml", mapData);
            }
        }
Beispiel #4
0
        void saveLayerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (layers.Count == 0)
                return;

            if (layers[clbLayers.SelectedIndex] is MapLayer)
            {
                SaveFileDialog sfDialog = new SaveFileDialog();
                sfDialog.Filter = "Map Layer Data (*.mldt)|*.mldt";
                sfDialog.CheckPathExists = true;
                sfDialog.OverwritePrompt = true;
                sfDialog.ValidateNames = true;

                DialogResult result = sfDialog.ShowDialog();

                if (result != DialogResult.OK)
                    return;

                MapLayerData data = new MapLayerData(
                    clbLayers.SelectedItem.ToString(),
                    ((MapLayer)layers[clbLayers.SelectedIndex]).Width,
                    ((MapLayer)layers[clbLayers.SelectedIndex]).Height);

                for (int y = 0; y < ((MapLayer)layers[clbLayers.SelectedIndex]).Height; y++)
                {
                    for (int x = 0; x < ((MapLayer)layers[clbLayers.SelectedIndex]).Width; x++)
                    {
                        data.SetTile(
                            x,
                            y,
                            ((MapLayer)layers[clbLayers.SelectedIndex]).GetTile(x, y).TileIndex,
                            ((MapLayer)layers[clbLayers.SelectedIndex]).GetTile(x, y).Tileset);
                    }
                }

                try
                {
                    XnaSerializer.Serialize<MapLayerData>(sfDialog.FileName, data);
                }
                catch (Exception exc)
                {
                    MessageBox.Show(exc.Message, "Error saving map layer data");
                }
            }
        }