PageRenderTime 34ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/Rawr.UI/Items/ItemListItem.cs

#
C# | 182 lines | 157 code | 16 blank | 9 comment | 27 complexity | ffed00eaac53d751d416d2fc14d593a9 MD5 | raw file
  1. using System;
  2. using System.Net;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.Windows.Documents;
  6. using System.Windows.Ink;
  7. using System.Windows.Input;
  8. using System.Windows.Media;
  9. using System.Windows.Media.Animation;
  10. using System.Windows.Shapes;
  11. using System.Collections.Generic;
  12. namespace Rawr.UI
  13. {
  14. public class ItemListItem
  15. {
  16. private ComparisonCalculationBase _calc;
  17. private double _maxValue;
  18. private double _maxWidth;
  19. public ItemListItem(ComparisonCalculationBase calc, double maxValue, double maxWidth)
  20. {
  21. _calc = calc;
  22. _maxValue = maxValue;
  23. _maxWidth = maxWidth;
  24. }
  25. public bool Equipped { get { return _calc.Equipped; } }
  26. public ItemInstance ItemInstance { get { return _calc.ItemInstance; } }
  27. public Item Item { get { return _calc.Item; } }
  28. public string Name { get { return _calc.Name; } }
  29. public float OverallRating { get { return _calc.OverallPoints; } }
  30. public int EnchantId
  31. {
  32. get
  33. {
  34. if (_calc.Item == null) return 0;
  35. return Math.Abs(_calc.Item.Id % (int)AvailableItemIDModifiers.Enchants);
  36. }
  37. }
  38. public int TinkeringId
  39. {
  40. get
  41. {
  42. if (_calc.Item == null) return 0;
  43. return Math.Abs(_calc.Item.Id % (int)AvailableItemIDModifiers.Tinkerings);
  44. }
  45. }
  46. public int ReforgeId
  47. {
  48. get
  49. {
  50. if (_calc.Item == null) return 0;
  51. return -_calc.Item.Id - (int)AvailableItemIDModifiers.Reforges;
  52. }
  53. }
  54. public ImageSource Icon
  55. {
  56. get
  57. {
  58. if (_calc.ItemInstance != null && _calc.ItemInstance.Item != null)
  59. return Icons.AnIcon(_calc.ItemInstance.Item.IconPath);
  60. else
  61. return null;
  62. }
  63. }
  64. #if false
  65. public void ItemImage_ImageFailed(object o, ExceptionRoutedEventArgs e)
  66. {
  67. ItemImage.ImageFailed -= new EventHandler<ExceptionRoutedEventArgs>(ItemImage_ImageFailed);
  68. #if DEBUG
  69. //TalentImage_ImageFailed2(o, e); // Tell me what happened
  70. //TalentImage.ImageFailed += new EventHandler<ExceptionRoutedEventArgs>(TalentImage_ImageFailed2);
  71. #endif
  72. // Getting the Image from the Armory failed, lets try another source
  73. if (itemInstance != null)
  74. {
  75. ItemImage.Source = Icons.AnIcon(ItemInstance.Item.IconPath);
  76. }
  77. else if (NonItemImageSource != null)
  78. {
  79. ItemImage.Source = Icons.AnIcon(NonItemImageSource);
  80. }
  81. }
  82. public void ItemImage_ImageFailed2(object o, ExceptionRoutedEventArgs e)
  83. {
  84. ItemImage.ImageFailed -= new EventHandler<ExceptionRoutedEventArgs>(ItemImage_ImageFailed2);
  85. // Getting the Image from the Armory & Wowhead failed, tell me why
  86. /*string infoString = string.Format("Talent Name: {0}\r\nClass: {1}\r\nTree Name: {2}\r\nTalent Icon: {3}\r\nSource String: {4}",
  87. talentData.Name, TalentTree.Class, TalentTree.TreeName, talentData.Icon, (TalentImage.Source as BitmapImage).UriSource);
  88. /*Base.ErrorBox eb = new Base.ErrorBox("Error getting the talent image", e.ErrorException, "Talent Image Update()", infoString);
  89. eb.Show();*/
  90. }
  91. #endif
  92. private ItemListItemRating[] _ratings = null;
  93. public ItemListItemRating[] Ratings
  94. {
  95. get
  96. {
  97. //if (_ratings == null)
  98. {
  99. _ratings = new ItemListItemRating[_calc.SubPoints.Length];
  100. Color[] colors = new Color[_ratings.Length];
  101. int i = 0;
  102. foreach (var kvp in Calculations.SubPointNameColors)
  103. colors[i++] = kvp.Value;
  104. for (i = 0; i < _ratings.Length; i++)
  105. _ratings[i] = new ItemListItemRating()
  106. {
  107. Brush = new SolidColorBrush(colors[i]),
  108. Width = Math.Max(0d, _maxWidth * ((double)_calc.SubPoints[i] / _maxValue))
  109. };
  110. }
  111. return _ratings;
  112. }
  113. }
  114. public ItemListItemGem[] Gems
  115. {
  116. get
  117. {
  118. if (_calc.ItemInstance == null || _calc.ItemInstance.Item == null)
  119. return new ItemListItemGem[0];
  120. List<ItemListItemGem> gems = new List<ItemListItemGem>();
  121. if (_calc.ItemInstance.Gem1 != null)
  122. gems.Add(new ItemListItemGem()
  123. {
  124. GemIcon = Icons.AnIcon(_calc.ItemInstance.Gem1.IconPath),
  125. SocketBrush = GetBrushForSlot(_calc.ItemInstance.Item.SocketColor1)
  126. });
  127. if (_calc.ItemInstance.Gem2 != null)
  128. gems.Add(new ItemListItemGem()
  129. {
  130. GemIcon = Icons.AnIcon(_calc.ItemInstance.Gem2.IconPath),
  131. SocketBrush = GetBrushForSlot(_calc.ItemInstance.Item.SocketColor2)
  132. });
  133. if (_calc.ItemInstance.Gem3 != null)
  134. gems.Add(new ItemListItemGem()
  135. {
  136. GemIcon = Icons.AnIcon(_calc.ItemInstance.Gem3.IconPath),
  137. SocketBrush = GetBrushForSlot(_calc.ItemInstance.Item.SocketColor3)
  138. });
  139. return gems.ToArray();
  140. }
  141. }
  142. private Brush GetBrushForSlot(ItemSlot slot)
  143. {
  144. switch (slot)
  145. {
  146. case ItemSlot.Red: return new SolidColorBrush(Colors.Red);
  147. case ItemSlot.Yellow: return new SolidColorBrush(Colors.Yellow);
  148. case ItemSlot.Blue: return new SolidColorBrush(Colors.Blue);
  149. case ItemSlot.Cogwheel: return new SolidColorBrush(Colors.Black);
  150. case ItemSlot.Hydraulic: return new SolidColorBrush(Colors.White);
  151. default: return new SolidColorBrush(Colors.Gray);
  152. }
  153. }
  154. public class ItemListItemRating
  155. {
  156. public double Width { get; set; }
  157. public Brush Brush { get; set; }
  158. public Visibility Visibility { get; set; }
  159. }
  160. public class ItemListItemGem
  161. {
  162. public ImageSource GemIcon { get; set; }
  163. public Brush SocketBrush { get; set; }
  164. }
  165. }
  166. }