ItemView.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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 = obj.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. _txtName.visible = false;
  62. _grpGot.visible = false;
  63. _imgNotHas.visible = false;
  64. _imgHas.visible = false;
  65. _imgShouTong.visible = false;
  66. // _grpCount.visible = true;
  67. _showTips = true;
  68. _txtName.text = itemCfg.name;
  69. _txtCount.SetVar("count", _itemData.num.ToString()).FlushVars();
  70. _txtHasCount.SetVar("count", "" + ItemDataManager.GetItemNum(_itemData.id)).FlushVars();
  71. }
  72. public ItemData ItemData
  73. {
  74. get
  75. {
  76. return _itemData;
  77. }
  78. }
  79. /// <summary>
  80. /// “已领取”显示状态
  81. /// </summary>
  82. /// <value></value>
  83. public bool GrpGotVisible
  84. {
  85. get
  86. {
  87. return _grpGot.visible;
  88. }
  89. set
  90. {
  91. _grpGot.visible = value;
  92. }
  93. }
  94. /// “已获得”显示状态
  95. /// </summary>
  96. /// <value></value>
  97. public bool ImgHasVisible
  98. {
  99. get
  100. {
  101. return _imgHas.visible;
  102. }
  103. set
  104. {
  105. _imgHas.visible = value;
  106. }
  107. }
  108. /// <summary>
  109. /// “未获得”显示状态
  110. /// </summary>
  111. /// <value></value>
  112. public bool ImgNotGotVisible
  113. {
  114. get
  115. {
  116. return _imgNotHas.visible;
  117. }
  118. set
  119. {
  120. _imgNotHas.visible = value;
  121. }
  122. }
  123. /// <summary>
  124. /// <summary>
  125. /// "首通奖励"显示状态
  126. /// </summary>
  127. /// <value></value>
  128. public bool ImgShouTongVisable
  129. {
  130. get
  131. {
  132. return _imgShouTong.visible;
  133. }
  134. set
  135. {
  136. _imgShouTong.visible = value;
  137. }
  138. }
  139. /// <summary>
  140. /// 显示拥有数量
  141. /// </summary>
  142. /// <value></value>
  143. public bool ShowHasCount
  144. {
  145. get
  146. {
  147. return _txtHasCount.visible;
  148. }
  149. set
  150. {
  151. _txtHasCount.visible = value;
  152. }
  153. }
  154. /// <summary>
  155. /// 显示名字
  156. /// </summary>
  157. /// <value></value>
  158. public bool ShowName
  159. {
  160. set
  161. {
  162. _txtName.visible = value;
  163. }
  164. }
  165. /// <summary>
  166. /// 显示稀有度
  167. /// </summary>
  168. /// <value></value>
  169. public bool ShowRarity
  170. {
  171. set
  172. {
  173. _loaRarity.visible = value;
  174. }
  175. }
  176. // /// <summary>
  177. // /// 显示数量
  178. // /// </summary>
  179. // /// <value></value>
  180. // public bool ShowCount
  181. // {
  182. // set
  183. // {
  184. // _grpCount.visible = value;
  185. // }
  186. // }
  187. /// <summary>
  188. /// 展示详情tips
  189. /// </summary>
  190. /// <value></value>
  191. public bool ShowTips
  192. {
  193. get
  194. {
  195. return _showTips;
  196. }
  197. set
  198. {
  199. _showTips = value;
  200. }
  201. }
  202. public float SetComItemScale
  203. {
  204. set
  205. {
  206. _item.SetScale(value, value);
  207. }
  208. }
  209. public float SetTxtCountScale
  210. {
  211. set
  212. {
  213. _txtCount.SetScale(value, value);
  214. }
  215. }
  216. public void SetTxtCountPos(int x, int y)
  217. {
  218. _txtCount.SetPosition(x, y, 0);
  219. }
  220. public void SetTxtNamePos(int x, int y)
  221. {
  222. _txtName.SetPosition(x, y, 0);
  223. }
  224. }
  225. }