ItemView.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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 Controller _buttonType;
  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. // _imgGot = obj.GetChild("imgGot") as GImage;
  35. _grpGot = _item.GetChild("grpGot") as GGroup;
  36. _imgNotHas = _item.GetChild("imgNotHas") as GImage;
  37. _imgHas = _item.GetChild("imgHas") as GImage;
  38. _imgShouTong = _item.GetChild("imgShowTong") as GImage;
  39. _imgNum = _item.GetChild("imgNum") as GImage;
  40. _qualityType = _item.GetController("QualityType") as Controller;
  41. _scaleType = _item.GetController("ScaleType") as Controller;
  42. _buttonType = _item.GetController("ButtonType") 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. if(itemCfg.rarity > 0)
  86. _qualityType.selectedIndex = itemCfg.rarity - 1;
  87. }
  88. public ItemData ItemData
  89. {
  90. get
  91. {
  92. return _itemData;
  93. }
  94. }
  95. public GComponent GetGComponentObj
  96. {
  97. get
  98. {
  99. return _obj;
  100. }
  101. }
  102. /// <summary>
  103. /// “已领取”显示状态
  104. /// </summary>
  105. /// <value></value>
  106. public bool GrpGotVisible
  107. {
  108. get
  109. {
  110. return _grpGot.visible;
  111. }
  112. set
  113. {
  114. _grpGot.visible = value;
  115. }
  116. }
  117. /// <summary>
  118. /// 左右上角小按钮显示状态
  119. /// </summary>
  120. /// <value></value>
  121. public int ButtonTypeVisible
  122. {
  123. get
  124. {
  125. return _buttonType.selectedIndex;
  126. }
  127. set
  128. {
  129. _buttonType.selectedIndex = value;
  130. }
  131. }
  132. /// “已获得”显示状态
  133. /// </summary>
  134. /// <value></value>
  135. public bool ImgHasVisible
  136. {
  137. get
  138. {
  139. return _imgHas.visible;
  140. }
  141. set
  142. {
  143. _imgHas.visible = value;
  144. }
  145. }
  146. /// <summary>
  147. /// “未获得”显示状态
  148. /// </summary>
  149. /// <value></value>
  150. public bool ImgNotGotVisible
  151. {
  152. get
  153. {
  154. return _imgNotHas.visible;
  155. }
  156. set
  157. {
  158. _imgNotHas.visible = value;
  159. }
  160. }
  161. /// <summary>
  162. /// <summary>
  163. /// "首通奖励"显示状态
  164. /// </summary>
  165. /// <value></value>
  166. public bool ImgShouTongVisable
  167. {
  168. get
  169. {
  170. return _imgShouTong.visible;
  171. }
  172. set
  173. {
  174. _imgShouTong.visible = value;
  175. }
  176. }
  177. /// <summary>
  178. /// 显示名字
  179. /// </summary>
  180. /// <value></value>
  181. public bool ShowName
  182. {
  183. set
  184. {
  185. _txtName.visible = value;
  186. }
  187. }
  188. /// <summary>
  189. /// 显示稀有度
  190. /// </summary>
  191. /// <value></value>
  192. public bool ShowRarity
  193. {
  194. set
  195. {
  196. _loaRarity.visible = value;
  197. }
  198. }
  199. // /// <summary>
  200. // /// 显示数量
  201. // /// </summary>
  202. // /// <value></value>
  203. // public bool ShowCount
  204. // {
  205. // set
  206. // {
  207. // _grpCount.visible = value;
  208. // }
  209. // }
  210. /// <summary>
  211. /// 展示详情tips
  212. /// </summary>
  213. /// <value></value>
  214. public bool ShowTips
  215. {
  216. get
  217. {
  218. return _showTips;
  219. }
  220. set
  221. {
  222. _showTips = value;
  223. }
  224. }
  225. public float SetComItemScale
  226. {
  227. set
  228. {
  229. _item.SetScale(value, value);
  230. }
  231. }
  232. public float SetTxtCountScale
  233. {
  234. set
  235. {
  236. _txtCount.SetScale(value, value);
  237. _imgNum.SetScale(value, value);
  238. }
  239. }
  240. public float SetTxtNameScale
  241. {
  242. set
  243. {
  244. _txtName.SetScale(value, value);
  245. }
  246. }
  247. public void SetTxtCountPos(int x, int y)
  248. {
  249. _txtCount.SetPosition(x, y, 0);
  250. }
  251. public bool ShowTxtCount
  252. {
  253. set
  254. {
  255. _txtCount.visible = value;
  256. _imgNum.visible = value;
  257. }
  258. }
  259. public void ChangeTxtCountStyle()
  260. {
  261. _txtCount.text = string.Format("{0}", _itemData.num);
  262. }
  263. public void SetTxtNamePos(int x, int y)
  264. {
  265. _txtName.SetPosition(x, y, 0);
  266. }
  267. }
  268. }