ItemView.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. _obj.onClick.Remove(AddClickListener);
  34. _obj.onClick.Add(AddClickListener);
  35. }
  36. public void Dispose()
  37. {
  38. _obj.onClick.Remove(AddClickListener);
  39. _obj.Dispose();
  40. }
  41. private void AddClickListener()
  42. {
  43. if (!ShowTips) return;
  44. GoodsItemTipsController.ShowItemTips(_itemData.id);
  45. }
  46. public void SetData(ItemData itemData)
  47. {
  48. _itemData = itemData;
  49. UpdateView();
  50. }
  51. private void UpdateView()
  52. {
  53. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemData.id);
  54. _loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  55. RarityIconController.UpdateRarityIcon(_loaRarity, _itemData.id, false);
  56. _imgGot.visible = false;
  57. _imgNotHas.visible = false;
  58. _imgHas.visible = false;
  59. _loaShouTongRewardVisble.visible = false;
  60. _grpCount.visible = true;
  61. _showTips = true;
  62. _txtName.text = itemCfg.name;
  63. _txtCount.SetVar("count", _itemData.num.ToString()).FlushVars();
  64. _txtHasCount.SetVar("count", "" + ItemDataManager.GetItemNum(_itemData.id)).FlushVars();
  65. }
  66. public ItemData ItemData
  67. {
  68. get
  69. {
  70. return _itemData;
  71. }
  72. }
  73. /// <summary>
  74. /// “已领取”显示状态
  75. /// </summary>
  76. /// <value></value>
  77. public bool ImgGotVisible
  78. {
  79. get
  80. {
  81. return _imgGot.visible;
  82. }
  83. set
  84. {
  85. _imgGot.visible = value;
  86. }
  87. }
  88. /// “已获得”显示状态
  89. /// </summary>
  90. /// <value></value>
  91. public bool ImgHasVisible
  92. {
  93. get
  94. {
  95. return _imgHas.visible;
  96. }
  97. set
  98. {
  99. _imgHas.visible = value;
  100. }
  101. }
  102. /// <summary>
  103. /// “未获得”显示状态
  104. /// </summary>
  105. /// <value></value>
  106. public bool ImgNotGotVisible
  107. {
  108. get
  109. {
  110. return _imgNotHas.visible;
  111. }
  112. set
  113. {
  114. _imgNotHas.visible = value;
  115. }
  116. }
  117. /// <summary>
  118. /// <summary>
  119. /// 显示拥有数量
  120. /// </summary>
  121. /// <value></value>
  122. public bool ShowHasCount
  123. {
  124. get
  125. {
  126. return _txtHasCount.visible;
  127. }
  128. set
  129. {
  130. _txtHasCount.visible = value;
  131. }
  132. }
  133. /// <summary>
  134. /// 显示首通奖励标志
  135. /// </summary>
  136. /// <value></value>
  137. public bool ShowShouTongSign
  138. {
  139. get
  140. {
  141. return _loaShouTongRewardVisble.visible;
  142. }
  143. set
  144. {
  145. _loaShouTongRewardVisble.visible = value;
  146. }
  147. }
  148. /// <summary>
  149. /// 显示mingz
  150. /// </summary>
  151. /// <value></value>
  152. public bool ShowName
  153. {
  154. set
  155. {
  156. _txtName.visible = value;
  157. }
  158. }
  159. /// <summary>
  160. /// 显示数量
  161. /// </summary>
  162. /// <value></value>
  163. public bool ShowCount
  164. {
  165. set
  166. {
  167. _grpCount.visible = value;
  168. }
  169. }
  170. /// <summary>
  171. /// 展示详情tips
  172. /// </summary>
  173. /// <value></value>
  174. public bool ShowTips
  175. {
  176. get
  177. {
  178. return _showTips;
  179. }
  180. set
  181. {
  182. _showTips = value;
  183. }
  184. }
  185. }
  186. }