ItemView.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. using FairyGUI;
  2. namespace GFGGame
  3. {
  4. public class ItemView
  5. {
  6. private GComponent _obj;
  7. private GComponent _item;
  8. private GLoader _loaIcon;
  9. private GLoader _loaRarity;
  10. private GTextField _txtName;
  11. private GTextField _txtCount;
  12. private GTextField _txtHasCount;
  13. // private GImage _imgGot;
  14. private GGroup _grpGot;
  15. private GImage _imgNotHas;
  16. private GImage _imgHas;
  17. private GImage _imgShouTong;
  18. // private GGroup _grpCount;
  19. private bool _showTips = true;
  20. private ItemData _itemData;
  21. public ItemView(GComponent obj)
  22. {
  23. _obj = obj;
  24. _item = obj.GetChild("comItemIcon").asCom;
  25. _loaIcon = _item.GetChild("loaIcon") as GLoader;
  26. _loaRarity = _item.GetChild("loaRarity") as GLoader;
  27. _txtName = _item.GetChild("txtName") as GTextField;
  28. _txtCount = obj.GetChild("txtCount") as GTextField;
  29. _txtHasCount = _item.GetChild("txtHasCount") as GTextField;
  30. // _imgGot = obj.GetChild("imgGot") as GImage;
  31. _grpGot = _item.GetChild("grpGot") as GGroup;
  32. _imgNotHas = _item.GetChild("imgNotHas") as GImage;
  33. _imgHas = _item.GetChild("imgHas") as GImage;
  34. _imgShouTong = _item.GetChild("imgShowTong") as GImage;
  35. // _grpCount = obj.GetChild("grpCount") as GGroup;
  36. // AddClickListener();
  37. _item.onClick.Remove(AddClickListener);
  38. _item.onClick.Add(AddClickListener);
  39. }
  40. public void Dispose()
  41. {
  42. _item.onClick.Remove(AddClickListener);
  43. _item.Dispose();
  44. }
  45. private void AddClickListener()
  46. {
  47. if (!ShowTips) return;
  48. GoodsItemTipsController.ShowItemTips(_itemData.id);
  49. }
  50. public void SetData(ItemData itemData)
  51. {
  52. _itemData = itemData;
  53. UpdateView();
  54. }
  55. private void UpdateView()
  56. {
  57. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemData.id);
  58. _loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  59. RarityIconController.UpdateRarityIcon(_loaRarity, _itemData.id, false);
  60. // _imgGot.visible = false;
  61. _grpGot.visible = false;
  62. _imgNotHas.visible = false;
  63. _imgHas.visible = false;
  64. _imgShouTong.visible = false;
  65. // _grpCount.visible = true;
  66. _showTips = true;
  67. _txtName.text = itemCfg.name;
  68. _txtCount.SetVar("count", _itemData.num.ToString()).FlushVars();
  69. _txtHasCount.SetVar("count", "" + ItemDataManager.GetItemNum(_itemData.id)).FlushVars();
  70. }
  71. public ItemData ItemData
  72. {
  73. get
  74. {
  75. return _itemData;
  76. }
  77. }
  78. /// <summary>
  79. /// “已领取”显示状态
  80. /// </summary>
  81. /// <value></value>
  82. public bool GrpGotVisible
  83. {
  84. get
  85. {
  86. return _grpGot.visible;
  87. }
  88. set
  89. {
  90. _grpGot.visible = value;
  91. }
  92. }
  93. /// “已获得”显示状态
  94. /// </summary>
  95. /// <value></value>
  96. public bool ImgHasVisible
  97. {
  98. get
  99. {
  100. return _imgHas.visible;
  101. }
  102. set
  103. {
  104. _imgHas.visible = value;
  105. }
  106. }
  107. /// <summary>
  108. /// “未获得”显示状态
  109. /// </summary>
  110. /// <value></value>
  111. public bool ImgNotGotVisible
  112. {
  113. get
  114. {
  115. return _imgNotHas.visible;
  116. }
  117. set
  118. {
  119. _imgNotHas.visible = value;
  120. }
  121. }
  122. /// <summary>
  123. /// <summary>
  124. /// "首通奖励"显示状态
  125. /// </summary>
  126. /// <value></value>
  127. public bool ImgShouTongVisable
  128. {
  129. get
  130. {
  131. return _imgShouTong.visible;
  132. }
  133. set
  134. {
  135. _imgShouTong.visible = value;
  136. }
  137. }
  138. /// <summary>
  139. /// 显示拥有数量
  140. /// </summary>
  141. /// <value></value>
  142. public bool ShowHasCount
  143. {
  144. get
  145. {
  146. return _txtHasCount.visible;
  147. }
  148. set
  149. {
  150. _txtHasCount.visible = value;
  151. }
  152. }
  153. /// <summary>
  154. /// 显示名字
  155. /// </summary>
  156. /// <value></value>
  157. public bool ShowName
  158. {
  159. set
  160. {
  161. _txtName.visible = value;
  162. }
  163. }
  164. /// <summary>
  165. /// 显示稀有度
  166. /// </summary>
  167. /// <value></value>
  168. public bool ShowRarity
  169. {
  170. set
  171. {
  172. _loaRarity.visible = value;
  173. }
  174. }
  175. // /// <summary>
  176. // /// 显示数量
  177. // /// </summary>
  178. // /// <value></value>
  179. // public bool ShowCount
  180. // {
  181. // set
  182. // {
  183. // _grpCount.visible = value;
  184. // }
  185. // }
  186. /// <summary>
  187. /// 展示详情tips
  188. /// </summary>
  189. /// <value></value>
  190. public bool ShowTips
  191. {
  192. get
  193. {
  194. return _showTips;
  195. }
  196. set
  197. {
  198. _showTips = value;
  199. }
  200. }
  201. public float SetComItemScale
  202. {
  203. set
  204. {
  205. _item.SetScale(value, value);
  206. }
  207. }
  208. public void SetTxtCountPos(int x, int y)
  209. {
  210. _txtCount.SetPosition(x, y, 0);
  211. }
  212. }
  213. }