PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/WorldView/Structures/ColorListData.cs

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