ItemView.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. using cfg.GfgCfg;
  2. using ET;
  3. using FairyGUI;
  4. using UnityEngine;
  5. namespace GFGGame
  6. {
  7. public class ItemView
  8. {
  9. private GComponent _obj;
  10. private GComponent _item;
  11. private GLoader _loaIcon;
  12. private GLoader _loaRarity;
  13. private GTextField _txtName;
  14. private GTextField _txtCount;
  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 Controller _buttonType;
  24. // private GGroup _grpCount;
  25. private bool _showTips = true;
  26. private ItemData _itemData;
  27. public ItemView(GComponent obj)
  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. // _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. _buttonType = _item.GetController("ButtonType") as Controller;
  44. // _grpCount = obj.GetChild("grpCount") as GGroup;
  45. // AddClickListener();
  46. _item.onClick.Remove(AddClickListener);
  47. _item.onClick.Add(AddClickListener);
  48. }
  49. public void Dispose()
  50. {
  51. _item.onClick.Remove(AddClickListener);
  52. _item.Dispose();
  53. }
  54. private void AddClickListener()
  55. {
  56. if (!ShowTips) return;
  57. GoodsItemTipsController.ShowItemTips(_itemData.id);
  58. }
  59. public void SetData(ItemData itemData)
  60. {
  61. _itemData = itemData;
  62. UpdateView();
  63. }
  64. private void UpdateView()
  65. {
  66. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(_itemData.id);
  67. if (itemCfg == null)
  68. {
  69. Log.Error($"使用了一个不存在的物品 {_itemData.id}!");
  70. return;
  71. }
  72. _loaIcon.url = string.IsNullOrEmpty(itemCfg.Res) ? "" : ResPathUtil.GetIconPath(itemCfg);
  73. RarityIconController.UpdateRarityIcon(_loaRarity, _itemData.id, false);
  74. // _imgGot.visible = false;
  75. _txtName.visible = false;
  76. _grpGot.visible = false;
  77. _imgNotHas.visible = false;
  78. _imgHas.visible = false;
  79. _imgShouTong.visible = false;
  80. // _grpCount.visible = true;
  81. _showTips = true;
  82. _txtCount.visible = true;
  83. _imgNum.visible = true;
  84. _txtName.text = itemCfg.Name;
  85. string strNum = "";
  86. if(_itemData.numRandomeMin > 0 && _itemData.num > _itemData.numRandomeMin)
  87. strNum = string.Format("{0}~{1}", _itemData.numRandomeMin, _itemData.num);
  88. else
  89. strNum = string.Format("{0}", _itemData.num);
  90. _txtCount.text = strNum;
  91. if (itemCfg.Rarity > 0)
  92. _qualityType.selectedIndex = itemCfg.Rarity - 1;
  93. }
  94. public ItemData ItemData
  95. {
  96. get
  97. {
  98. return _itemData;
  99. }
  100. }
  101. public GComponent GetGComponentObj
  102. {
  103. get
  104. {
  105. return _obj;
  106. }
  107. }
  108. /// <summary>
  109. /// “已领取”显示状态
  110. /// </summary>
  111. /// <value></value>
  112. public bool GrpGotVisible
  113. {
  114. get
  115. {
  116. return _grpGot.visible;
  117. }
  118. set
  119. {
  120. _grpGot.visible = value;
  121. }
  122. }
  123. /// <summary>
  124. /// 左右上角小按钮显示状态
  125. /// </summary>
  126. /// <value></value>
  127. public int ButtonTypeVisible
  128. {
  129. get
  130. {
  131. return _buttonType.selectedIndex;
  132. }
  133. set
  134. {
  135. _buttonType.selectedIndex = value;
  136. }
  137. }
  138. /// “已获得”显示状态
  139. /// </summary>
  140. /// <value></value>
  141. public bool ImgHasVisible
  142. {
  143. get
  144. {
  145. return _imgHas.visible;
  146. }
  147. set
  148. {
  149. _imgHas.visible = value;
  150. }
  151. }
  152. /// <summary>
  153. /// “未获得”显示状态
  154. /// </summary>
  155. /// <value></value>
  156. public bool ImgNotGotVisible
  157. {
  158. get
  159. {
  160. return _imgNotHas.visible;
  161. }
  162. set
  163. {
  164. _imgNotHas.visible = value;
  165. }
  166. }
  167. /// <summary>
  168. /// <summary>
  169. /// "首通奖励"显示状态
  170. /// </summary>
  171. /// <value></value>
  172. public bool ImgShouTongVisable
  173. {
  174. get
  175. {
  176. return _imgShouTong.visible;
  177. }
  178. set
  179. {
  180. _imgShouTong.visible = value;
  181. }
  182. }
  183. /// <summary>
  184. /// 显示名字
  185. /// </summary>
  186. /// <value></value>
  187. public bool ShowName
  188. {
  189. set
  190. {
  191. _txtName.visible = value;
  192. }
  193. }
  194. /// <summary>
  195. /// 显示稀有度
  196. /// </summary>
  197. /// <value></value>
  198. public bool ShowRarity
  199. {
  200. set
  201. {
  202. _loaRarity.visible = value;
  203. }
  204. }
  205. // /// <summary>
  206. // /// 显示数量
  207. // /// </summary>
  208. // /// <value></value>
  209. // public bool ShowCount
  210. // {
  211. // set
  212. // {
  213. // _grpCount.visible = value;
  214. // }
  215. // }
  216. /// <summary>
  217. /// 展示详情tips
  218. /// </summary>
  219. /// <value></value>
  220. public bool ShowTips
  221. {
  222. get
  223. {
  224. return _showTips;
  225. }
  226. set
  227. {
  228. _showTips = value;
  229. }
  230. }
  231. public float SetComItemScale
  232. {
  233. set
  234. {
  235. _item.SetScale(value, value);
  236. }
  237. }
  238. public float SetTxtCountScale
  239. {
  240. set
  241. {
  242. _txtCount.SetScale(value, value);
  243. _imgNum.SetScale(value, value);
  244. }
  245. }
  246. public float SetTxtNameScale
  247. {
  248. set
  249. {
  250. _txtName.SetScale(value, value);
  251. }
  252. }
  253. public void SetTxtCountPos(int x, int y)
  254. {
  255. _txtCount.SetPosition(x, y, 0);
  256. }
  257. public bool ShowTxtCount
  258. {
  259. set
  260. {
  261. _txtCount.visible = value;
  262. _imgNum.visible = value;
  263. }
  264. }
  265. public void ChangeTxtCountStyle()
  266. {
  267. _txtCount.text = string.Format("{0}", _itemData.num);
  268. }
  269. public void SetTxtNamePos(int x, int y)
  270. {
  271. _txtName.SetPosition(x, y, 0);
  272. }
  273. }
  274. }