Beispiel #1
0
        /// <summary> Parses an #RRGGBB hex color string. </summary>
        public static ColorDesc ParseHex(string hex)
        {
            if (hex.Length > 0 && hex[0] == '#')
            {
                hex = hex.Remove(0, 1);
            }
            if (hex.Length != 3 && hex.Length != 6)
            {
                throw new ArgumentException("hex must be either 3 or 6 chars long");
            }

            ColorDesc c = default(ColorDesc);
            int       R, G, B;

            if (hex.Length == 6)
            {
                R = (Hex(hex[0]) << 4) | Hex(hex[1]);
                G = (Hex(hex[2]) << 4) | Hex(hex[3]);
                B = (Hex(hex[4]) << 4) | Hex(hex[5]);
            }
            else
            {
                R = Hex(hex[0]); R |= (R << 4);
                G = Hex(hex[1]); G |= (G << 4);
                B = Hex(hex[2]); B |= (B << 4);
            }

            c.R = (byte)R; c.G = (byte)G; c.B = (byte)B; c.A = 255;
            return(c);
        }
Beispiel #2
0
        internal static void LoadList()
        {
            if (!File.Exists(Paths.CustomColorsFile))
            {
                return;
            }
            string[]  lines = File.ReadAllLines(Paths.CustomColorsFile);
            ColorDesc col   = default(ColorDesc);

            for (int i = 0; i < lines.Length; i++)
            {
                string[] parts = lines[i].SplitSpaces();
                if (parts.Length != 7)
                {
                    continue;
                }
                col.Code = parts[0][0]; col.Fallback = parts[1][0]; col.Name = parts[2];

                if (Byte.TryParse(parts[3], out col.R) && Byte.TryParse(parts[4], out col.G) &&
                    Byte.TryParse(parts[5], out col.B) && Byte.TryParse(parts[6], out col.A))
                {
                    List[col.Index] = col;
                }
            }
        }
Beispiel #3
0
        /// <summary> Finds partial matches of 'color' against the list of colors. </summary>
        public static string FindColor(Player p, string color)
        {
            int       matches;
            ColorDesc desc = Find(p, color, out matches, Colors.List,
                                  col => !col.Undefined, col => col.Name, "colors", 20);

            return(desc.Undefined ? null : "&" + desc.Code);
        }
Beispiel #4
0
 public bool IsModified()
 {
     if ((Code >= '0' && Code <= '9') || (Code >= 'a' && Code <= 'f'))
     {
         ColorDesc def = Colors.DefaultCol(Code);
         return(R != def.R || G != def.G || B != def.B || Name != def.Name);
     }
     return(!Undefined);
 }
Beispiel #5
0
 public static void Update(ColorDesc color)
 {
     List[color.Index] = color;
     Player[] players = PlayerInfo.Online.Items;
     foreach (Player p in players)
     {
         p.Session.SendSetTextColor(color);
     }
     Save();
 }
Beispiel #6
0
 public static void Update(ColorDesc col)
 {
     List[col.Index] = col;
     Player[] players = PlayerInfo.Online.Items;
     foreach (Player p in players)
     {
         if (!p.Supports(CpeExt.TextColors))
         {
             continue;
         }
         p.Send(Packet.SetTextColor(col));
     }
     SaveList();
 }
Beispiel #7
0
        public void SendEnvColor(byte type, string hex)
        {
            if (String.IsNullOrEmpty(hex))
            {
                Send(Packet.EnvColor(type, -1, -1, -1)); return;
            }

            try {
                ColorDesc c = Colors.ParseHex(hex);
                Send(Packet.EnvColor(type, c.R, c.G, c.B));
            } catch (ArgumentException) {
                Send(Packet.EnvColor(type, -1, -1, -1));
            }
        }
Beispiel #8
0
        public void Show(Player p)
        {
            if (!p.Supports(CpeExt.SelectionCuboid) || !Shows)
            {
                return;
            }

            ColorDesc col = Colors.ParseHex(Config.ShowColor);

            p.Send(Packet.MakeSelection(
                       ID, "", new Vec3U16(MinX, MinY, MinZ),
                       new Vec3U16((ushort)(MaxX + 1), (ushort)(MaxY + 1), (ushort)(MaxZ + 1)),
                       col.R, col.G, col.B, Config.ShowAlpha, p.hasCP437));
        }
Beispiel #9
0
        static void SetColor(Player p, string input, string area, string variable, ref string target)
        {
            if (IsResetString(input))
            {
                p.Message("Reset {0} for {1} &Sto normal", variable, area);
                target = "";
            }
            else
            {
                ColorDesc rgb = default(ColorDesc);
                if (!CommandParser.GetHex(p, input, ref rgb))
                {
                    return;
                }

                p.Message("Set {0} for {1} &Sto #{2}", variable, area, input);
                target = Utils.Hex(rgb.R, rgb.G, rgb.B);
            }
        }
Beispiel #10
0
        public static ColorDesc DefaultCol(char code)
        {
            switch (code)
            {
            case '0': return(new ColorDesc('0', "Black"));

            case '1': return(new ColorDesc('1', "Navy"));

            case '2': return(new ColorDesc('2', "Green"));

            case '3': return(new ColorDesc('3', "Teal"));

            case '4': return(new ColorDesc('4', "Maroon"));

            case '5': return(new ColorDesc('5', "Purple"));

            case '6': return(new ColorDesc('6', "Gold"));

            case '7': return(new ColorDesc('7', "Silver"));

            case '8': return(new ColorDesc('8', "Gray"));

            case '9': return(new ColorDesc('9', "Blue"));

            case 'a': return(new ColorDesc('a', "Lime"));

            case 'b': return(new ColorDesc('b', "Aqua"));

            case 'c': return(new ColorDesc('c', "Red"));

            case 'd': return(new ColorDesc('d', "Pink"));

            case 'e': return(new ColorDesc('e', "Yellow"));

            case 'f': return(new ColorDesc('f', "White"));
            }

            ColorDesc col = default(ColorDesc);

            col.Code = code;
            return(col);
        }
Beispiel #11
0
        /// <summary> Parses an #RRGGBB hex color string. </summary>
        public static bool TryParseHex(string hex, out ColorDesc c)
        {
            c = default(ColorDesc);
            if (hex == null || hex.Length == 0)
            {
                return(false);
            }
            if (hex[0] == '#')
            {
                hex = hex.Remove(0, 1);
            }
            if (!(hex.Length == 3 || hex.Length == 6))
            {
                return(false);
            }

            for (int i = 0; i < hex.Length; i++)
            {
                if (UnHex(hex[i]) == -1)
                {
                    return(false);
                }
            }

            int R, G, B;

            if (hex.Length == 6)
            {
                R = (UnHex(hex[0]) << 4) | UnHex(hex[1]);
                G = (UnHex(hex[2]) << 4) | UnHex(hex[3]);
                B = (UnHex(hex[4]) << 4) | UnHex(hex[5]);
            }
            else
            {
                R = UnHex(hex[0]); R |= (R << 4);
                G = UnHex(hex[1]); G |= (G << 4);
                B = UnHex(hex[2]); B |= (B << 4);
            }

            c.R = (byte)R; c.G = (byte)G; c.B = (byte)B; c.A = 255;
            return(true);
        }
Beispiel #12
0
        public static void SetColor(Player p, string value, byte envType, string envTypeName, ref string target)
        {
            if (IsResetString(value))
            {
                Player.Message(p, "Reset {0} color for {1} %Sto normal", envTypeName, p.level.ColoredName);
                target = "";
            }
            else
            {
                ColorDesc rgb = default(ColorDesc);
                if (!CommandParser.GetHex(p, value, ref rgb))
                {
                    return;
                }

                Player.Message(p, "Set {0} color for {1} %Sto #{2}", envTypeName, p.level.ColoredName, value);
                target = Utils.Hex(rgb.R, rgb.G, rgb.B);
            }
            UpdateEnvColor(p, envType, value);
        }