Exemple #1
0
        public UOTexture16 GetLandTexture(uint g)
        {
            if (!_landDictionary.TryGetValue(g, out UOTexture16 texture) || texture.IsDisposed)
            {
                const int SIZE   = 44;
                ushort[]  pixels = ReadLandArt((ushort)g);
                texture = new UOTexture16(SIZE, SIZE);
                texture.PushData(pixels);
                _landDictionary.Add(g, texture);
            }

            //else
            //    texture.Ticks = Engine.Ticks + 3000;
            return(texture);
        }
Exemple #2
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 UOTexture16[] SplitTexture16(UOTexture original, int[,] partXYplusWidthHeight)
        {
            if (partXYplusWidthHeight.GetLength(0) == 0 || partXYplusWidthHeight.GetLength(1) < 4)
            {
                return(null);
            }

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

            ushort[] originalData = new ushort[pwidth * pheight];
            original.GetData(originalData, 0, pwidth * pheight);

            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];
                UOTexture16 part     = new UOTexture16(width, height);
                ushort[]    partData = new ushort[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);
        }
Exemple #3
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];

            ushort[] 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 UOTexture16(Width, Height);
            _mapTexture.PushData(data);
        }
Exemple #4
0
        private void CreateMiniMapTexture(bool force = false)
        {
            if (_gumpTexture == null || _gumpTexture.IsDisposed)
            {
                return;
            }

            ushort lastX = World.Player.Position.X;
            ushort lastY = World.Player.Position.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.MapBlockIndex;
            int mapBlockHeight = FileManager.Map.MapBlocksSize[World.MapIndex, 1];

            ushort[] data = FileManager.Gumps.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 = FileManager.Map.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;
                            uint color  = mb.Cells[x, y].Graphic;
                            bool island = mb.Cells[x, y].IsLand;

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

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

                                for (; obj != null; obj = obj.Left)
                                {
                                    if (obj is Multi)
                                    {
                                        color  = obj.Graphic;
                                        island = false;

                                        break;
                                    }
                                }
                            }

                            if (!island)
                            {
                                color += 0x4000;
                            }
                            int tableSize = 2;
                            color = (uint)(0x8000 | FileManager.Hues.GetRadarColorData((int)color));
                            CreatePixels(data, (int)color, gx, gy, Width, Height, table, tableSize);
                        }
                    }
                }
            }

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