protected void AddLayer(MapLayer layer) { TreeNode node = new TreeNode(layer.LayerName); node.Tag = layer; layersNode.Nodes.Add(node); }
private void newMapToolStripMenuItem_Click(object sender, EventArgs e) { using (NewMapDialog dlg = new NewMapDialog()) { DialogResult result; result = dlg.ShowDialog(); if (result != DialogResult.OK) { return; } int tw = (dlg.MapWidth + WorldMap.tileSize - 1) / WorldMap.tileSize; int th = (dlg.MapHeight + WorldMap.tileSize - 1) / WorldMap.tileSize; imageGrid.WidthCells = tw; imageGrid.HeightCells = th; imageGrid.Enabled = true; int tx, tz; if ((tw <= WorldMap.tilesPerSection) && (th <= WorldMap.tilesPerSection)) { // if the world fits in a single section, then center it in section 0,0 tx = (WorldMap.tilesPerSection - tw) / 2; tz = (WorldMap.tilesPerSection - th) / 2; } else { // if the world doesn't fit in a single section, then center on the origin tx = -tw / 2; tz = -th / 2; } CoordXZ minTile = new CoordXZ(tx, tz, WorldMap.tileSize); CoordXZ maxTile = new CoordXZ(tx + tw - 1, tz + th - 1, WorldMap.tileSize); worldMap = new WorldMap(dlg.MapName, minTile, maxTile, dlg.MinTerrainHeight, dlg.MaxTerrainHeight, dlg.DefaultTerrainHeight); currentViewLayer = worldMap.GetLayer("heightfield"); gridOffset = minTile; InitTreeView(); } }
public void SetViewLayer(string layerName) { currentViewLayer = worldMap.GetLayer(layerName); imageGrid.ClearCells(); UpdateVisible(); }
public void LoadMap() { using (OpenFileDialog dlg = new OpenFileDialog()) { dlg.Title = "Load Map"; dlg.DefaultExt = "mwm"; dlg.Filter = "Multiverse World Map files (*.mwm)|*.mwm|All files (*.*)|*.*"; dlg.RestoreDirectory = true; if (dlg.ShowDialog() == DialogResult.OK) { worldMap = new WorldMap(dlg.FileName); currentViewLayer = worldMap.GetLayer("heightfield"); gridOffset = worldMap.MinTile; imageGrid.WidthCells = worldMap.MaxTile.x - worldMap.MinTile.x + 1; imageGrid.HeightCells = worldMap.MaxTile.z - worldMap.MinTile.z + 1; imageGrid.Enabled = true; InitTreeView(); } } }
public void FromXml(string mapFilename) { XmlReaderSettings xmlSettings = new XmlReaderSettings(); XmlReader r = XmlReader.Create(mapFilename); // read until we find the start of the world description while (r.Read()) { // look for the start of the map description if (r.NodeType == XmlNodeType.Element) { if (r.Name == "WorldMap") { break; } } } // parse attributes for (int i = 0; i < r.AttributeCount; i++) { r.MoveToAttribute(i); // set the field in this object based on the element we just read switch (r.Name) { case "WorldName": worldName = r.Value; break; case "MinTileX": minTile.x = int.Parse(r.Value); break; case "MinTileZ": minTile.z = int.Parse(r.Value); break; case "MaxTileX": maxTile.x = int.Parse(r.Value); break; case "MaxTileZ": maxTile.z = int.Parse(r.Value); break; case "MinHeight": minHeight = float.Parse(r.Value); break; case "MaxHeight": maxHeight = float.Parse(r.Value); break; } } r.MoveToElement(); //Moves the reader back to the element node. // now parse the sub-elements while (r.Read()) { // look for the start of an element if (r.NodeType == XmlNodeType.Element) { // parse that element // save the name of the element string elementName = r.Name; switch (elementName) { case "Zone": MapZone zone = new MapZone(this, r); zones.Add(zone.Name, zone); break; case "Layer": MapLayer layer = MapLayer.MapLayerFactory(this, r); layers.Add(layer.LayerName, layer); layerAndWorldOWP.Add(layer); break; case "Property": properties.ParseProperty(r); break; } } else if (r.NodeType == XmlNodeType.EndElement) { break; } } }
public WorldMap(string filename) { // create map sections sections = new Dictionary<CoordXZ, MapSection>(); zones = new Dictionary<string, MapZone>(); layers = new Dictionary<string, MapLayer>(); emptyOWP = new List<IObjectWithProperties>(); layerAndWorldOWP = new List<IObjectWithProperties>(); properties = new MapProperties(this); worldPath = System.IO.Path.GetDirectoryName(filename); FromXml(filename); // add worldmap to the end of the list layerAndWorldOWP.Add(this); // create heightfield layer heightFieldLayer = layers["heightfield"]; alpha0Layer = layers["alpha0"]; alpha1Layer = layers["alpha1"]; Debug.Assert(heightFieldLayer != null); Debug.Assert(alpha0Layer != null); Debug.Assert(alpha1Layer != null); }
protected void InitLayers(float defaultHeight) { // create heightfield layer heightFieldLayer = new ValueMapLayer16(this, "heightfield", defaultMetersPerTile, 1, minHeight, maxHeight - minHeight, defaultHeight); layers.Add("heightfield", heightFieldLayer); layerAndWorldOWP.Add(heightFieldLayer); // create alpha0 layer alpha0Layer = new ColorMapLayer(this, "alpha0", defaultMetersPerTile, 1, new Axiom.Core.ColorEx(1, 0, 0, 0)); layers.Add("alpha0", alpha0Layer); layerAndWorldOWP.Add(alpha0Layer); alpha0Layer.Properties.NewProperty("TerrainTexture0", "Alpha Layer 0 Terrain Textures", "Terrain Texture 0", typeof(string), "terrain0.dds"); alpha0Layer.Properties.NewProperty("TerrainTexture1", "Alpha Layer 0 Terrain Textures", "Terrain Texture 1", typeof(string), "terrain1.dds"); alpha0Layer.Properties.NewProperty("TerrainTexture2", "Alpha Layer 0 Terrain Textures", "Terrain Texture 2", typeof(string), "terrain2.dds"); alpha0Layer.Properties.NewProperty("TerrainTexture3", "Alpha Layer 0 Terrain Textures", "Terrain Texture 3", typeof(string), "terrain3.dds"); // create alpha1 layer alpha1Layer = new ColorMapLayer(this, "alpha1", defaultMetersPerTile, 1, new Axiom.Core.ColorEx(0, 0, 0, 0)); layers.Add("alpha1", alpha1Layer); layerAndWorldOWP.Add(alpha1Layer); alpha1Layer.Properties.NewProperty("TerrainTexture4", "Alpha Layer 1 Terrain Textures", "Terrain Texture 4", typeof(string), "terrain4.dds"); alpha1Layer.Properties.NewProperty("TerrainTexture5", "Alpha Layer 1 Terrain Textures", "Terrain Texture 5", typeof(string), "terrain5.dds"); alpha1Layer.Properties.NewProperty("TerrainTexture6", "Alpha Layer 1 Terrain Textures", "Terrain Texture 6", typeof(string), "terrain6.dds"); alpha1Layer.Properties.NewProperty("TerrainTexture7", "Alpha Layer 1 Terrain Textures", "Terrain Texture 7", typeof(string), "terrain7.dds"); // add world to end of list layerAndWorldOWP.Add(this); }