ItemView.cs 6.6 KB

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