ItemView.cs 6.7 KB

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