PageRenderTime 64ms CodeModel.GetById 60ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/WorldView/Structures/ColorListData.cs

#
C# | 113 lines | 94 code | 19 blank | 0 comment | 7 complexity | 9260d6d2d34188ed72be0e01fc4b10da MD5 | raw file
  1using System;
  2using System.Drawing;
  3using System.Collections.Generic;
  4
  5namespace MoreTerra.Structures
  6{
  7	public class ColorListDataNode
  8	{
  9		public Color defaultColor;
 10		public Color currentColor;
 11
 12		public String defaultColorName;
 13		public String currentColorName;
 14
 15		public Int32 nodeId;
 16
 17		public ColorListDataNode()
 18		{
 19
 20		}
 21
 22		public ColorListDataNode(Color color, String name, Int32 id)
 23		{
 24			defaultColor = color;
 25			defaultColorName = name;
 26
 27			currentColor = color;
 28			currentColorName = name;
 29
 30			nodeId = id;
 31		}
 32	}
 33
 34	public class ColorListData
 35	{
 36		private Dictionary<String, Dictionary<String, ColorListDataNode>> data;
 37		private String name;
 38
 39		public ColorListData()
 40		{
 41			data = new Dictionary<String, Dictionary<String, ColorListDataNode>>();
 42		}
 43
 44		public void AddNewNode(String nodeName, String parentName, Color color, String colorName, Int32 id)
 45		{
 46			if (!data.ContainsKey(parentName))
 47				data.Add(parentName, new Dictionary<String, ColorListDataNode>());
 48
 49			if (data[parentName].ContainsKey(nodeName))
 50				return;
 51
 52			data[parentName].Add(nodeName, new ColorListDataNode(color, colorName, id));
 53		}
 54
 55		public ColorListDataNode GetNode(String nodeName, String parentName = "")
 56		{
 57			if (parentName != String.Empty)
 58			{
 59				if (data.ContainsKey(parentName))
 60					if (data[parentName].ContainsKey(nodeName))
 61						return data[parentName][nodeName];
 62			}
 63			else
 64			{
 65				foreach (KeyValuePair<String, Dictionary<String, ColorListDataNode>> kvp in data)
 66				{
 67					if (kvp.Value.ContainsKey(nodeName))
 68						return kvp.Value[nodeName];
 69				}
 70			}
 71			return null;
 72		}
 73
 74		public void Clear()
 75		{
 76			data.Clear();
 77		}
 78
 79		public Int32 Count
 80		{
 81			get
 82			{
 83				Int32 count = 0;
 84				foreach(KeyValuePair<String, Dictionary<String, ColorListDataNode>> kvp in data)
 85				{
 86					count += kvp.Value.Count;
 87				}
 88
 89				return count;
 90			}
 91		}
 92
 93		public Dictionary<String, Dictionary<String, ColorListDataNode>> Data
 94		{
 95			get
 96			{
 97				return data;
 98			}
 99		}
100
101		public String Name
102		{
103			get
104			{
105				return name;
106			}
107			set
108			{
109				name = value;
110			}
111		}
112	}
113}