private void tryLoadMap(string name) { try { Map m = Map.LoadMap(name, this.pictureBoxDrawing, SetUndo, SetRedo, SetPostMode); if (m != null) { map = m; mapFileName = name; this.btnConvert.Enabled = true; setMapMenus(true); this.rdbTiles.Checked = true; } } catch (XmlMapperException exception) { ErrorBox("Error parsing the map file: " + exception.Text + ".", "Open map error"); } catch (Exception) { ErrorBox("Error opening file " + name + ".", "Open map error"); } }
private void newMapToolStripMenuItem_Click(object sender, EventArgs e) { NewMapForm form = new NewMapForm(); form.ShowDialogCenter(this); if (!form.OK) return; map = Map.NewMap(form.MapWidth, form.MapHeight, this.pictureBoxDrawing, SetUndo, SetRedo, SetPostMode); this.btnConvert.Enabled = true; setMapMenus(true); this.rdbTiles.Checked = true; mapFileName = ""; }
/// <summary> /// Load a map instance from a file. /// </summary> /// <param name="fileName">Path for the file</param> /// <param name="dbox">Drawing box for the map representation</param> /// <param name="undo">Delegate disabling and enabling the 'undo' action</param> /// <param name="redo">Delegate disabling and enabling the 'redo' action</param> /// <param name="postMode">Delegate changing edit mode on the interface</param> /// <returns></returns> public static Map LoadMap(string fileName, System.Windows.Forms.PictureBox dbox, ValueSetterDelegate undo, ValueSetterDelegate redo, ValueSetterDelegate postMode) { XmlDocument doc = new XmlDocument(); doc.Load(fileName); XmlElement d = doc.DocumentElement; if (d.Name != "tilemap") { throw new XmlMapperException("not a tiled map file"); } bool convert = !d.HasAttribute("version"); bool convert2 = convert || !d.GetAttribute("version").Equals(Config.MapVersion); XmlElement el = d.FirstChildElement("header"); if (el == null) throw new XmlMapperException("no header was found"); int width = el.GetIntAttribute("width"); int height = el.GetIntAttribute("height"); bool post = el.GetBoolAttribute("details"); Map map = new Map(width, height, dbox, undo, redo, postMode); el = d.FirstChildElement("scrollblockers"); if (el == null) throw new XmlMapperException("no scrollblockers info found"); XmlNodeList nl = el.GetElementsByTagName("scrollblocker"); for (int i = 0; i < nl.Count; i++) { XmlElement sn = nl.Item(i).TryToElement(); if (sn == null) continue; int x = sn.GetIntAttribute("x"); int y = sn.GetIntAttribute("y"); map.tiles[x, y].ScrollBlocker = map.scrollBlockers.Count; map.scrollBlockers.Add(new Pair<int, int>(x, y)); } el = d.FirstChildElement("tiles"); if (el == null) throw new XmlMapperException("no tiles info found"); nl = el.GetElementsByTagName("tile"); for (int i = 0; i < nl.Count; i++) { XmlElement sn = nl.Item(i).TryToElement(); if (sn == null) continue; int x = sn.GetIntAttribute("x"); int y = sn.GetIntAttribute("y"); int variant = sn.GetIntAttribute("variant"); bool filled = sn.TryGetBoolAttribute("filled"); if (convert) { if (variant == 0) variant = -1; else if (variant == 1) variant = 0; } if (convert2) { if (variant == -1) variant = 0; else filled = true; } bool wide = sn.GetBoolAttribute("wide"); string walls = sn.GetAttribute("walls"); Tile tile = map.tiles[x, y]; tile.Filled = filled; tile.Variant = variant; tile.Wide = wide; bool[] w = parseBools(walls); for (int j = 0; j < 4; j++) tile.SetBlock(j, w[j]); } map.post = post; map.setPostMode(post); map.FullRedraw(); return map; }
public ScrollblockersPlacer(Pair<int, int> from, Pair<int, int> to, Map map, FOMap fomap) { this.fomap = fomap; Angle = 0; Dist = 0; MaxHx = (ushort)(2 * Config.BigTileEdgeSize * map.Width); MaxHy = (ushort)(2 * Config.BigTileEdgeSize * map.Height); Hx = (ushort)((map.Width - from.First - 1) * (2 * Config.BigTileEdgeSize) + Config.BigTileEdgeSize); Hy = (ushort)(from.Second * (2 * Config.BigTileEdgeSize) + Config.BigTileEdgeSize); Tx = (ushort)((map.Width - to.First - 1) * (2 * Config.BigTileEdgeSize) + Config.BigTileEdgeSize); Ty = (ushort)(to.Second * (2 * Config.BigTileEdgeSize) + Config.BigTileEdgeSize); }
/// <summary> /// Create a new map instance and associate the form controls. /// </summary> /// <param name="width">Width of the map in tiles</param> /// <param name="height">Height of the map in tiles</param> /// <param name="dbox">Drawing box for the map representation</param> /// <param name="undo">Delegate disabling and enabling the 'undo' action</param> /// <param name="redo">Delegate disabling and enabling the 'redo' action</param> /// <param name="postMode">Delegate changing edit mode on the interface</param> /// <returns></returns> public static Map NewMap(int width, int height, System.Windows.Forms.PictureBox dbox, ValueSetterDelegate undo, ValueSetterDelegate redo, ValueSetterDelegate postMode) { Map map = new Map(width, height, dbox, undo, redo, postMode); map.setPostMode(false); map.FullRedraw(); return map; }