ItemView.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. using FairyGUI;
  2. namespace GFGGame
  3. {
  4. public class ItemView
  5. {
  6. private GComponent _obj;
  7. private GLoader _loaIcon;
  8. private GLoader _loaRarity;
  9. private GTextField _txtName;
  10. private GTextField _txtCount;
  11. private GTextField _txtHasCount;
  12. private GImage _imgGot;
  13. private GImage _imgNotHas;
  14. private GImage _imgHas;
  15. private GLoader _loaShouTongRewardVisble;
  16. private GGroup _grpCount;
  17. private bool _showTips = true;
  18. private ItemData _itemData;
  19. public ItemView(GComponent obj)
  20. {
  21. _obj = obj;
  22. _loaIcon = obj.GetChild("loaIcon") as GLoader;
  23. _loaRarity = obj.GetChild("loaRarity") as GLoader;
  24. _txtName = obj.GetChild("txtName") as GTextField;
  25. _txtCount = obj.GetChild("txtCount") as GTextField;
  26. _txtHasCount = obj.GetChild("txtHasCount") as GTextField;
  27. _imgGot = obj.GetChild("imgGot") as GImage;
  28. _imgNotHas = obj.GetChild("imgNotHas") as GImage;
  29. _imgHas = obj.GetChild("imgHas") as GImage;
  30. _loaShouTongRewardVisble = obj.GetChild("loaShouTongReward") as GLoader;
  31. _grpCount = obj.GetChild("grpCount") as GGroup;
  32. AddClickListener();
  33. }
  34. private void AddClickListener()
  35. {
  36. _obj.onClick.Add(() =>
  37. {
  38. if (!ShowTips) return;
  39. GoodsItemTipsController.ShowItemTips(_itemData.id);
  40. });
  41. }
  42. public void SetData(ItemData itemData)
  43. {
  44. _itemData = itemData;
  45. UpdateView();
  46. }
  47. private void UpdateView()
  48. {
  49. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemData.id);
  50. _loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  51. RarityIconController.UpdateRarityIcon(_loaRarity, _itemData.id, false);
  52. _imgGot.visible = false;
  53. _imgNotHas.visible = false;
  54. _imgHas.visible = false;
  55. _loaShouTongRewardVisble.visible = false;
  56. _grpCount.visible = true;
  57. _showTips = true;
  58. _txtName.text = itemCfg.name;
  59. _txtCount.SetVar("count", _itemData.num.ToString()).FlushVars();
  60. _txtHasCount.SetVar("count", "" + ItemDataManager.GetItemNum(_itemData.id)).FlushVars();
  61. }
  62. /// <summary>
  63. /// “已领取”显示状态
  64. /// </summary>
  65. /// <value></value>
  66. public bool ImgGotVisible
  67. {
  68. get
  69. {
  70. return _imgGot.visible;
  71. }
  72. set
  73. {
  74. _imgGot.visible = value;
  75. }
  76. }
  77. /// “已获得”显示状态
  78. /// </summary>
  79. /// <value></value>
  80. public bool ImgHasVisible
  81. {
  82. get
  83. {
  84. return _imgHas.visible;
  85. }
  86. set
  87. {
  88. _imgHas.visible = value;
  89. }
  90. }
  91. /// <summary>
  92. /// “未获得”显示状态
  93. /// </summary>
  94. /// <value></value>
  95. public bool ImgNotGotVisible
  96. {
  97. get
  98. {
  99. return _imgNotHas.visible;
  100. }
  101. set
  102. {
  103. _imgNotHas.visible = value;
  104. }
  105. }
  106. /// <summary>
  107. /// <summary>
  108. /// "已拥有"显示状态
  109. /// </summary>
  110. /// <value></value>
  111. public bool TxtHasCountVisble
  112. {
  113. get
  114. {
  115. return _txtHasCount.visible;
  116. }
  117. set
  118. {
  119. _txtHasCount.visible = value;
  120. }
  121. }
  122. public bool LoaShouTongRewardVisble
  123. {
  124. get
  125. {
  126. return _loaShouTongRewardVisble.visible;
  127. }
  128. set
  129. {
  130. _loaShouTongRewardVisble.visible = value;
  131. }
  132. }
  133. /// <summary>
  134. /// 显示数量
  135. /// </summary>
  136. /// <value></value>
  137. public bool ShowCount
  138. {
  139. set
  140. {
  141. _grpCount.visible = value;
  142. }
  143. }
  144. /// <summary>
  145. /// 展示详情tips
  146. /// </summary>
  147. /// <value></value>
  148. public bool ShowTips
  149. {
  150. get
  151. {
  152. return _showTips;
  153. }
  154. set
  155. {
  156. _showTips = value;
  157. }
  158. }
  159. }
  160. }