Ejemplo n.º 1
0
        /// <summary>
        ///     Splits a texture into an array of smaller textures of the specified size.
        /// </summary>
        /// <param name="original">The texture to be split into smaller textures</param>
        /// <param name="partXYplusWidthHeight">
        ///     We must specify here an array with size of 'parts' for the first dimension,
        ///     for each part, in the second dimension, we specify:
        ///     starting x and y, plus width and height for that specified part (4 as size in second dimension).
        /// </param>
        internal static UOTexture[] SplitTexture16(UOTexture original, int[,] partXYplusWidthHeight)
        {
            if (partXYplusWidthHeight.GetLength(0) == 0 || partXYplusWidthHeight.GetLength(1) < 4)
            {
                return(null);
            }

            UOTexture[] r       = new UOTexture[partXYplusWidthHeight.GetLength(0)];
            int         pwidth  = original.Width;  //((original.Width + 1) >> 1) << 1;
            int         pheight = original.Height; //((original.Height + 1) >> 1) << 1;

            uint[] originalData = original.Data;

            int index = 0;

            for (int p = 0; p < partXYplusWidthHeight.GetLength(0); p++)
            {
                int x      = partXYplusWidthHeight[p, 0],
                    y      = partXYplusWidthHeight[p, 1],
                    width  = partXYplusWidthHeight[p, 2],
                    height = partXYplusWidthHeight[p, 3];

                UOTexture part     = new UOTexture(width, height);
                uint[]    partData = new uint[width * height];

                for (int py = 0; py < height; py++)
                {
                    for (int px = 0; px < width; px++)
                    {
                        int partIndex = px + py * width;

                        //If a part goes outside of the source texture, then fill the overlapping part with transparent
                        if (y + py >= pheight || x + px >= pwidth)
                        {
                            partData[partIndex] = 0;
                        }
                        else
                        {
                            partData[partIndex] = originalData[x + px + (y + py) * pwidth];
                        }
                    }
                }

                part.PushData(partData);
                r[index++] = part;
            }

            return(r);
        }
Ejemplo n.º 2
0
        private void CreateMiniMapTexture(bool force = false)
        {
            if (_gumpTexture == null || _gumpTexture.IsDisposed)
            {
                return;
            }

            ushort lastX = World.Player.X;
            ushort lastY = World.Player.Y;


            if (_x != lastX || _y != lastY)
            {
                _x = lastX;
                _y = lastY;
            }
            else if (!force)
            {
                return;
            }

            if (_mapTexture != null && !_mapTexture.IsDisposed)
            {
                _mapTexture.Dispose();
            }

            int blockOffsetX = Width >> 2;
            int blockOffsetY = Height >> 2;
            int gumpCenterX  = Width >> 1;
            //int gumpCenterY = Height >> 1;

            //0xFF080808 - pixel32
            //0x8421 - pixel16
            int minBlockX = ((lastX - blockOffsetX) >> 3) - 1;
            int minBlockY = ((lastY - blockOffsetY) >> 3) - 1;
            int maxBlockX = ((lastX + blockOffsetX) >> 3) + 1;
            int maxBlockY = ((lastY + blockOffsetY) >> 3) + 1;

            if (minBlockX < 0)
            {
                minBlockX = 0;
            }

            if (minBlockY < 0)
            {
                minBlockY = 0;
            }

            int maxBlockIndex  = World.Map.BlocksCount;
            int mapBlockHeight = MapLoader.Instance.MapBlocksSize[World.MapIndex, 1];

            uint[] data = GumpsLoader.Instance.GetGumpPixels(_useLargeMap ? (uint)5011 : 5010, out _, out _);

            Point[] table = new Point[2]
            {
                new Point(0, 0), new Point(0, 1)
            };

            for (int i = minBlockX; i <= maxBlockX; i++)
            {
                int blockIndexOffset = i * mapBlockHeight;

                for (int j = minBlockY; j <= maxBlockY; j++)
                {
                    int blockIndex = blockIndexOffset + j;

                    if (blockIndex >= maxBlockIndex)
                    {
                        break;
                    }

                    RadarMapBlock?mbbv = MapLoader.Instance.GetRadarMapBlock(World.MapIndex, i, j);

                    if (!mbbv.HasValue)
                    {
                        break;
                    }

                    RadarMapBlock mb         = mbbv.Value;
                    Chunk         block      = World.Map.Chunks[blockIndex];
                    int           realBlockX = i << 3;
                    int           realBlockY = j << 3;

                    for (int x = 0; x < 8; x++)
                    {
                        int px = realBlockX + x - lastX + gumpCenterX;

                        for (int y = 0; y < 8; y++)
                        {
                            int py = realBlockY + y - lastY;
                            int gx = px - py;
                            int gy = px + py;

                            int color = mb.Cells[x, y].Graphic;

                            bool island = mb.Cells[x, y].IsLand;

                            if (block != null)
                            {
                                GameObject obj = block.Tiles[x, y];

                                while (obj?.TNext != null)
                                {
                                    obj = obj.TNext;
                                }

                                for (; obj != null; obj = obj.TPrevious)
                                {
                                    if (obj is Multi)
                                    {
                                        if (obj.Hue == 0)
                                        {
                                            color  = obj.Graphic;
                                            island = false;
                                        }
                                        else
                                        {
                                            color = obj.Hue + 0x4000;
                                        }

                                        break;
                                    }
                                }
                            }

                            if (!island)
                            {
                                color += 0x4000;
                            }

                            int tableSize = 2;

                            if (island && color > 0x4000)
                            {
                                color = HuesLoader.Instance.GetColor16
                                        (
                                    16384, (ushort)(color - 0x4000)
                                        ); //28672 is an arbitrary position in hues.mul, is the 14 position in the range
                            }
                            else
                            {
                                color = HuesLoader.Instance.GetRadarColorData(color);
                            }

                            CreatePixels(data, 0x8000 | color, gx, gy, Width, Height, table, tableSize);
                        }
                    }
                }
            }

            _mapTexture = new UOTexture(Width, Height);
            _mapTexture.PushData(data);
        }