Esempio n. 1
0
        /// <summary>
        /// Adds an <see cref="MultiTile"/> to specific location
        /// </summary>
        public void TileAdd(int x, int y, int z, ushort id)
        {
            if (x > Width || y > Height)
            {
                return;
            }

            AddToUndoList("Add Tile");
            MultiTile tile = new MultiTile(id, x, y, z, 1);

            Tiles.Add(tile);
            CalcSolver(x, y);
            _modified = true;
            Tiles.Sort();
            RecalculateMinMax(tile);
        }
Esempio n. 2
0
        /// <summary>
        /// Removes specific <see cref="MultiTile"/>
        /// </summary>
        public void TileRemove(MultiTile tile)
        {
            if (Width == 0 || Height == 0)
            {
                return;
            }

            AddToUndoList("Remove Tile");

            if (tile == null)
            {
                return;
            }

            Tiles.Remove(tile);
            _modified = true;
            RecalculateMinMax(tile);
        }
Esempio n. 3
0
        /// <summary>
        /// Sets Z value of given <see cref="MultiTile"/>
        /// </summary>
        public void TileZSet(MultiTile tile, int setZ)
        {
            AddToUndoList("Set Z");
            tile.Z = setZ;
            if (tile.Z > 127)
            {
                tile.Z = 127;
            }

            if (tile.Z < -128)
            {
                tile.Z = -128;
            }

            CalcSolver(tile.X, tile.Y);
            Tiles.Sort();
            _modified = true;
            RecalculateMinMax(tile);
        }
Esempio n. 4
0
        /// <summary>
        /// Moves given <see cref="MultiTile"/>
        /// </summary>
        public void TileMove(MultiTile tile, int newX, int newY)
        {
            if (Width == 0 || Height == 0)
            {
                return;
            }

            AddToUndoList("Move Tile");

            if (tile == null)
            {
                return;
            }

            tile.X = newX;
            tile.Y = newY;
            CalcSolver(newX, newY);
            Tiles.Sort();
            _modified = true;
            RecalculateMinMax(tile);
        }
Esempio n. 5
0
        /// <summary>
        /// Resizes Multi size
        /// </summary>
        public void Resize(int width, int height)
        {
            AddToUndoList("Resize");
            if (Width > width || Height > height)
            {
                for (int i = Tiles.Count - 1; i >= 0; --i)
                {
                    MultiTile tile = Tiles[i];
                    if (tile.X >= width)
                    {
                        Tiles.RemoveAt(i);
                    }
                    else if (tile.Y >= height)
                    {
                        Tiles.RemoveAt(i);
                    }
                }
            }

            if (Width < width || Height < height)
            {
                for (int x = 0; x < width; ++x)
                {
                    for (int y = 0; y < height; ++y)
                    {
                        if (x < Width && y < Height)
                        {
                            continue;
                        }

                        Tiles.Add(new FloorTile(x, y, _parent.DrawFloorZ));
                    }
                }
            }

            Width     = width;
            Height    = height;
            _modified = true;
            RecalculateMinMax();
        }
Esempio n. 6
0
        private void RecalculateMinMax(MultiTile tile)
        {
            if (tile.IsVirtualFloor)
            {
                return;
            }

            if (tile.GetBitmap() == null)
            {
                return;
            }

            int px = tile.XMod - GapXMod;
            int py = tile.YMod - GapYMod;

            if (px < XMin)
            {
                XMin = px;
            }

            if (py < YMin)
            {
                YMin = py;
            }

            px += tile.GetBitmap().Width;
            py += tile.GetBitmap().Height;

            if (px > XMax)
            {
                XMax = px;
            }

            if (py > YMax)
            {
                YMax = py;
            }

            if (tile.Z > ZMax)
            {
                ZMax = tile.Z;
            }

            if (tile.Z < ZMin)
            {
                ZMin = tile.Z;
            }

            _modified = false;

            XMinOrg = XMin;
            XMaxOrg = XMax;
            YMinOrg = YMin;
            YMaxOrg = YMax;

            if (_parent.ShowWalkables)
            {
                CalcWalkable();
            }

            if (_parent.ShowDoubleSurface)
            {
                CalcDoubleSurface();
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Gets <see cref="MultiTile"/> from given Pixel Location
        /// </summary>
        private MultiTile GetSelected(Point mouseLoc, int maxHeight, bool drawFloor)
        {
            if (Width == 0 || Height == 0)
            {
                return(null);
            }

            if (mouseLoc == Point.Empty)
            {
                return(null);
            }

            MultiTile selected = null;

            for (int i = Tiles.Count - 1; i >= 0; --i) // inverse for speedup
            {
                MultiTile tile = Tiles[i];
                if (tile.IsVirtualFloor)
                {
                    continue;
                }

                if (tile.Z > maxHeight)
                {
                    continue;
                }

                if (drawFloor && _parent.DrawFloorZ > tile.Z)
                {
                    continue;
                }

                Bitmap bmp = tile.GetBitmap();
                if (bmp == null)
                {
                    continue;
                }

                int px = tile.XMod;
                int py = tile.YMod;
                px -= XMin;
                py -= YMin;

                if (mouseLoc.X <= px || mouseLoc.X >= px + bmp.Width || mouseLoc.Y <= py || mouseLoc.Y >= py + bmp.Height)
                {
                    continue;
                }

                // Check for transparent part
                Color p = bmp.GetPixel(mouseLoc.X - px, mouseLoc.Y - py);
                if (p.R == 0 && p.G == 0 && p.B == 0)
                {
                    continue;
                }

                selected = tile;
                break;
            }

            return(selected);
        }