Exemple #1
0
		private void LoadColors(XmlNodeList colorNodes)
		{
			Int32 count = -1;

			if ((colorNodes == null) || (colorNodes.Count == 0))
			{
				errorLog.AppendLine("There are no Color items to load.");
				return;
			}

			foreach (XmlNode colorNode in colorNodes)
			{
				String name = String.Empty;
				Int32 red = -1;
				Int32 green = -1;
				Int32 blue = -1;
				Color useColor = Color.Black;
				Boolean hasColor = false;
				count++;

				foreach (XmlAttribute att in colorNode.Attributes)
				{
					switch (att.Name)
					{
						case "name":
							name = att.Value;
							break;
						case "red":
							if (Int32.TryParse(att.Value, out red) == false)
							{
								errorLog.AppendLine(String.Format("Color #{0} has an invalid red attribute.  Value=\"{1}\"",
									count, att.Value));
								continue;
							}

							if ((red < 0) || (red > 255))
							{
								errorLog.AppendLine(String.Format("Color #{0} had a out of range red attribute.  Value=\"{1}\"",
									count, red));
								continue;
							}
							break;
						case "green":
							if (Int32.TryParse(att.Value, out green) == false)
							{
								errorLog.AppendLine(String.Format("Color #{0} has an invalid green attribute.  Value=\"{1}\"",
									count, att.Value));
								continue;
							}

							if ((green < 0) || (green > 255))
							{
								errorLog.AppendLine(String.Format("Color #{0} had a out of range green attribute.  Value=\"{1}\"",
									count, green));
								continue;
							}
							break;
						case "blue":
							if (Int32.TryParse(att.Value, out blue) == false)
							{
								errorLog.AppendLine(String.Format("Color #{0} has an invalid blue attribute.  Value=\"{1}\"",
									count, att.Value));
								continue;
							}

							if ((blue < 0) || (blue > 255))
							{
								errorLog.AppendLine(String.Format("Color #{0} had a out of range blue attribute.  Value=\"{1}\"",
									count, blue));
								continue;
							}
							break;
						case "colorString":
							hasColor = Global.TryParseColor(att.Value, out useColor);

							if (hasColor == false)
							{
								errorLog.AppendLine(String.Format("Color #{0} has a bad colorString value.  Value={1}",
									count, att.Value));
								continue;
							}
							break;
						default:
							errorLog.AppendLine(String.Format("Color #{0} has unknown attribute \"{1}\" has value \"{2}\"",
								count, att.Name, att.Value));
							break;
					}
				}

				if (name == String.Empty)
				{
					errorLog.AppendLine(String.Format("Color #{0} had no name attribute.", count));
					continue;
				}

				if (hasColor == false)
				{
					if (red == -1)
					{
						errorLog.AppendLine(String.Format("Color #{0} had no colorString and no red attribute.", count));
						continue;
					}

					if (green == -1)
					{
						errorLog.AppendLine(String.Format("Color #{0} had no colorString and no green attribute.", count));
						continue;
					}

					if (blue == -1)
					{
						errorLog.AppendLine(String.Format("Color #{0} had no colorString and no blue attribute.", count));
						continue;
					}
					useColor = Color.FromArgb(red, green, blue);
				}
				else
				{
					if ((red != -1) && (useColor.R != red))
					{
						errorLog.AppendLine(String.Format("Color #{0} has both a colorString and a red attribute but they do not match.",
							count));
						continue;
					}

					if ((green != -1) && (useColor.G != green))
					{
						errorLog.AppendLine(String.Format("Color #{0} has both a colorString and a green attribute but they do not match.",
							count));
						continue;
					}

					if ((blue != -1) && (useColor.B != blue))
					{
						errorLog.AppendLine(String.Format("Color #{0} has both a colorString and a blue attribute but they do not match.",
							count));
						continue;
					}
				}

				if (colors.ContainsKey(name))
				{
					errorLog.AppendLine(String.Format("Color #{0} had a duplicate name to {1}.", count, name));
					continue;
				}

				ColorInfo color = new ColorInfo();
				color.name = name;
				color.color = useColor;

				colors.Add(name, color);
			}
		}
Exemple #2
0
		public void AddCustomColor(String colorName, Color newColor)
		{
			if (colors.ContainsKey(colorName))
				return;

			ColorInfo ci = new ColorInfo();

			ci.name = colorName;
			ci.color = newColor;
			ci.isCustom = true;

			colors.Add(colorName, ci);
		}