Ejemplo n.º 1
0
        /// <summary>
        /// Handles the <see cref="DialogTerrain"/> form, checks all the directories and builds the <see cref="Terrain"/> object.
        /// </summary>
        public void NewTerrain()
        {
            using (var dialog = new DialogTerrain())
            {
                var result = dialog.ShowDialog();
                if (result != DialogResult.OK) return;

                var name = dialog.TerrainName;
                var type = dialog.TerrainType;
                var tileset = dialog.TilesetID;
                var x = dialog.SelectionX;
                var y = dialog.SelectionY;
                var width = dialog.SelectionWidth;
                var height = dialog.SelectionHeight;

                if (CheckTerrain(name))
                {
                    MessageBox.Show(@"Terrain with this name already exists.", @"New Terrain");
                    return;
                }

                var index = 1;
                while (true)
                {
                    var exit = true;
                    foreach (var tmp in Terrain)
                    {
                        if (tmp.ID == index)
                            exit = false;
                    }

                    if (exit)
                        break;

                    index++;
                }

                var terrain = new TerrainTile(index, name, type, tileset, x, y, width, height);

                Terrain.Add(terrain);

                SaveTerrain(index);

                if (TerrainAdded != null)
                    TerrainAdded.Invoke(this, new TerrainAddedEventArgs(terrain));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles the <see cref="DialogTerrain"/> form and updates the <see cref="Terrain"/> object with the new data.
        /// </summary>
        public void EditTerrain(int id)
        {
            var terrain = GetTerrain(id);

            if (terrain == null) return;

            using (var dialog = new DialogTerrain(terrain.Name, terrain.Type, terrain.Tileset, terrain.X, terrain.Y, terrain.Width, terrain.Height))
            {
                var result = dialog.ShowDialog();
                if (result != DialogResult.OK) return;

                var name = dialog.TerrainName;
                var type = dialog.TerrainType;
                var tileset = dialog.TilesetID;
                var x = dialog.SelectionX;
                var y = dialog.SelectionY;
                var width = dialog.SelectionWidth;
                var height = dialog.SelectionHeight;

                if (terrain.Name.ToLower() != name.ToLower())
                {
                    if (CheckTerrain(name))
                    {
                        MessageBox.Show(@"A terrain tile with this name already exists.", @"Edit Terrain");
                        return;
                    }
                }

                UpdateTerrain(id, name, type, tileset, x, y, width, height);
            }
        }