示例#1
0
        // HTML color #ffffff or banner color 123
        public static uint ParseUniformColor(string color)
        {
            const uint INVALID_COLOR = 0xdeadbeef;

            color = color.Trim();
            int bannerColor;

            if (int.TryParse(color, out bannerColor))
            {
                return(BannerManager.GetColor(bannerColor));
            }
            if (color.Length < 7 || color[0] != '#')
            {
                return(INVALID_COLOR);
            }
            try
            {
                byte r = byte.Parse(color.Substring(1, 2), NumberStyles.HexNumber);
                byte g = byte.Parse(color.Substring(3, 2), NumberStyles.HexNumber);
                byte b = byte.Parse(color.Substring(5, 2), NumberStyles.HexNumber);
                byte a = color.Length == 9 ? byte.Parse(color.Substring(7, 2), NumberStyles.HexNumber) : (byte)255;
                return(((uint)a << 24) | ((uint)r << 16) | ((uint)g << 8) | ((uint)b));
            }
            catch
            {
                return(INVALID_COLOR);
            }
        }
示例#2
0
        public static string SetKingdomColor(List <string> strings)
        {
            var args = ConsoleUtilities.Resplit(strings);

            if (args.Count == 1 && args[0] == "colors")
            {
                string output = $"\nAvailable colors\n==============================\n";
                foreach (var paletteEntry in BannerManager.ColorPalette)
                {
                    var c = Color.FromUint(paletteEntry.Value.Color);
                    output += $" Id: {paletteEntry.Key}, {c.ToString()}, rgba({(int)(c.Red * 255f)}, {(int)(c.Green * 255)}, {(int)(c.Blue * 255)}, {c.Alpha})\n";
                }
                return(output);
            }
            else if (args.Count == 1 && args[0] == "kingdoms")
            {
                return(ConsoleUtilities.GetObjectList <Kingdom>());
            }
            else if (args.Count < 3)
            {
                return($@"Usage: ""kingdomcolor.set_kingdom_color [KingdomId/KingdomName] [ColorId] [ColorId] [UniformColor] [UniformColor]""
UniformColors are optional and can be an HTML color ('#ffffff') or color id
Use ""kingdomcolor.set_kingdom_color colors/kingdoms"" to list available colors or kingdoms");
            }
            var kingdom = ConsoleUtilities.FindObjectByIdName <Kingdom>(args[0]);

            if (kingdom == null)
            {
                return("Couldn't find kingdom.");
            }
            int bannerColor;
            int bannerColor2;

            if (!int.TryParse(args[1], out bannerColor))
            {
                return("Invalid color1 specified");
            }
            if (!int.TryParse(args[2], out bannerColor2))
            {
                return("Invalid color2 specified");
            }
            uint primaryBannerColor   = BannerManager.GetColor(bannerColor);
            uint secondaryBannerColor = BannerManager.GetColor(bannerColor2);
            uint?color1 = null;
            uint?color2 = null;

            if (args.Count >= 4)
            {
                color1 = KingdomColorModule.ParseUniformColor(args[3]);
                color2 = KingdomColorModule.ParseUniformColor(args[4]);
            }
            KingdomColorModule.Instance.SetKingdomColors(kingdom, primaryBannerColor, secondaryBannerColor, color1 ?? primaryBannerColor, color2 ?? secondaryBannerColor);
            return($"Set {kingdom.Name} colors. Open and close the Clan page to take effect.");
        }
示例#3
0
        public static (uint color1, uint color2) GetColors(this IFaction faction)
        {
            var bannerData = faction.Banner.BannerDataList;
            var color1     = faction.Color;
            var color2     = faction.Color2;

            if (bannerData != null && bannerData.Count > 0)
            {
                color1 = BannerManager.GetColor(bannerData[0].ColorId);
                if (bannerData.Count > 1)
                {
                    color2 = BannerManager.GetColor(bannerData[1].ColorId);
                }
            }

            return(color1, color2);
        }