ItemView.cs 7.3 KB

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