ItemView.cs 7.4 KB

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