MirGoodsCell.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using Client.MirGraphics;
  2. using Client.MirScenes;
  3. using SlimDX;
  4. namespace Client.MirControls
  5. {
  6. public sealed class MirGoodsCell : MirControl
  7. {
  8. public UserItem Item;
  9. public MirLabel NameLabel, PriceLabel, CountLabel;
  10. public bool UsePearls = false;
  11. public bool Recipe = false;
  12. public bool MultipleAvailable = false;
  13. public MirImageControl NewIcon;
  14. public MirGoodsCell()
  15. {
  16. Size = new Size(205, 32);
  17. BorderColour = Color.Lime;
  18. NameLabel = new MirLabel
  19. {
  20. AutoSize = true,
  21. Parent = this,
  22. NotControl = true,
  23. Location = new Point(44, 0),
  24. };
  25. CountLabel = new MirLabel
  26. {
  27. AutoSize = true,
  28. Parent = this,
  29. NotControl = true,
  30. DrawControlTexture = true,
  31. Location = new Point(23, 17),
  32. ForeColour = Color.Yellow,
  33. };
  34. PriceLabel = new MirLabel
  35. {
  36. AutoSize = true,
  37. Parent = this,
  38. NotControl = true,
  39. Location = new Point(44, 14),
  40. };
  41. NewIcon = new MirImageControl
  42. {
  43. Index = 550,
  44. Library = Libraries.Prguse,
  45. Parent = this,
  46. Location = new Point(190, 5),
  47. NotControl = true,
  48. Visible = false
  49. };
  50. BeforeDraw += (o, e) => Update();
  51. AfterDraw += (o, e) => DrawItem();
  52. }
  53. private void Update()
  54. {
  55. NewIcon.Visible = false;
  56. if (Item == null || Item.Info == null) return;
  57. NameLabel.Text = Item.Info.FriendlyName;
  58. CountLabel.Text = (Item.Count <= 1) ? "" : Item.Count.ToString();
  59. NewIcon.Visible = !Item.IsShopItem || MultipleAvailable;
  60. if (UsePearls)
  61. {
  62. PriceLabel.Text = GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.PricePearl), (uint)(Item.Price() * GameScene.NPCRate), Item.Price() > 1 ? "s" : "");
  63. }
  64. else if (Recipe)
  65. {
  66. ClientRecipeInfo recipe = GameScene.RecipeInfoList.SingleOrDefault(x => x.Item.ItemIndex == Item.ItemIndex);
  67. PriceLabel.Text = GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.PriceGold), (uint)(recipe.Gold * GameScene.NPCRate));
  68. }
  69. else
  70. {
  71. PriceLabel.Text = GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.PriceGold), (uint)(Item.Price() * GameScene.NPCRate));
  72. }
  73. }
  74. protected override Vector2[] BorderInfo
  75. {
  76. get
  77. {
  78. if (Size == Size.Empty) return null;
  79. if (BorderRectangle != DisplayRectangle)
  80. {
  81. _borderInfo = new[]
  82. {
  83. new Vector2(DisplayRectangle.Left - 1, DisplayRectangle.Top - 1),
  84. new Vector2(DisplayRectangle.Right, DisplayRectangle.Top - 1),
  85. new Vector2(DisplayRectangle.Left - 1, DisplayRectangle.Top - 1),
  86. new Vector2(DisplayRectangle.Left - 1, DisplayRectangle.Bottom),
  87. new Vector2(DisplayRectangle.Left - 1, DisplayRectangle.Bottom),
  88. new Vector2(DisplayRectangle.Right, DisplayRectangle.Bottom),
  89. new Vector2(DisplayRectangle.Right, DisplayRectangle.Top - 1),
  90. new Vector2(DisplayRectangle.Right, DisplayRectangle.Bottom),
  91. new Vector2(DisplayRectangle.Left + 40, DisplayRectangle.Bottom),
  92. new Vector2(DisplayRectangle.Left + 40, DisplayRectangle.Top - 1)
  93. };
  94. BorderRectangle = DisplayRectangle;
  95. }
  96. return _borderInfo;
  97. }
  98. }
  99. protected override void OnMouseEnter()
  100. {
  101. base.OnMouseEnter();
  102. GameScene.Scene.CreateItemLabel(Item, hideAdded: GameScene.HideAddedStoreStats);
  103. }
  104. protected override void OnMouseLeave()
  105. {
  106. base.OnMouseLeave();
  107. GameScene.Scene.DisposeItemLabel();
  108. GameScene.HoverItem = null;
  109. }
  110. private void DrawItem()
  111. {
  112. if (Item == null || Item.Info == null) return;
  113. Size size = Libraries.Items.GetTrueSize(Item.Image);
  114. Point offSet = new Point((40 - size.Width)/2, (32 - size.Height)/2);
  115. Libraries.Items.Draw(Item.Image, offSet.X + DisplayLocation.X, offSet.Y + DisplayLocation.Y);
  116. CountLabel.Draw();
  117. }
  118. }
  119. }