Example #1
0
        public ColorScheme(RegistryKey key) : this()
        {
            Name = key.Name.Substring(key.Name.LastIndexOf('\\') + 1);

            //	Border - may be texture or static color
            object borderTextureObject = key.GetValue("BorderTexture");

            if (borderTextureObject != null)
            {
                if (TextureLibrary.Contains((string)borderTextureObject))
                {
                    BorderTexture = TextureLibrary.Lookup((string)borderTextureObject);
                }
                else
                {
                    throw new Exception("Unknown texture specified in color scheme: " + (string)borderTextureObject);
                }
            }
            else
            {
                BorderColor = Color.FromArgb(Convert.ToInt32(key.GetValue("BorderColor")));
            }
            HighlightColor = Color.FromArgb(Convert.ToInt32(key.GetValue("HighlightColor")));
            TextColor      = Color.FromArgb(Convert.ToInt32(key.GetValue("TextColor")));
            int    nSquareColors = 0;
            object value;

            //	repeat for each square color until we run out of specified colors/textures
            while (true)
            {
                //	first see if a texture is defined for this square color
                string valuename = "SquareTexture" + (nSquareColors + 1).ToString();
                value = key.GetValue(valuename);
                if (value != null)
                {
                    if (TextureLibrary.Contains((string)value))
                    {
                        if (SquareTextures == null)
                        {
                            SquareTextures = new Dictionary <int, Texture>();
                        }
                        Texture texture = TextureLibrary.Lookup((string)value);
                        SquareTextures.Add(nSquareColors, texture);
                        SquareColors.Add(nSquareColors, texture.SubstituteColor);
                        nSquareColors++;
                    }
                    else
                    {
                        throw new Exception("Unknown texture specified in color scheme: " + valuename);
                    }
                }
                else
                {
                    //	if no texture check for a specific color
                    valuename = "SquareColor" + (nSquareColors + 1).ToString();
                    value     = key.GetValue(valuename);
                    if (value != null)
                    {
                        SquareColors.Add(nSquareColors, Color.FromArgb(Convert.ToInt32(value)));
                        nSquareColors++;
                    }
                    else
                    {
                        //	out of square colors/textures
                        break;
                    }
                }
            }
            NumberOfColors = nSquareColors;
            int    nPlayerColors        = 0;
            string playerColorValueName = "PlayerColor" + (nPlayerColors + 1).ToString();

            while ((value = key.GetValue(playerColorValueName)) != null)
            {
                PlayerColors.Add(nPlayerColors, Color.FromArgb(Convert.ToInt32(value)));
                nPlayerColors++;
                playerColorValueName = "PlayerColor" + (nPlayerColors + 1).ToString();
            }
            Modified = false;
        }