Exemplo n.º 1
0
        /// <summary>
        ///     Raises the OnTileChanged event.
        /// </summary>
        /// <param name="tileRef">A reference to the new tile.</param>
        /// <param name="oldTile">The old tile that got replaced.</param>
        public void RaiseOnTileChanged(TileRef tileRef, Tile oldTile)
        {
            if (SuppressOnTileChanged)
            {
                return;
            }

            TileChanged?.Invoke(this, new TileChangedEventArgs(tileRef, oldTile));

            if (_netManager.IsClient)
            {
                return;
            }

            var message = _netManager.CreateNetMessage <MsgMap>();

            message.MessageType = MapMessage.TurfUpdate;
            message.SingleTurf  = new MsgMap.Turf
            {
                X    = tileRef.X,
                Y    = tileRef.Y,
                Tile = (uint)tileRef.Tile
            };
            message.GridIndex = tileRef.LocalPos.GridID;

            _netManager.ServerSendToAll(message);
        }
Exemplo n.º 2
0
 public TrackerTile this[CoordPair C] {
     get { return(tiles[C.Y, C.X]); }
     set {
         var old = tiles[C.Y, C.X];
         tiles[C.Y, C.X] = value;
         TileChanged?.Invoke(this, new TileChangedEventArgs(C, old));
     }
 }
Exemplo n.º 3
0
 public TrackerTile this[int x, int y] {
     get { return(tiles[y, x]); }
     set {
         var old = tiles[y, x];
         tiles[y, x] = value;
         TileChanged?.Invoke(this, new TileChangedEventArgs(new CoordPair(x, y), old));
     }
 }
Exemplo n.º 4
0
 public PrimaryTile this[CoordPair cp] {
     get { return(tiles[cp.Y, cp.X]); }
     set {
         var old = tiles[cp.Y, cp.X];
         tiles[cp.Y, cp.X] = value;
         TileChanged?.Invoke(this, new TileChangedEventArgs(cp, old));
     }
 }
Exemplo n.º 5
0
        public void ChangeData(byte[] data, int offset)
        {
            Array.Copy(data, 0, Data, offset, data.Length);

            int startTile = offset / 32;
            int length    = data.Length / 32;

            TileChanged?.Invoke(this, new TileChangedEventArgs(CountTo(startTile, length)));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Data)));
        }
Exemplo n.º 6
0
        private void SetTile(MapLocation location, MapTile tile, bool throwOnOutOfBounds)
        {
            int index = GetTileIndex(location);

            if (!CheckTileIndex(index, throwOnOutOfBounds))
            {
                return;
            }

            var oldValue = _tiles[index];

            _tiles[index] = tile;
            TileChanged?.Invoke(location, oldValue, tile);
        }
        /// <summary>
        /// On mouse down
        /// </summary>
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            Focus();

            if (Image == null || _tiles.Count <= 0 || TileID < 0)
            {
                return;
            }

            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            Point     origin = GetOrigin();
            Rectangle rect   = new Rectangle(origin.X * ImageScale + AutoScrollPosition.X, origin.Y * ImageScale + AutoScrollPosition.Y, Image.Width * ImageScale, Image.Height * ImageScale);

            if (rect.Contains(e.Location) == false)
            {
                return;
            }

            int       x         = (e.Location.X - rect.X) / ImageScale / SnapSize.Width * SnapSize.Width;
            int       y         = (e.Location.Y - rect.Y) / ImageScale / SnapSize.Height * SnapSize.Height;
            Rectangle selection = new Rectangle(new Point(x, y), SnapSize);
            int       cols      = Image.Width / SnapSize.Width;
            int       col       = selection.X / SnapSize.Width;
            int       row       = selection.Y / SnapSize.Height;
            int       index     = (row * cols) + col;

            if (index >= _tiles.Count)
            {
                return;
            }

            _tiles[index].TileID = TileID;
            TileChanged?.Invoke();
        }
Exemplo n.º 8
0
 /// <summary>
 /// Raising a tile change event.
 /// </summary>
 /// <param name="tile"></param>
 private void OnTileChanged(Tile tile) => TileChanged?.Invoke(this, new TileChangedEventArgs(tile.X, tile.Y, tile.Type));
Exemplo n.º 9
0
 protected void RaiseTileChanged(TileXy oldTile, TileXy newTile)
 {
     TileChanged?.Invoke(this, new TileChangedEventArgs(oldTile, newTile));
 }