/// <summary> /// Initializes a new instance of the <see cref="EditorTileMap"/> class. /// </summary> /// <param name="map"><see cref="TileMap"/> object.</param> public EditorTileMap(TileMap map) { UndoRedoArea = new UndoRedoArea(map.Name) { MaxHistorySize = 100 }; BuildFromTileMap(map); MapManager.Instance.MapChanged += MapChanged; LayerAdded += EditorMap_LayerAdded; PropertyChanged += EditorMap_PropertyChanged; HookEvents(); }
/// <summary> /// Handles the <see cref="DialogMap"/> form, checks all the directories and builds the <see cref="TileMap"/> object. /// </summary> public void NewMap() { using (var dialog = new DialogMap()) { var result = dialog.ShowDialog(); if (result != DialogResult.OK) return; var name = dialog.MapName; var width = dialog.MapWidth; var height = dialog.MapHeight; var tileWidth = dialog.TileWidth; var tileHeight = dialog.TileHeight; if (CheckMap(name)) { MessageBox.Show(@"A map with this name already exists.", @"New Map"); return; } var index = 1; while (true) { var exit = true; foreach (var tmp in Maps) { if (tmp.ID == index) exit = false; } if (exit) break; index++; } var map = new TileMap(index, name, width, height, tileWidth, tileHeight); map.Layers.Add(new TileLayer("Default", 100, true)); var editormap = new EditorTileMap(map); Maps.Add(editormap); Console.WriteLine(@"Map {0} created.", editormap.Name); SaveMap(index); if (MapAdded != null) MapAdded.Invoke(this, new MapAddedEventArgs(editormap)); SelectMap(index); } }
private void BuildFromTileMap(TileMap map) { using (UndoRedoManager.Start("Initializing map " + map.Name)) { _building = true; _dontCache = true; ID = map.ID; Name = map.Name; Width = map.Width; Height = map.Height; TileWidth = map.TileWidth; TileHeight = map.TileHeight; ConcreteWidth = Width; ConcreteHeight = Height; ConcreteLayers = map.Layers; RevertToConcrete(); _building = false; _dontCache = false; UndoRedoManager.Commit(); } }
/// <summary> /// Converts the 2D Tile array in to an enumerable Tile List. /// Saves the <see cref="EditorTileMap"/> object to XML. /// </summary> /// <param name="path">Path to save to.</param> public void SaveToXml(string path) { var map = new TileMap { ID = ID, Name = Name, Width = ConcreteWidth, Height = ConcreteHeight, TileWidth = TileWidth, TileHeight = TileHeight, Layers = ConcreteLayers }; map.SaveToXml(path); UnsavedChanges = false; }