private bool CreateSpecialTile(out Tile toAdd) { toAdd = new SpecialTile(int.Parse(tsLblSelX.Text), int.Parse(tsLblSelY.Text)); if (cmbSpecialType.SelectedIndex < 0 || cmbWarpAnim.SelectedIndex < 0 || lvTiles2.SelectedIndices.Count == 0) { return(false); } SpecialTileSpec type = (SpecialTileSpec)cmbSpecialType.SelectedIndex; object[] paramList; if (type == SpecialTileSpec.WARP) { int outID, outX, outY; WarpAnim add = (WarpAnim)cmbWarpAnim.SelectedIndex; if (!int.TryParse(txtDestWarpX.Text, out outX) || !int.TryParse(txtDestWarpY.Text, out outY) || !int.TryParse(txtDestWarpMap.Text, out outID)) { MessageBox.Show("Error: please enter valid values for X, Y, and Dest"); return(false); } paramList = new object[4]; paramList[0] = outID; paramList[1] = outX; paramList[2] = outY; paramList[3] = add; } else { paramList = null; } (toAdd as SpecialTile).SetType(type, paramList); (toAdd as SpecialTile).Graphic = lvTiles2.SelectedIndices[0]; return(true); }
private void cmbSpecialType_SelectedIndexChanged(object sender, EventArgs e) { if (!m_fileOpen) { grpWarpPlacement.Enabled = false; return; } if (cmbSpecialType.SelectedItem == null) { return; } SpecialTileSpec t = (SpecialTileSpec)Enum.Parse(typeof(SpecialTileSpec), cmbSpecialType.SelectedItem.ToString()); switch (t) { case SpecialTileSpec.WARP: grpWarpPlacement.Enabled = true; break; default: grpWarpPlacement.Enabled = false; break; } }
/// <summary> /// Format - None/Wall/Jump: null; Grass/Water: spawn_id; Warp: dest_warp_id, dest_x, dest_y, warpanim; /// </summary> /// <param name="type">Type to set the special tyle as</param> /// <param name="list">See format in summary</param> public void SetType(SpecialTileSpec type, params object[] list) { //updates stored values when type == Type switch (type) { case SpecialTileSpec.NONE: case SpecialTileSpec.WALL: case SpecialTileSpec.JUMP: if (list != null) { throw new ArgumentException("Invalid parameters for this TileType"); } Type = type; d_map = d_x = d_y = s_id = -1; break; case SpecialTileSpec.GRASS: case SpecialTileSpec.WATER: case SpecialTileSpec.CAVE: if (list == null || list.Length != 1 || !(list[0].GetType() == typeof(int))) { throw new ArgumentException("Invalid parameters for this TileType"); } Type = type; d_map = d_x = d_y = -1; s_id = (int)list[0]; break; case SpecialTileSpec.WARP: //TODO: add in WarpAnim if (list == null || list.Length != 4 || list[0].GetType() != typeof(int) || list[1].GetType() != typeof(int) || list[2].GetType() != typeof(int) || list[3].GetType() != typeof(WarpAnim)) { throw new ArgumentException("Invalid parameters for this TileType"); } Type = type; s_id = -1; d_map = (int)list[0]; d_x = (int)list[1]; d_y = (int)list[2]; d_anim = (WarpAnim)list[3]; break; case SpecialTileSpec.NUM_VALS: default: throw new InvalidOperationException("TileType must be a valid value."); } }
private void FillTileSpecial(Tile tileToFill, Tile fillTile) { SpecialTile destTile = tileToFill as SpecialTile, sourceTile = fillTile as SpecialTile; if (destTile.Type == sourceTile.Type) { return; } SpecialTileSpec graphicToMatch = destTile.Type; Stack <Tile> tileStack = new Stack <Tile>(); tileStack.Push(tileToFill); while (tileStack.Count != 0) { SpecialTile currentTile = tileStack.Pop() as SpecialTile; if (currentTile.Type == graphicToMatch) { currentTile.CopyTypeFrom(sourceTile); if (currentTile.X > 0) { tileStack.Push(m_openMap.GetTile(currentTile.X - 1, currentTile.Y, LAYERS.Special)); } if (currentTile.Y > 0) { tileStack.Push(m_openMap.GetTile(currentTile.X, currentTile.Y - 1, LAYERS.Special)); } if (currentTile.X < m_openMap.Width - 1) { tileStack.Push(m_openMap.GetTile(currentTile.X + 1, currentTile.Y, LAYERS.Special)); } if (currentTile.Y < m_openMap.Height - 1) { tileStack.Push(m_openMap.GetTile(currentTile.X, currentTile.Y + 1, LAYERS.Special)); } } } }
public bool LoadFromStream(Stream s) { isLoaded = false; byte[] all; using (var memoryStream = new MemoryStream()) { s.CopyTo(memoryStream); all = memoryStream.ToArray(); } CRC32 crc = new CRC32(); uint crcVal = crc.Check(all, 0, (uint)all.Length - 4); //crc everything except the value of the crc s.Seek(-sizeof(int), SeekOrigin.End); //last four bytes (int) is CRC value uint fileVal = (uint)s.ReadInt(); if (crcVal != fileVal) { return(isLoaded); } s.Seek(0, SeekOrigin.Begin); if (s.ReadInt() != Const.MAGIC_NUMBER) { return(isLoaded); } spawns = new List <Spawn>(); int loadedLayers = 0; while (s.Position < s.Length - 4) { switch ((MapField)s.ReadByte()) { case MapField.MapInfo: w = s.ReadInt(); h = s.ReadInt(); Type = (MapType)s.ReadInt(); mapname = s.ReadString(); Warp = s.ReadInt(); PlayerSpawn = new Microsoft.Xna.Framework.Point(s.ReadInt(), s.ReadInt()); int numLayers = s.ReadInt(); if (numLayers != this.layers.Length) { throw new Exception("Invalid number of layers!"); } break; case MapField.MapLayer: int numTiles = s.ReadInt(); var newLayer = layers[loadedLayers] = new SortedList <string, Tile>(numTiles); for (int i = 0; i < numTiles; i++) { Tile toAdd = null; LAYERS layer = LAYERS.Graphic; switch ((TileType)s.ReadInt()) { case TileType.Animated: toAdd = new AnimatedTile(s.ReadInt(), s.ReadInt(), s.ReadInt()); layer = LAYERS.Graphic; break; case TileType.Graphic: toAdd = new GraphicTile(s.ReadInt(), s.ReadInt(), s.ReadInt()); break; case TileType.Special: layer = LAYERS.Special; SpecialTile st = new SpecialTile(s.ReadInt(), s.ReadInt()); SpecialTileSpec tt = (SpecialTileSpec)s.ReadInt(); st.Graphic = s.ReadInt(); if (tt == SpecialTileSpec.WALL) { st.Density = (float)s.ReadDouble(); } object[] param = null; switch (tt) { case SpecialTileSpec.WARP: param = new object[] { s.ReadInt(), s.ReadInt(), s.ReadInt(), (WarpAnim)s.ReadInt() }; break; } st.SetType(tt, param); toAdd = st; break; } if (toAdd != null) { AddTile(toAdd.X, toAdd.Y, layer, toAdd); } } layers[loadedLayers++] = newLayer; break; case MapField.SpawnInfo: Spawn sp = new Spawn(s.ReadInt(), s.ReadString()); int numPairs = s.ReadInt(); for (int i = 0; i < numPairs; i++) { sp.AddSpawnPair(s.ReadInt(), s.ReadInt()); } break; } } // Make sure we don't have any null layers (they cause problems later) for (int i = 0; i < layers.Length; i++) { if (layers[i] == null) { layers[i] = new SortedList <string, Tile>(); } } fileName = ""; isLoaded = true; isSaved = true; return(isLoaded); }