/// <summary> /// Handles the <see cref="DialogTileset"/> form, checks all the directories and builds the <see cref="Tileset"/> object. /// </summary> public void NewTileset() { using (var dialog = new DialogTileset()) { var result = dialog.ShowDialog(); if (result != DialogResult.OK) return; var name = dialog.TilesetName; var path = dialog.FilePath; int width = dialog.TileWidth; int height = dialog.TileHeight; if (CheckTileset(name)) { MessageBox.Show(@"A tileset with this name already exists.", @"New Tileset"); return; } var index = 1; while (true) { var exit = true; foreach (var tmp in Tilesets) { if (tmp.ID == index) exit = false; } if (exit) break; index++; } string newName = name + Path.GetExtension(path); string newPath = Path.Combine(ProjectManager.Instance.Project.TilesetPath, newName); File.Copy(path, newPath); path = newPath; var tileset = new Tileset(index, name, path, width, height); Tilesets.Add(tileset); SaveTileset(index); if (TilesetAdded != null) TilesetAdded.Invoke(this, new TilesetAddedEventArgs(tileset)); SelectTileset(index); } }
/// <summary> /// Handles the <see cref="DialogTileset"/> form and updates the <see cref="Tileset"/> object with the new data. /// </summary> public void EditTileset(int id) { var tileset = GetTileset(id); if (tileset == null) return; using (var dialog = new DialogTileset(tileset.Name, tileset.Image, tileset.TileWidth, tileset.TileHeight)) { var result = dialog.ShowDialog(); if (result != DialogResult.OK) return; var name = dialog.TilesetName; var path = dialog.FilePath; int tileWidth = dialog.TileWidth; int tileHeight = dialog.TileHeight; if (tileset.Name.ToLower() != name.ToLower()) { if (CheckTileset(name)) { MessageBox.Show(@"A tileset with this name already exists.", @"Edit Tileset"); return; } } UpdateTileset(id, name, path, tileWidth, tileHeight); } }