Inheritance: IComparable
        public MultiComponentList ConvertToSDK()
        {
            int count = 0;

            MTileList[][] tiles = new MTileList[Width][];
            for (int x = 0; x < Width; ++x)
            {
                tiles[x] = new MTileList[Height];
                for (int y = 0; y < Height; ++y)
                {
                    tiles[x][y] = new MTileList();
                }
            }
            for (int i = 0; i < Tiles.Count; ++i)
            {
                MultiTile tile = Tiles[i];
                if (tile.isVirtualFloor)
                {
                    continue;
                }
                tiles[tile.X][tile.Y].Add((ushort)(tile.ID), (sbyte)tile.Z, tile.Invisible ? (TileFlag)0 : (TileFlag)1);
                ++count;
            }
            return(new MultiComponentList(tiles, count, Width, Height));
        }
        private void RecalcMinMax(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();
            }
        }
 /// <summary>
 /// Removes specific <see cref="MultiTile"/>
 /// </summary>
 public void TileRemove(MultiTile tile)
 {
     if (Width == 0 || Height == 0)
     {
         return;
     }
     AddToUndoList("Remove Tile");
     if (tile != null)
     {
         Tiles.Remove(tile);
         Modified = true;
         RecalcMinMax(tile);
     }
 }
        /// <summary>
        /// Gets <see cref="MultiTile"/> from given Pixel Location
        /// </summary>
        public MultiTile GetSelected(Point mouseLoc, int maxheight, bool drawFloor)
        {
            if (Width == 0 || Height == 0)
            {
                return(null);
            }
            MultiTile selected = null;

            if (mouseLoc != Point.Empty)
            {
                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))))
                    {
                        //Check for transparent part
                        Color p = bmp.GetPixel(mouseLoc.X - px, mouseLoc.Y - py);
                        if (!((p.R == 0) && (p.G == 0) && (p.B == 0)))
                        {
                            selected = tile;
                            break;
                        }
                    }
                }
            }
            return(selected);
        }
        /// <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();
            RecalcMinMax(tile);
        }
Esempio n. 6
0
 public MultiEditor()
 {
     SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint, true);
     InitializeComponent();
     refMarkerMulti = this;
     MouseLoc = new Point();
     MovingLoc = new Point();
     m_DrawTile = new MultiTile();
     Selectedpanel.Visible = false;
     FloatingPreviewPanel.Visible = false;
     FloatingPreviewPanel.Tag = -1;
     BTN_Select.Checked = true;
     pictureBoxDrawTiles.MouseWheel += new MouseEventHandler(pictureBoxDrawTiles_OnMouseWheel);
     pictureBoxMulti.ContextMenu = null;
     ForceRefresh = true;
 }
 /// <summary>
 /// Alters Z level for given <see cref="MultiTile"/>
 /// </summary>
 public void TileZMod(MultiTile tile, int modz)
 {
     AddToUndoList("Modify Z");
     tile.Z += modz;
     if (tile.Z > 127)
     {
         tile.Z = 127;
     }
     if (tile.Z < -128)
     {
         tile.Z = -128;
     }
     CalcSolver(tile.X, tile.Y);
     Tiles.Sort();
     Modified = true;
     RecalcMinMax(tile);
 }
 /// <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;
     RecalcMinMax(tile);
 }
 /// <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)
     {
         tile.X = newx;
         tile.Y = newy;
         CalcSolver(newx, newy);
         Tiles.Sort();
         Modified = true;
         RecalcMinMax(tile);
     }
 }
        /// <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;
            RecalcMinMax();
        }
        /// <summary>
        /// Gets Bitmap of Multi and sets HoverTile
        /// </summary>
        public void GetImage(Graphics gfx, int xoff, int yoff, int maxheight, Point mouseLoc, bool drawFloor, bool forcerefresh)
        {
            if (Width == 0 || Height == 0)
            {
                return;
            }

            if (Modified)
            {
                RecalcMinMax();
            }

            xMin = xMinOrg;
            xMax = xMaxOrg;
            yMin = yMinOrg;
            yMax = yMaxOrg;

            if (drawFloor)
            {
                int floorzmod = -Parent.DrawFloorZ << 2 - 44;
                if (yMin > floorzmod)
                {
                    yMin = floorzmod;
                }
                floorzmod = (Width + Height) * 22 - Parent.DrawFloorZ << 2;
                if (yMaxOrg < floorzmod)
                {
                    yMax = floorzmod;
                }
            }
            Parent.HoverTile = GetSelected(mouseLoc, maxheight, drawFloor);

            Rectangle clipBounds = Rectangle.Round(gfx.ClipBounds);

            for (int i = 0; i < Tiles.Count; ++i)
            {
                MultiTile tile = Tiles[i];
                if (!tile.isVirtualFloor)
                {
                    if (tile.Z > maxheight)
                    {
                        continue;
                    }
                }
                Bitmap bmp = tile.GetBitmap();
                if (bmp == null)
                {
                    continue;
                }
                drawdestRectangle.X      = tile.Xmod;
                drawdestRectangle.Y      = tile.Ymod;
                drawdestRectangle.X     -= xMin + xoff;
                drawdestRectangle.Y     -= yMin + yoff;
                drawdestRectangle.Width  = bmp.Width;
                drawdestRectangle.Height = bmp.Height;

                if (!clipBounds.IntersectsWith(drawdestRectangle))
                {
                    continue;
                }
                if (tile.isVirtualFloor)
                {
                    if (drawFloor)
                    {
                        gfx.DrawImageUnscaled(bmp, drawdestRectangle);
                    }
                }
                else
                {
                    if ((Parent.HoverTile != null) && (Parent.HoverTile == tile))
                    {
                        gfx.DrawImage(bmp, drawdestRectangle, 0, 0, drawdestRectangle.Width, drawdestRectangle.Height, GraphicsUnit.Pixel, MultiTile.HoverColor);
                    }
                    else if ((Parent.SelectedTile != null) && (Parent.SelectedTile == tile))
                    {
                        gfx.DrawImage(bmp, drawdestRectangle, 0, 0, drawdestRectangle.Width, drawdestRectangle.Height, GraphicsUnit.Pixel, MultiTile.SelectedColor);
                    }
                    else if (tile.Transparent)
                    {
                        gfx.DrawImage(bmp, drawdestRectangle, 0, 0, drawdestRectangle.Width, drawdestRectangle.Height, GraphicsUnit.Pixel, MultiTile.TransColor);
                    }
                    else if ((Parent.ShowWalkables) && (tile.Walkable))
                    {
                        gfx.DrawImage(bmp, drawdestRectangle, 0, 0, drawdestRectangle.Width, drawdestRectangle.Height, GraphicsUnit.Pixel, MultiTile.StandableColor);
                    }
                    else if ((Parent.ShowDoubleSurface) && (tile.DoubleSurface))
                    {
                        gfx.DrawImage(bmp, drawdestRectangle, 0, 0, drawdestRectangle.Width, drawdestRectangle.Height, GraphicsUnit.Pixel, MultiTile.StandableColor);
                    }
                    else
                    {
                        gfx.DrawImageUnscaled(bmp, drawdestRectangle);
                    }
                }
            }
        }
 /// <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();
     RecalcMinMax(tile);
 }
 /// <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)
     {
         tile.X = newx;
         tile.Y = newy;
         CalcSolver(newx, newy);
         Tiles.Sort();
         Modified = true;
         RecalcMinMax(tile);
     }
 }
 /// <summary>
 /// Removes specific <see cref="MultiTile"/>
 /// </summary>
 public void TileRemove(MultiTile tile)
 {
     if (Width == 0 || Height == 0)
         return;
     AddToUndoList("Remove Tile");
     if (tile != null)
     {
         Tiles.Remove(tile);
         Modified = true;
         RecalcMinMax(tile);
     }
 }
        private void RecalcMinMax(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();
        }
 /// <summary>
 /// Alters Z level for given <see cref="MultiTile"/>
 /// </summary>
 public void TileZMod(MultiTile tile, int modz)
 {
     AddToUndoList("Modify Z");
     tile.Z += modz;
     if (tile.Z > 127)
         tile.Z = 127;
     if (tile.Z < -128)
         tile.Z = -128;
     CalcSolver(tile.X, tile.Y);
     Tiles.Sort();
     Modified = true;
     RecalcMinMax(tile);
 }
        // Public Methods (3) 

        public int CompareTo(object x)
        {
            if (x == null)
            {
                return(1);
            }

            if (!(x is MultiTile))
            {
                throw new ArgumentNullException();
            }

            MultiTile a = (MultiTile)x;

            if (X > a.X)
            {
                return(1);
            }
            else if (X < a.X)
            {
                return(-1);
            }
            if (Y > a.Y)
            {
                return(1);
            }
            else if (Y < a.Y)
            {
                return(-1);
            }

            if (!a.isVirtualFloor && !isVirtualFloor)
            {
                ItemData ourData   = TileData.ItemTable[ID];
                ItemData theirData = TileData.ItemTable[a.ID];

                int ourTreshold = 0;
                if (ourData.Height > 0)
                {
                    ++ourTreshold;
                }
                if (!ourData.Background)
                {
                    ++ourTreshold;
                }
                int ourZ          = Z;
                int theirTreshold = 0;
                if (theirData.Height > 0)
                {
                    ++theirTreshold;
                }
                if (!theirData.Background)
                {
                    ++theirTreshold;
                }
                int theirZ = a.Z;

                ourZ   += ourTreshold;
                theirZ += theirTreshold;
                int res = ourZ - theirZ;
                if (res == 0)
                {
                    res = ourTreshold - theirTreshold;
                }
                if (res == 0)
                {
                    res = Solver - a.Solver;
                }
                return(res);
            }
            else
            {
                if (Z > a.Z)
                {
                    return(1);
                }
                else if (a.Z > Z)
                {
                    return(-1);
                }
                if (a.isVirtualFloor)
                {
                    return(1);
                }
                else if (isVirtualFloor)
                {
                    return(-1);
                }
            }

            return(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;
     RecalcMinMax(tile);
 }