/// <summary> /// Convert a string that represents a list of tiles to the list of tiles. /// </summary> /// <param name="builder">the string received from the communication methods</param> /// <returns>the list of tiles</returns> public static List<Tile> TileCollectionFromString(string builder) { string[] tileBuilders = builder.Split(groupDelim); List<Tile> tiles = new List<Tile>(); foreach(string tileBuilder in tileBuilders) { Tile tile = new Tile(tileBuilder); if (tile.height > 0) tiles.Add(tile); } return tiles; }
/// <summary> /// Add a tile to this map. /// </summary> /// <param name="ToAdd">The tile to add</param> /// <returns>true if the tile is added; false on error</returns> public bool Add(Tile ToAdd) { if(ToAdd.PosX > 40000000 || // 40,000 km. Roughly the circumference of the Earth. ToAdd.PosX < 0 || // -1 = 40000000 ToAdd.PosY > 40000000 || ToAdd.PosY < 0 || ToAdd.PosZ < -50000 || // thickness of the crust ToAdd.PosZ > 8000) // atmosphere too thin to support life { return false; } int tileHeight = ToAdd.TileHeight; while (tileHeight > 1) { tileHeight--; if (GetTileExact(ToAdd.PosX, ToAdd.PosY, ToAdd.PosZ - tileHeight) != null) { return false; } } if(GetTileOverlap(ToAdd.PosX, ToAdd.PosY, ToAdd.PosZ) != null) { return false; } if(!Tiles.ContainsKey(ToAdd.PosX)) { Tiles.Add(ToAdd.PosX, new Dictionary<int, Dictionary<int, Tile>>()); } if(!Tiles[ToAdd.PosX].ContainsKey(ToAdd.PosY)) { Tiles[ToAdd.PosX].Add(ToAdd.PosY, new Dictionary<int, Tile>()); } if(!Tiles[ToAdd.PosX][ToAdd.PosY].ContainsKey(ToAdd.PosZ)) { Tiles[ToAdd.PosX][ToAdd.PosY].Add(ToAdd.PosZ, ToAdd); } else { Tiles[ToAdd.PosX][ToAdd.PosY][ToAdd.PosZ] = null; } foreach (Creature observer in PresentCharacters) { if (!MapDeltas.ContainsKey(observer)) { MapDeltas.Add(observer, new MapDelta()); } MapDeltas[observer].AddedTiles.Add(ToAdd); } return true; }
void Z_ValueChanged(object sender, EventArgs e) { if (editPane.SettingNewTile) return; if (editPane.shownTile == null) return; Tile replacement = new Tile(editPane.shownTile.CurrentTileSet, editPane.shownTile.Slope, editPane.shownTile.TileHeight, editPane.shownTile.PosX, editPane.shownTile.PosY, (int)editPane.Z.Value); if (SwapTiles(editPane.shownTile, replacement)) { editPane.SetTile(replacement); } }
void TileHeight_SelectedValueChanged(object sender, EventArgs e) { if (editPane.SettingNewTile) return; if (editPane.shownTile == null) return; int height = 0; int.TryParse(editPane.TileHeight.SelectedItem.ToString(), out height); if(height > 0) { Tile replacement = new Tile(editPane.shownTile.CurrentTileSet, editPane.shownTile.Slope, height, editPane.shownTile.PosX, editPane.shownTile.PosY, editPane.shownTile.PosZ); if (SwapTiles(editPane.shownTile, replacement)) { editPane.SetTile(replacement); } } }
void TileDirection_SelectedValueChanged(object sender, EventArgs e) { if (editPane.SettingNewTile) return; if (editPane.shownTile == null) return; Direction dir; if(Enum.TryParse<Direction>(editPane.TileDirection.SelectedItem.ToString(), out dir)) { Tile replacement = new Tile(editPane.shownTile.CurrentTileSet, dir, editPane.shownTile.TileHeight, editPane.shownTile.PosX, editPane.shownTile.PosY, editPane.shownTile.PosZ); if (SwapTiles(editPane.shownTile, replacement)) { editPane.SetTile(replacement); } } }
bool SwapTiles(Tile toRemove, Tile toAdd) { if(!currentMap.Remove(toRemove)) { return false; } if(!currentMap.Add(toAdd)) { currentMap.Add(toRemove); return false; } toRemove.Delete(currentMap.Name); toAdd.Save(currentMap.Name); scene.Remove(toRemove); scene.Add(toAdd); return true; }
void Set_SelectedValueChanged(object sender, EventArgs e) { if (editPane.SettingNewTile) return; if (editPane.shownTile == null) return; uint nTile = 0; foreach(TileSet ts in TileSet.GetSets()) { if(editPane.Set.SelectedItem.ToString() == ts.Name) { nTile = ts.Id; break; } } Tile replacement = new Tile(nTile, editPane.shownTile.Slope, editPane.shownTile.TileHeight, editPane.shownTile.PosX, editPane.shownTile.PosY, editPane.shownTile.PosZ); if (SwapTiles(editPane.shownTile, replacement)) { editPane.SetTile(replacement); } }
void AddTile_Click(object sender, EventArgs e) { Tile newTile = null; if (editPane.shownTile == null) { newTile = new Tile(0, Direction.DirectionLess, 1, 20000000, 20000000, 0); } else { newTile = new Tile(editPane.shownTile.CurrentTileSet, editPane.shownTile.Slope, editPane.shownTile.TileHeight, editPane.shownTile.PosX, editPane.shownTile.PosY, editPane.shownTile.PosZ + editPane.shownTile.TileHeight); } if (currentMap.Add(newTile)) { newTile.Save(currentMap.Name); scene.Add(newTile); editPane.SetTile(newTile); } else { MessageBox.Show(String.Format("Could not add the tile at ({0},{1},{2})", editPane.shownTile.PosX, editPane.shownTile.PosY, editPane.shownTile.PosZ)); } }
static void playScene_DM_KeyDown(object sender, KeyEventArgs e) { #region Add a Tile if (e.KeyCode == Keys.NumPad0) { // Num pad 0 used to add a tile if (_currentTile == null) return; if (playScene.CollidesWithTile(_currentTile.PosX, _currentTile.PosY, _currentTile.PosZ + _currentTile.TileHeight, _currentTile.TileHeight, true, _currentTile)) return; TileChange request = new TileChange(); Tile nTile = new Tile(_currentTile.CurrentTileSet, _currentTile.Slope, _currentTile.TileHeight, _currentTile.PosX, _currentTile.PosY, _currentTile.PosZ + _currentTile.TileHeight); request.AddedTiles.Add(nTile); request.CharacterName = DrivingCharacter.CharacterName; request.AccountName = DrivingCharacter.AccountName; string resp = ServiceConsumer.ChangeTiles(request); if (!String.IsNullOrEmpty(resp)) { MapDelta delta = _handleDelta(resp); if (delta.RemovedTiles.Contains(_currentTile)) { _currentTile = null; } if (delta.AddedTiles.Count > 0) { _currentTile = delta.AddedTiles[0]; } } return; } #endregion #region Move a Tile BL else if(e.KeyCode == Keys.NumPad1) { // Num pad 1 moves tile to bottom left if (_currentTile == null) return; int targX = _currentTile.PosX; int targY = _currentTile.PosY; int targZ = _currentTile.PosZ; switch(playScene.TopDirection) { case Direction.NorthWest: targY--; break; case Direction.NorthEast: targX--; break; case Direction.SouthWest: targX++; break; case Direction.SouthEast: targY++; break; } if (playScene.CollidesWithTile(targX, targY, targZ, _currentTile.TileHeight, true, _currentTile)) return; TileChange request = new TileChange(); Tile nTile = new Tile(_currentTile.CurrentTileSet, _currentTile.Slope, _currentTile.TileHeight, targX, targY, targZ); request.AddedTiles.Add(nTile); request.RemovedTiles.Add(_currentTile); request.CharacterName = DrivingCharacter.CharacterName; request.AccountName = DrivingCharacter.AccountName; string resp = ServiceConsumer.ChangeTiles(request); if (!String.IsNullOrEmpty(resp)) { MapDelta delta = _handleDelta(resp); if (delta.RemovedTiles.Contains(_currentTile)) { _currentTile = null; } if (delta.AddedTiles.Count > 0) { _currentTile = delta.AddedTiles[0]; } } return; } #endregion #region Move a Tile B else if(e.KeyCode == Keys.NumPad2) { // Num pad 2 moves tile to bottom if (_currentTile == null) return; int targX = _currentTile.PosX; int targY = _currentTile.PosY; int targZ = _currentTile.PosZ; switch (playScene.TopDirection) { case Direction.NorthWest: targY--; targX++; break; case Direction.NorthEast: targY--; targX--; break; case Direction.SouthWest: targY++; targX++; break; case Direction.SouthEast: targY++; targX--; break; } if (playScene.CollidesWithTile(targX, targY, targZ, _currentTile.TileHeight, true, _currentTile)) return; TileChange request = new TileChange(); Tile nTile = new Tile(_currentTile.CurrentTileSet, _currentTile.Slope, _currentTile.TileHeight, targX, targY, targZ); request.AddedTiles.Add(nTile); request.RemovedTiles.Add(_currentTile); request.CharacterName = DrivingCharacter.CharacterName; request.AccountName = DrivingCharacter.AccountName; string resp = ServiceConsumer.ChangeTiles(request); if (!String.IsNullOrEmpty(resp)) { MapDelta delta = _handleDelta(resp); if (delta.RemovedTiles.Contains(_currentTile)) { _currentTile = null; } if (delta.AddedTiles.Count > 0) { _currentTile = delta.AddedTiles[0]; } } return; } #endregion #region Move a Tile BR else if(e.KeyCode == Keys.NumPad3) { // Num pad 3 moves tile to bottom right if (_currentTile == null) return; int targX = _currentTile.PosX; int targY = _currentTile.PosY; int targZ = _currentTile.PosZ; switch (playScene.TopDirection) { case Direction.NorthWest: targX++; break; case Direction.NorthEast: targY--; break; case Direction.SouthWest: targY++; break; case Direction.SouthEast: targX--; break; } if (playScene.CollidesWithTile(targX, targY, targZ, _currentTile.TileHeight, true, _currentTile)) return; TileChange request = new TileChange(); Tile nTile = new Tile(_currentTile.CurrentTileSet, _currentTile.Slope, _currentTile.TileHeight, targX, targY, targZ); request.AddedTiles.Add(nTile); request.RemovedTiles.Add(_currentTile); request.CharacterName = DrivingCharacter.CharacterName; request.AccountName = DrivingCharacter.AccountName; string resp = ServiceConsumer.ChangeTiles(request); if (!String.IsNullOrEmpty(resp)) { MapDelta delta = _handleDelta(resp); if (delta.RemovedTiles.Contains(_currentTile)) { _currentTile = null; } if (delta.AddedTiles.Count > 0) { _currentTile = delta.AddedTiles[0]; } } return; } #endregion #region Move a Tile L else if(e.KeyCode == Keys.NumPad4) { // Num pad 4 moves tile to left if (_currentTile == null) return; int targX = _currentTile.PosX; int targY = _currentTile.PosY; int targZ = _currentTile.PosZ; switch (playScene.TopDirection) { case Direction.NorthWest: targX--; targY--; break; case Direction.NorthEast: targX--; targY++; break; case Direction.SouthWest: targX++; targY--; break; case Direction.SouthEast: targX--; targY++; break; } if (playScene.CollidesWithTile(targX, targY, targZ, _currentTile.TileHeight, true, _currentTile)) return; TileChange request = new TileChange(); Tile nTile = new Tile(_currentTile.CurrentTileSet, _currentTile.Slope, _currentTile.TileHeight, targX, targY, targZ); request.AddedTiles.Add(nTile); request.RemovedTiles.Add(_currentTile); request.CharacterName = DrivingCharacter.CharacterName; request.AccountName = DrivingCharacter.AccountName; string resp = ServiceConsumer.ChangeTiles(request); if (!String.IsNullOrEmpty(resp)) { MapDelta delta = _handleDelta(resp); if (delta.RemovedTiles.Contains(_currentTile)) { _currentTile = null; } if (delta.AddedTiles.Count > 0) { _currentTile = delta.AddedTiles[0]; } } return; } #endregion #region Rotate a Tile else if(e.KeyCode == Keys.NumPad5) { // Num pad 5 rotates the tile if (_currentTile == null) return; Direction slopeDirection = _currentTile.Slope; switch(_currentTile.Slope) { case Direction.DirectionLess: slopeDirection = Direction.North; break; case Direction.North: slopeDirection = Direction.NorthEast; break; case Direction.NorthEast: slopeDirection = Direction.East; break; case Direction.East: slopeDirection = Direction.SouthEast; break; case Direction.SouthEast: slopeDirection = Direction.South; break; case Direction.South: slopeDirection = Direction.SouthWest; break; case Direction.SouthWest: slopeDirection = Direction.West; break; case Direction.West: slopeDirection = Direction.NorthWest; break; case Direction.NorthWest: slopeDirection = Direction.DirectionLess; break; } TileChange request = new TileChange(); Tile nTile = new Tile(_currentTile.CurrentTileSet, slopeDirection, _currentTile.TileHeight, _currentTile.PosX, _currentTile.PosY, _currentTile.PosZ); request.AddedTiles.Add(nTile); request.RemovedTiles.Add(_currentTile); request.CharacterName = DrivingCharacter.CharacterName; request.AccountName = DrivingCharacter.AccountName; string resp = ServiceConsumer.ChangeTiles(request); if (!String.IsNullOrEmpty(resp)) { MapDelta delta = _handleDelta(resp); if (delta.RemovedTiles.Contains(_currentTile)) { _currentTile = null; } if (delta.AddedTiles.Count > 0) { _currentTile = delta.AddedTiles[0]; } } return; } #endregion #region Move a Tile R else if(e.KeyCode == Keys.NumPad6) { // Num pad 6 moves tile to right if (_currentTile == null) return; int targX = _currentTile.PosX; int targY = _currentTile.PosY; int targZ = _currentTile.PosZ; switch (playScene.TopDirection) { case Direction.NorthWest: targX++; targY++; break; case Direction.NorthEast: targX++; targY--; break; case Direction.SouthWest: targX--; targY++; break; case Direction.SouthEast: targX--; targY--; break; } if (playScene.CollidesWithTile(targX, targY, targZ, _currentTile.TileHeight, true, _currentTile)) return; TileChange request = new TileChange(); Tile nTile = new Tile(_currentTile.CurrentTileSet, _currentTile.Slope, _currentTile.TileHeight, targX, targY, targZ); request.AddedTiles.Add(nTile); request.RemovedTiles.Add(_currentTile); request.CharacterName = DrivingCharacter.CharacterName; request.AccountName = DrivingCharacter.AccountName; string resp = ServiceConsumer.ChangeTiles(request); if (!String.IsNullOrEmpty(resp)) { MapDelta delta = _handleDelta(resp); if(delta.RemovedTiles.Contains(_currentTile)) { _currentTile = null; } if (delta.AddedTiles.Count > 0) { _currentTile = delta.AddedTiles[0]; } } return; } #endregion #region Move a Tile TL else if(e.KeyCode == Keys.NumPad7) { // Num pad 7 moves tile to top left if (_currentTile == null) return; int targX = _currentTile.PosX; int targY = _currentTile.PosY; int targZ = _currentTile.PosZ; switch (playScene.TopDirection) { case Direction.NorthWest: targX--; break; case Direction.NorthEast: targY++; break; case Direction.SouthWest: targY--; break; case Direction.SouthEast: targX++; break; } if (playScene.CollidesWithTile(targX, targY, targZ, _currentTile.TileHeight, true, _currentTile)) return; TileChange request = new TileChange(); Tile nTile = new Tile(_currentTile.CurrentTileSet, _currentTile.Slope, _currentTile.TileHeight, targX, targY, targZ); request.AddedTiles.Add(nTile); request.RemovedTiles.Add(_currentTile); request.CharacterName = DrivingCharacter.CharacterName; request.AccountName = DrivingCharacter.AccountName; string resp = ServiceConsumer.ChangeTiles(request); if (!String.IsNullOrEmpty(resp)) { MapDelta delta = _handleDelta(resp); if (delta.RemovedTiles.Contains(_currentTile)) { _currentTile = null; } if (delta.AddedTiles.Count > 0) { _currentTile = delta.AddedTiles[0]; } } return; } #endregion #region Move a Tile T else if(e.KeyCode == Keys.NumPad8) { // Num pad 8 moves tile to top if (_currentTile == null) return; int targX = _currentTile.PosX; int targY = _currentTile.PosY; int targZ = _currentTile.PosZ; switch (playScene.TopDirection) { case Direction.NorthWest: targX--; targY++; break; case Direction.NorthEast: targX++; targY++; break; case Direction.SouthWest: targX--; targY--; break; case Direction.SouthEast: targX++; targY--; break; } if (playScene.CollidesWithTile(targX, targY, targZ, _currentTile.TileHeight, true, _currentTile)) return; TileChange request = new TileChange(); Tile nTile = new Tile(_currentTile.CurrentTileSet, _currentTile.Slope, _currentTile.TileHeight, targX, targY, targZ); request.AddedTiles.Add(nTile); request.RemovedTiles.Add(_currentTile); request.CharacterName = DrivingCharacter.CharacterName; request.AccountName = DrivingCharacter.AccountName; string resp = ServiceConsumer.ChangeTiles(request); if (!String.IsNullOrEmpty(resp)) { MapDelta delta = _handleDelta(resp); if (delta.RemovedTiles.Contains(_currentTile)) { _currentTile = null; } if (delta.AddedTiles.Count > 0) { _currentTile = delta.AddedTiles[0]; } } return; } #endregion #region Move a Tile TR else if(e.KeyCode == Keys.NumPad9) { // Num pad 9 moves tile to top right if (_currentTile == null) return; int targX = _currentTile.PosX; int targY = _currentTile.PosY; int targZ = _currentTile.PosZ; switch (playScene.TopDirection) { case Direction.NorthWest: targY++; break; case Direction.NorthEast: targX++; break; case Direction.SouthWest: targX--; break; case Direction.SouthEast: targY--; break; } if (playScene.CollidesWithTile(targX, targY, targZ, _currentTile.TileHeight, true, _currentTile)) return; TileChange request = new TileChange(); Tile nTile = new Tile(_currentTile.CurrentTileSet, _currentTile.Slope, _currentTile.TileHeight, targX, targY, targZ); request.AddedTiles.Add(nTile); request.RemovedTiles.Add(_currentTile); request.CharacterName = DrivingCharacter.CharacterName; request.AccountName = DrivingCharacter.AccountName; string resp = ServiceConsumer.ChangeTiles(request); if (!String.IsNullOrEmpty(resp)) { MapDelta delta = _handleDelta(resp); if (delta.RemovedTiles.Contains(_currentTile)) { _currentTile = null; } if (delta.AddedTiles.Count > 0) { _currentTile = delta.AddedTiles[0]; } } return; } #endregion #region Change a Tileset else if(e.KeyCode == Keys.Enter) { // Enter key changes the tileset if (_currentTile == null) return; uint tileSet = _currentTile.CurrentTileSet; if (tileSet >= TileSet._library.Count - 1) tileSet = 0; else tileSet++; TileChange request = new TileChange(); Tile nTile = new Tile(tileSet, _currentTile.Slope, _currentTile.TileHeight, _currentTile.PosX, _currentTile.PosY, _currentTile.PosZ); request.AddedTiles.Add(nTile); request.RemovedTiles.Add(_currentTile); request.CharacterName = DrivingCharacter.CharacterName; request.AccountName = DrivingCharacter.AccountName; string resp = ServiceConsumer.ChangeTiles(request); if (!String.IsNullOrEmpty(resp)) { MapDelta delta = _handleDelta(resp); if (delta.RemovedTiles.Contains(_currentTile)) { _currentTile = null; } if (delta.AddedTiles.Count > 0) { _currentTile = delta.AddedTiles[0]; } } return; } #endregion #region Remove a Tile else if(e.KeyCode == Keys.Decimal) { // Num pad . deletes the tile if (_currentTile == null) return; TileChange request = new TileChange(); request.RemovedTiles.Add(_currentTile); request.CharacterName = DrivingCharacter.CharacterName; request.AccountName = DrivingCharacter.AccountName; string resp = ServiceConsumer.ChangeTiles(request); if (!String.IsNullOrEmpty(resp)) { MapDelta delta = _handleDelta(resp); if (delta.RemovedTiles.Contains(_currentTile)) { _currentTile = null; } if (delta.AddedTiles.Count > 0) { _currentTile = delta.AddedTiles[0]; } } return; } #endregion #region Shorten a Tile else if(e.KeyCode == Keys.Divide) { // Divide key shortens the tile if (_currentTile == null) return; if (_currentTile.TileHeight <= 1) return; TileChange request = new TileChange(); Tile nTile = new Tile(_currentTile.CurrentTileSet, _currentTile.Slope, _currentTile.TileHeight - 1, _currentTile.PosX, _currentTile.PosY, _currentTile.PosZ - 1); request.AddedTiles.Add(nTile); request.RemovedTiles.Add(_currentTile); request.CharacterName = DrivingCharacter.CharacterName; request.AccountName = DrivingCharacter.AccountName; string resp = ServiceConsumer.ChangeTiles(request); if (!String.IsNullOrEmpty(resp)) { MapDelta delta = _handleDelta(resp); if (delta.RemovedTiles.Contains(_currentTile)) { _currentTile = null; } if (delta.AddedTiles.Count > 0) { _currentTile = delta.AddedTiles[0]; } } return; } #endregion #region Heighten a Tile else if(e.KeyCode == Keys.Multiply) { // Multiply key heightens the tile if (_currentTile == null) return; if (playScene.CollidesWithTile(_currentTile.PosX, _currentTile.PosY, _currentTile.PosZ + 1, _currentTile.TileHeight + 1, true, _currentTile)) return; if (_currentTile.TileHeight >= 4) return; TileChange request = new TileChange(); Tile nTile = new Tile(_currentTile.CurrentTileSet, _currentTile.Slope, _currentTile.TileHeight + 1, _currentTile.PosX, _currentTile.PosY, _currentTile.PosZ + 1); request.AddedTiles.Add(nTile); request.RemovedTiles.Add(_currentTile); request.CharacterName = DrivingCharacter.CharacterName; request.AccountName = DrivingCharacter.AccountName; string resp = ServiceConsumer.ChangeTiles(request); if (!String.IsNullOrEmpty(resp)) { MapDelta delta = _handleDelta(resp); if (delta.RemovedTiles.Contains(_currentTile)) { _currentTile = null; } if (delta.AddedTiles.Count > 0) { _currentTile = delta.AddedTiles[0]; } } return; } #endregion #region Lower a Tile else if(e.KeyCode == Keys.Subtract) { // Subtract key decreases the tile's elevation if (_currentTile == null) return; if (playScene.CollidesWithTile(_currentTile.PosX, _currentTile.PosY, _currentTile.PosZ - 1, _currentTile.TileHeight, true, _currentTile)) return; TileChange request = new TileChange(); Tile nTile = new Tile(_currentTile.CurrentTileSet, _currentTile.Slope, _currentTile.TileHeight, _currentTile.PosX, _currentTile.PosY, _currentTile.PosZ - 1); request.AddedTiles.Add(nTile); request.RemovedTiles.Add(_currentTile); request.CharacterName = DrivingCharacter.CharacterName; request.AccountName = DrivingCharacter.AccountName; string resp = ServiceConsumer.ChangeTiles(request); if (!String.IsNullOrEmpty(resp)) { MapDelta delta = _handleDelta(resp); if (delta.RemovedTiles.Contains(_currentTile)) { _currentTile = null; } if (delta.AddedTiles.Count > 0) { _currentTile = delta.AddedTiles[0]; } } return; } #endregion #region Raise a Tile else if(e.KeyCode == Keys.Add) { // Add key increases the tile's elevation if (_currentTile == null) return; if (playScene.CollidesWithTile(_currentTile.PosX, _currentTile.PosY, _currentTile.PosZ + 1, _currentTile.TileHeight, true, _currentTile)) return; TileChange request = new TileChange(); Tile nTile = new Tile(_currentTile.CurrentTileSet, _currentTile.Slope, _currentTile.TileHeight, _currentTile.PosX, _currentTile.PosY, _currentTile.PosZ + 1); request.AddedTiles.Add(nTile); request.RemovedTiles.Add(_currentTile); request.CharacterName = DrivingCharacter.CharacterName; request.AccountName = DrivingCharacter.AccountName; string resp = ServiceConsumer.ChangeTiles(request); if (!String.IsNullOrEmpty(resp)) { MapDelta delta = _handleDelta(resp); if (delta.RemovedTiles.Contains(_currentTile)) { _currentTile = null; } if (delta.AddedTiles.Count > 0) { _currentTile = delta.AddedTiles[0]; } } return; } #endregion }
static void playScene_DM_TileSelected(object Sender, TileSelectEventArgs e) { _currentTile = e.tile; }
/// <summary> /// Removes tiles from those which are to be drawn in the scene. /// /// If many tiles are to be removed, they should be removed as a list to reduce redrawing. /// </summary> /// <param name="tile">A tile to remove</param> public void Remove(Tile toRemove) { List<Tile> removing = new List<Tile>(); foreach (Tile currentTile in drawableTiles) { if (currentTile.PosX == toRemove.PosX && currentTile.PosY == toRemove.PosY && currentTile.PosZ == toRemove.PosZ) { removing.Add(currentTile); } } foreach (Tile t in removing) { drawableTiles.Remove(t); if (drawableImages.Contains(t.CachedImage)) { drawableImages.Remove(t.CachedImage); } } this.Refresh(); }
public bool CollidesWithTile(int x, int y, int z, int height, bool isTile, Tile exceptionTile) { if (isTile) { foreach (Tile t in drawableTiles) { if (t != exceptionTile && t.PosX == x && t.PosY == y && t.PosZ > z - height && t.PosZ <= z + t.TileHeight) { return true; } } } else { foreach(Tile t in drawableTiles) { if (t != exceptionTile && t.PosX == x && t.PosY == y && t.PosZ <= z && t.PosZ > z + height + t.TileHeight) { return true; } } } return false; }
/// <summary> /// Adds tiles to those which are to be drawn in the scene. /// /// If many tiles are to be added, they should be added as a list to reduce redrawing. /// </summary> /// <param name="tile">A tile to add</param> public void Add(Tile tile) { drawableTiles.Add(tile); TileImage image = tile.Image(ViewCenterX, ViewCenterY, ViewCenterZ, topDirection, this); image.TileSelected += image_TileSelected; image.SourceTile = tile; drawableImages.Add(image); drawableImages.Sort(); this.Refresh(); }
public void SetTile(Tile tile) { SettingNewTile = true; shownTile = tile; if (tile != null) { X.Value = tile.PosX; Y.Value = tile.PosY; Z.Value = tile.PosZ; Set.Text = TileSet.GetSet(shownTile.CurrentTileSet).Name; TileHeight.Text = shownTile.TileHeight.ToString(); TileDirection.Text = shownTile.Slope.ToString(); } else { Z.Value = 0; Y.Value = 0; X.Value = 0; Set.Text = ""; TileHeight.Text = ""; TileDirection.Text = ""; } SettingNewTile = false; }
public TileEditPane(Tile tile) { this.BackColor = Color.Black; shownTile = tile; Label labX = new Label(); labX.BackColor = Color.Black; labX.ForeColor = Color.White; labX.Text = "X: "; labX.Size = labX.PreferredSize; labX.Location = new Point(padding, padding); this.Controls.Add(labX); X = new NumericUpDown(); X.Minimum = Int32.MinValue; X.Maximum = Int32.MaxValue; X.BackColor = Color.Black; X.ForeColor = Color.White; X.Height = X.PreferredHeight; X.Width = Math.Max(0, this.ClientRectangle.Width - labX.Width - (padding * 3)); X.Location = new Point(labX.Location.X + labX.Width + padding, labX.Location.Y); this.Controls.Add(X); Label labY = new Label(); labY.BackColor = Color.Black; labY.ForeColor = Color.White; labY.Text = "Y: "; labY.Size = labY.PreferredSize; labY.Location = new Point(padding, labX.Location.Y + labX.Height + padding); this.Controls.Add(labY); Y = new NumericUpDown(); Y.Minimum = Int32.MinValue; Y.Maximum = Int32.MaxValue; Y.BackColor = Color.Black; Y.ForeColor = Color.White; Y.Height = Y.PreferredHeight; Y.Width = Math.Max(0, this.ClientRectangle.Width - labY.Width - (padding * 3)); Y.Location = new Point(labY.Location.X + labY.Width + padding, labY.Location.Y); this.Controls.Add(Y); Label labZ = new Label(); labZ.BackColor = Color.Black; labZ.ForeColor = Color.White; labZ.Text = "Z: "; labZ.Size = labZ.PreferredSize; labZ.Location = new Point(padding, labY.Location.Y + labY.Height + padding); this.Controls.Add(labZ); Z = new NumericUpDown(); Z.Minimum = Int32.MinValue; Z.Maximum = Int32.MaxValue; Z.BackColor = Color.Black; Z.ForeColor = Color.White; Z.Height = Z.PreferredHeight; Z.Width = Math.Max(0, this.ClientRectangle.Width - labZ.Width - (padding * 3)); Z.Location = new Point(labZ.Location.X + labZ.Width + padding, labZ.Location.Y); this.Controls.Add(Z); Label tileSetLabel = new Label(); tileSetLabel.BackColor = Color.Black; tileSetLabel.ForeColor = Color.White; tileSetLabel.Text = "Tileset: "; tileSetLabel.Size = tileSetLabel.PreferredSize; tileSetLabel.Location = new Point(padding, labZ.Location.Y + labZ.Height + (padding * 2)); this.Controls.Add(tileSetLabel); Set = new ComboBox(); Set.BackColor = Color.Black; Set.ForeColor = Color.White; Set.AutoCompleteMode = AutoCompleteMode.Suggest; Set.AutoCompleteSource = AutoCompleteSource.CustomSource; Set.AutoCompleteCustomSource = new AutoCompleteStringCollection(); foreach (TileSet ts in TileSet.GetSets()) { Set.Items.Add(ts.Name); } Set.Height = Set.PreferredHeight; Set.Width = Math.Max(0, this.ClientRectangle.Width - tileSetLabel.Width - (padding * 3)); Set.Location = new Point(tileSetLabel.Location.X + tileSetLabel.Width + padding, tileSetLabel.Location.Y); this.Controls.Add(Set); Label tileHeightLabel = new Label(); tileHeightLabel.BackColor = Color.Black; tileHeightLabel.ForeColor = Color.White; tileHeightLabel.Text = "Height: "; tileHeightLabel.Size = tileHeightLabel.PreferredSize; tileHeightLabel.Location = new Point(padding, Set.Location.Y + Set.Height + (padding * 2)); this.Controls.Add(tileHeightLabel); TileHeight = new ComboBox(); TileHeight.BackColor = Color.Black; TileHeight.ForeColor = Color.White; TileHeight.AutoCompleteMode = AutoCompleteMode.Suggest; TileHeight.AutoCompleteSource = AutoCompleteSource.CustomSource; TileHeight.AutoCompleteCustomSource = new AutoCompleteStringCollection(); TileHeight.Items.Add("1"); TileHeight.Items.Add("2"); TileHeight.Items.Add("3"); TileHeight.Items.Add("4"); TileHeight.Height = TileHeight.PreferredHeight; TileHeight.Width = Math.Max(0, this.ClientRectangle.Width - tileHeightLabel.Width - (padding * 3)); TileHeight.Location = new Point(tileHeightLabel.Location.X + tileHeightLabel.Width + padding, tileHeightLabel.Location.Y); this.Controls.Add(TileHeight); Label tileDirectionLabel = new Label(); tileDirectionLabel.BackColor = Color.Black; tileDirectionLabel.ForeColor = Color.White; tileDirectionLabel.Text = "Height: "; tileDirectionLabel.Size = tileDirectionLabel.PreferredSize; tileDirectionLabel.Location = new Point(padding, TileHeight.Location.Y + TileHeight.Height + (padding * 2)); this.Controls.Add(tileDirectionLabel); TileDirection = new ComboBox(); TileDirection.BackColor = Color.Black; TileDirection.ForeColor = Color.White; TileDirection.AutoCompleteMode = AutoCompleteMode.Suggest; TileDirection.AutoCompleteSource = AutoCompleteSource.CustomSource; TileDirection.AutoCompleteCustomSource = new AutoCompleteStringCollection(); foreach(Direction dir in Enum.GetValues(typeof(Direction))) { TileDirection.Items.Add(dir.ToString()); } TileDirection.Height = TileDirection.PreferredHeight; TileDirection.Width = Math.Max(0, this.ClientRectangle.Width - tileDirectionLabel.Width - (padding * 3)); TileDirection.Location = new Point(tileDirectionLabel.Location.X + tileDirectionLabel.Width + padding, tileDirectionLabel.Location.Y); this.Controls.Add(TileDirection); AddTile = new Button(); AddTile.BackColor = Color.Black; AddTile.ForeColor = Color.White; AddTile.Text = "Add Tile"; AddTile.Height = AddTile.PreferredSize.Height; AddTile.Width = this.ClientRectangle.Width - (padding * 2); AddTile.Location = new Point(padding, TileDirection.Location.Y + TileDirection.Height + padding); this.Controls.Add(AddTile); RemoveTile = new Button(); RemoveTile.BackColor = Color.Black; RemoveTile.ForeColor = Color.White; RemoveTile.Text = "Remove Tile"; RemoveTile.Height = RemoveTile.PreferredSize.Height; RemoveTile.Width = this.ClientRectangle.Width - (padding * 2); RemoveTile.Location = new Point(padding, AddTile.Location.Y + AddTile.Height + padding); this.Controls.Add(RemoveTile); RefreshDisplay(); }
/// <summary> /// Remove a tile from this map. /// </summary> /// <param name="ToRemove">The tile to remove</param> /// <returns>True on success; false if the tile is not found</returns> public bool Remove(Tile ToRemove) { if(!Tiles.ContainsKey(ToRemove.PosX)) { return false; } if(!Tiles[ToRemove.PosX].ContainsKey(ToRemove.PosY)) { return false; } if(!Tiles[ToRemove.PosX][ToRemove.PosY].ContainsKey(ToRemove.PosZ)) { return false; } Tiles[ToRemove.PosX][ToRemove.PosY].Remove(ToRemove.PosZ); if(Tiles[ToRemove.PosX][ToRemove.PosY].Count == 0) { Tiles[ToRemove.PosX].Remove(ToRemove.PosY); } if(Tiles[ToRemove.PosX].Count == 0) { Tiles.Remove(ToRemove.PosX); } foreach (Character observer in PresentCharacters) { if (!MapDeltas.ContainsKey(observer)) { MapDeltas.Add(observer, new MapDelta()); } MapDeltas[observer].RemovedTiles.Add(ToRemove); } return true; }