ItemView.cs 6.2 KB

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