ItemView.cs 6.5 KB

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