Пример #1
0
        public void InitPalette(WorldRenderer wr)
        {
            var remap = new PlayerColorRemap(info.RemapIndex, owner.Color, info.Ramp);

            wr.AddPalette(info.BaseName + owner.InternalName, new Palette(wr.Palette(info.BasePalette).Palette, remap), info.AllowModifiers);

            var argb = (uint)Color.FromArgb(128, owner.Color.RGB).ToArgb();

            wr.AddPalette("highlight" + owner.InternalName, new Palette(Exts.MakeArray(256, i => i == 0 ? 0 : argb)), false);
        }
Пример #2
0
 public void LoadPalettes(WorldRenderer wr)
 {
     if (info.Tilesets?.Count > 0)
     {
         // If it's tileset-specific, only load it if it matches the tileset of this map
         if (info.Tilesets.Any(tileSet => string.Equals(tileSet, world.Map.Tileset, StringComparison.InvariantCultureIgnoreCase)))
         {
             wr.AddPalette(info.Name, ((IProvidesCursorPaletteInfo)info).ReadPalette(world.Map), info.AllowModifiers);
         }
     }
     else
     {
         // Else, add it as normal
         wr.AddPalette(info.Name, ((IProvidesCursorPaletteInfo)info).ReadPalette(world.Map), info.AllowModifiers);
     }
 }
Пример #3
0
        public void LoadPalettes(WorldRenderer wr)
        {
            var colors = new uint[Palette.Size];

            using (var s = Game.ModData.ModFiles.Open(info.Filename))
            {
                var lines = s.ReadAllLines().ToArray();
                if (lines[0] != "JASC-PAL")
                {
                    throw new InvalidDataException("File {0} is not a valid JASC palatte!".F(info.Filename));
                }

                for (var i = 0; i < Palette.Size; i++)
                {
                    var split = lines[i + 3].Split(' ');
                    colors[i] = (split.Count() == 4)
                                                ? (uint)Color.FromArgb(int.Parse(split[3]), int.Parse(split[0]), int.Parse(split[1]), int.Parse(split[2])).ToArgb()
                                                : (uint)Color.FromArgb(int.Parse(split[0]), int.Parse(split[1]), int.Parse(split[2])).ToArgb();
                }

                foreach (var i in info.ShadowIndex)
                {
                    colors[i] = 140u << 24;
                }
            }

            wr.AddPalette(info.Name, new ImmutablePalette(colors), info.AllowModifiers);
        }
Пример #4
0
        public void LoadPlayerPalettes(WorldRenderer wr, string playerName, Color color, bool replaceExisting)
        {
            var argb = (uint)Color.FromArgb(128, color).ToArgb();
            var pal  = new ImmutablePalette(Enumerable.Range(0, Palette.Size).Select(i => i == info.TransparentIndex ? 0 : argb));

            wr.AddPalette(info.BaseName + playerName, pal, false, replaceExisting);
        }
Пример #5
0
        public void LoadPalettes(WorldRenderer wr)
        {
            var basePalette = wr.Palette(info.BasePalette).Palette;
            var pal         = new ImmutablePalette(basePalette, new IndexedColorRemap(basePalette, info.Index, info.ReplaceIndex));

            wr.AddPalette(info.Name, pal, info.AllowModifiers);
        }
Пример #6
0
 public void LoadPalettes(WorldRenderer wr)
 {
     if (info.Tileset == null || info.Tileset.ToLowerInvariant() == world.Map.Tileset.ToLowerInvariant())
     {
         wr.AddPalette(info.Name, ((IProvidesCursorPaletteInfo)info).ReadPalette(world.Map), info.AllowModifiers);
     }
 }
Пример #7
0
 public void InitPalette(WorldRenderer wr)
 {
     if (info.Tileset == null || info.Tileset.ToLowerInvariant() == world.Map.Tileset.ToLowerInvariant())
     {
         wr.AddPalette(info.Name, new Palette(FileSystem.Open(info.Filename), info.Transparent));
     }
 }
Пример #8
0
        public void LoadPlayerPalettes(WorldRenderer wr, string playerName, HSLColor color, bool replaceExisting)
        {
            var remap = new AlphaPaletteRemap(info.Alpha, info.Premultiply);
            var pal   = new ImmutablePalette(wr.Palette(info.BasePalette + playerName).Palette, remap);

            wr.AddPalette(info.BaseName + playerName, pal, info.AllowModifiers, replaceExisting);
        }
Пример #9
0
        public void InitPalette(WorldRenderer wr)
        {
            var c = info.Type == ShroudPaletteType.Shroud ? Shroud :
                    info.Type == ShroudPaletteType.Fog ? Fog : Combined;

            wr.AddPalette(info.Name, new Palette(Exts.MakeArray(256, i => (uint)c[i % 8].ToArgb())), false);
        }
Пример #10
0
 public void LoadPalettes(WorldRenderer wr)
 {
     if (info.Tileset == null || info.Tileset.ToLowerInvariant() == world.Map.Tileset.ToLowerInvariant())
     {
         wr.AddPalette(info.Name, new ImmutablePalette(GlobalFileSystem.Open(info.Filename), info.ShadowIndex), info.AllowModifiers);
     }
 }
Пример #11
0
        public void LoadPlayerPalettes(WorldRenderer wr, string playerName, HSLColor color, bool replaceExisting)
        {
            var remap = new PlayerColorRemap(info.RemapIndex, color, info.Ramp);
            var pal   = new ImmutablePalette(wr.Palette(info.BasePalette).Palette, remap);

            wr.AddPalette(info.BaseName + playerName, pal, info.AllowModifiers, replaceExisting);
        }
Пример #12
0
        public void InitPalette(WorldRenderer wr)
        {
            var info = Rules.Info["player"].Traits.WithInterface <PlayerColorPaletteInfo>()
                       .First(p => p.BaseName == Info.PlayerPalette);

            index = info.RemapIndex;
            wr.AddPalette("colorpicker", wr.GetPalette(info.BasePalette));
        }
Пример #13
0
        public void InitPalette(WorldRenderer wr)
        {
            var paletteName = "{0}{1}".F(info.BaseName, owner.InternalName);
            var newpal      = new Palette(wr.GetPalette(info.BasePalette),
                                          new PlayerColorRemap(info.RemapIndex, owner.ColorRamp));

            wr.AddPalette(paletteName, newpal);
        }
Пример #14
0
        void ILoadsPalettes.LoadPalettes(WorldRenderer wr)
        {
            color           = colorManager.Color;
            var(_, h, s, _) = color.ToAhsv();
            var remap = new PlayerColorRemap(info.RemapIndex, h, s);

            wr.AddPalette(info.Name, new ImmutablePalette(wr.Palette(info.BasePalette).Palette, remap), info.AllowModifiers);
        }
Пример #15
0
        public void LoadPalettes(WorldRenderer wr)
        {
            var(_, h, s, _) = info.Color.ToAhsv();

            var remap = new PlayerColorRemap(info.RemapIndex, h, s);

            wr.AddPalette(info.Name, new ImmutablePalette(wr.Palette(info.Base).Palette, remap), info.AllowModifiers);
        }
Пример #16
0
        public void LoadPalettes(WorldRenderer wr)
        {
            if (info.Tileset != null && info.Tileset.ToLowerInvariant() != world.Map.Tileset.ToLowerInvariant())
            {
                return;
            }

            wr.AddPalette(info.Name, new PaletteFromPalLoader().ReadPalette(world.Map.Open(info.Filename), new int[0]), info.AllowModifiers);
        }
Пример #17
0
 public void InitPalette(WorldRenderer wr)
 {
     if (info.Tileset == null || info.Tileset.ToLowerInvariant() == world.Map.Tileset.ToLowerInvariant())
     {
         // TODO: This shouldn't rely on a base palette
         var pal = wr.GetPalette("terrain");
         wr.AddPalette(info.Name, new Palette(pal, new SingleColorRemap(Color.FromArgb(info.A, info.R, info.G, info.B))));
     }
 }
Пример #18
0
        public void LoadPalettes(WorldRenderer worldRenderer)
        {
            var colors = new uint[Palette.Size];

            colors[244] = 0xffff9e52;
            colors[245] = 0xffefb68c;
            colors[246] = 0xffffebc6;
            colors[247] = 0xffffffff;

            worldRenderer.AddPalette(info.Name, new ImmutablePalette(colors), info.AllowModifiers);
        }
Пример #19
0
        public void LoadPalettes(WorldRenderer wr)
        {
            // Enable palette only for a specific tileset
            if (info.Tileset != null && info.Tileset.ToLowerInvariant() != world.Map.Tileset.ToLowerInvariant())
            {
                return;
            }

            var c = (uint)((info.A << 24) | (info.R << 16) | (info.G << 8) | info.B);

            wr.AddPalette(info.Name, new ImmutablePalette(Enumerable.Range(0, Palette.Size).Select(i => (i == 0) ? 0 : c)), info.AllowModifiers);
        }
Пример #20
0
        public void InitPalette(WorldRenderer wr)
        {
            // Enable palette only for a specific tileset
            if (info.Tileset != null && info.Tileset.ToLowerInvariant() != world.Map.Tileset.ToLowerInvariant())
            {
                return;
            }

            var c = (uint)((info.A << 24) | (info.R << 16) | (info.G << 8) | info.B);

            wr.AddPalette(info.Name, new Palette(Exts.MakeArray(256, i => (i == 0) ? 0 : c)), info.AllowModifiers);
        }
Пример #21
0
        public void LoadPalettes(WorldRenderer wr)
        {
            Func <int, uint> makeColor = i =>
            {
                if (i < 128)
                {
                    return((uint)(int2.Lerp(255, 0, i, 127) << 24));
                }
                return(0);
            };

            wr.AddPalette(info.Name, new ImmutablePalette(Enumerable.Range(0, Palette.Size).Select(i => makeColor(i))));
        }
Пример #22
0
        public void LoadPalettes(WorldRenderer wr)
        {
            var basePalette = wr.Palette(info.BasePalette).Palette;

            // Bit twiddling is equivalent to unpacking RGB channels, dividing them by 2, subtracting from 255, then repacking
            var fog = new uint[Palette.Size];

            for (var i = 0; i < Palette.Size; i++)
            {
                fog[i] = ~((basePalette[i] >> 1) & 0x007F7F7F);
            }

            wr.AddPalette(info.Name, new ImmutablePalette(fog), info.AllowModifiers);
        }
Пример #23
0
        public void LoadPlayerPalettes(WorldRenderer wr, string playerName, Color c, bool replaceExisting)
        {
            var pal = new MutablePalette(wr.Palette(info.BasePalette).Palette);

            foreach (var i in info.RemapIndex)
            {
                var bw   = (float)(((pal[i] & 0xff) + ((pal[i] >> 8) & 0xff) + ((pal[i] >> 16) & 0xff)) / 3) / 0xff;
                var dstR = bw > .5 ? 1 - (1 - 2 * (bw - .5)) * (1 - (float)c.R / 0xff) : 2 * bw * ((float)c.R / 0xff);
                var dstG = bw > .5 ? 1 - (1 - 2 * (bw - .5)) * (1 - (float)c.G / 0xff) : 2 * bw * ((float)c.G / 0xff);
                var dstB = bw > .5 ? 1 - (1 - 2 * (bw - .5)) * (1 - (float)c.B / 0xff) : 2 * bw * ((float)c.B / 0xff);
                pal[i] = (pal[i] & 0xff000000) | ((uint)(dstR * 0xff) << 16) | ((uint)(dstG * 0xff) << 8) | (uint)(dstB * 0xff);
            }

            wr.AddPalette(info.BaseName + playerName, new ImmutablePalette(pal), info.AllowModifiers, replaceExisting);
        }
Пример #24
0
        public void LoadPalettes(WorldRenderer worldRenderer)
        {
            using (var stream = world.Map.Open(info.Filename))
            {
                /*var identifier = */ stream.ReadASCII(10);
                /*var dataSize = */ stream.ReadInt32();
                var numFrames = stream.ReadInt32();
                /*var imagesOffset = */ stream.ReadInt32();
                /*var numPalettes = */ stream.ReadInt32();
                var firstPaletteId = stream.ReadInt32();
                /*var paletteOffset = */ stream.ReadInt32();

                /*var entry = */ stream.ReadASCII(5); // "ENTRY"
                stream.Position += numFrames * 4;

                /*var pal = */ stream.ReadASCII(5); // " PAL "
                stream.Position += (info.Subpalette - firstPaletteId) * Palette.Size * 3;

                var colors = new uint[Palette.Size];

                for (var i = 0; i < Palette.Size; i++)
                {
                    colors[i] = (uint)((0xff << 24) | (stream.ReadUInt8() << 16) | (stream.ReadUInt8() << 8) | (stream.ReadUInt8() << 0));
                }

                // Transparent.
                colors[0] = 0x00000000;

                // Tracks
                colors[240] = 0xff181c18;
                colors[241] = 0xff212421;
                colors[242] = 0xff181c18;
                colors[243] = 0xff292c29;

                // Muzzle flash.
                colors[244] = 0x00000000;
                colors[245] = 0x00000000;
                colors[246] = 0x00000000;
                colors[247] = 0x00000000;

                // Shadow.
                colors[253] = 0x40000000;
                colors[254] = 0x80000000;
                colors[255] = 0xc0000000;

                worldRenderer.AddPalette(info.Name, new ImmutablePalette(colors), info.AllowModifiers);
            }
        }
Пример #25
0
        public void LoadPalettes(WorldRenderer wr)
        {
            // Enable palette only for a specific tileset
            if (info.Tileset != null && info.Tileset.ToLowerInvariant() != world.Map.Tileset.ToLowerInvariant())
            {
                return;
            }

            var a = info.A / 255f;
            var r = (int)(a * info.R + 0.5f).Clamp(0, 255);
            var g = (int)(a * info.G + 0.5f).Clamp(0, 255);
            var b = (int)(a * info.B + 0.5f).Clamp(0, 255);
            var c = (uint)Color.FromArgb(info.A, r, g, b).ToArgb();

            wr.AddPalette(info.Name, new ImmutablePalette(Enumerable.Range(0, Palette.Size).Select(i => (i == 0) ? 0 : c)), info.AllowModifiers);
        }
Пример #26
0
        public void LoadPlayerPalettes(WorldRenderer wr, string playerName, Color color, bool replaceExisting)
        {
            var basePalette = wr.Palette(info.BasePalette).Palette;
            ImmutablePalette pal;

            if (info.PlayerIndex.TryGetValue(playerName, out var remap))
            {
                pal = new ImmutablePalette(basePalette, new IndexedColorRemap(basePalette, info.RemapIndex, remap));
            }
            else
            {
                pal = new ImmutablePalette(basePalette);
            }

            wr.AddPalette(info.BaseName + playerName, pal, info.AllowModifiers, replaceExisting);
        }
Пример #27
0
        public void LoadPalettes(WorldRenderer wr)
        {
            Stream s;

            if (!world.Map.TryOpen(info.Filename, out s))
            {
                // throw new FileNotFoundException("Couldn't find palette file: " + info.Filename);
                return;
            }

            var newPal = PaletteFromStream(s, info);

            if (info.Tileset == null || info.Tileset.ToLowerInvariant() == world.Map.Tileset.ToLowerInvariant())
            {
                wr.AddPalette(info.Name, newPal, info.AllowModifiers);
            }

            s.Close();
            s.Dispose();
        }
Пример #28
0
        public void LoadPalettes(WorldRenderer wr)
        {
            var colors = new uint[Palette.Size];

            using (var s = Game.ModData.ModFiles.Open(info.Filename))
            {
                s.Seek(info.Offset, SeekOrigin.Begin);

                for (var i = 0; i < Palette.Size; i++)
                {
                    var packed = s.ReadUInt16();
                    colors[i] = (uint)((255 << 24) | ((packed & 0xF800) << 8) | ((packed & 0x7E0) << 5) | ((packed & 0x1f) << 3));

                    if (info.InvertColor)
                    {
                        colors[i] ^= 0x00FFFFFF;
                    }
                }
            }

            wr.AddPalette(info.Name, new ImmutablePalette(colors), info.AllowModifiers);
        }
Пример #29
0
        public void InitPalette(WorldRenderer wr)
        {
            var colors = new uint[256];

            using (var s = GlobalFileSystem.Open(info.Filename))
            {
                s.Seek(info.Offset, SeekOrigin.Begin);

                for (var i = 0; i < 256; i++)
                {
                    var packed = s.ReadUInt16();
                    colors[i] = (uint)((255 << 24) | ((packed & 0xF800) << 8) | ((packed & 0x7E0) << 5) | ((packed & 0x1f) << 3));

                    if (info.InvertColor)
                    {
                        colors[i] ^= 0x00FFFFFF;
                    }
                }
            }

            wr.AddPalette(info.Name, new Palette(colors), info.AllowModifiers);
        }
Пример #30
0
        public void LoadPalettes(WorldRenderer wr)
        {
            // Rotate vectors to expected orientation
            // Voxel coordinates are x=forward, y=right, z=up
            var channel = new int[] { 2, 1, 0 };
            var n       = info.Type == NormalType.RedAlert2 ? RA2Normals : TSNormals;

            // Map normals into color range
            // Introduces a maximum error of ~0.5%
            var data = new uint[Palette.Size];

            for (var i = 0; i < n.Length / 3; i++)
            {
                data[i] = 0xFF000000;
                for (var j = 0; j < 3; j++)
                {
                    var t = (n[3 * i + j] + 1) / 2;
                    data[i] |= (uint)((byte)(t * 0xFF + 0.5) << (8 * channel[j]));
                }
            }

            wr.AddPalette(info.Name, new ImmutablePalette(data));
        }