ItemView.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using FairyGUI;
  2. namespace GFGGame
  3. {
  4. public class ItemView
  5. {
  6. private GComponent _obj;
  7. private GLoader _loaIcon;
  8. private GLoader _loaRarity;
  9. private GTextField _txtName;
  10. private GTextField _txtCount;
  11. private GTextField _txtHasCount;
  12. private GImage _imgGot;
  13. private GLoader _loaShouTongRewardVisble;
  14. private ItemData _itemData;
  15. public ItemView(GComponent obj)
  16. {
  17. _obj = obj;
  18. _loaIcon = obj.GetChild("loaIcon") as GLoader;
  19. _loaRarity = obj.GetChild("loaRarity") as GLoader;
  20. _txtName = obj.GetChild("txtName") as GTextField;
  21. _txtCount = obj.GetChild("txtCount") as GTextField;
  22. _txtHasCount = obj.GetChild("txtHasCount") as GTextField;
  23. _imgGot = obj.GetChild("imgGot") as GImage;
  24. _loaShouTongRewardVisble = obj.GetChild("loaShouTongReward") as GLoader;
  25. AddClickListener();
  26. }
  27. private void AddClickListener()
  28. {
  29. _obj.onClick.Add(() => { GoodsItemTipsController.ShowItemTips(_itemData.id); });
  30. }
  31. public void SetData(ItemData itemData)
  32. {
  33. _itemData = itemData;
  34. UpdateView();
  35. }
  36. private void UpdateView()
  37. {
  38. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemData.id);
  39. _loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  40. RarityIconController.UpdateRarityIcon(_loaRarity, _itemData.id, false);
  41. _imgGot.visible = false;
  42. _loaShouTongRewardVisble.visible = false;
  43. _txtName.text = itemCfg.name;
  44. _txtCount.SetVar("count", _itemData.num.ToString()).FlushVars();
  45. _txtHasCount.SetVar("count", "" + ItemDataManager.GetItemNum(_itemData.id)).FlushVars();
  46. }
  47. /// <summary>
  48. /// “已领取”显示状态
  49. /// </summary>
  50. /// <value></value>
  51. public bool ImgGotVisible
  52. {
  53. get
  54. {
  55. return _imgGot.visible;
  56. }
  57. set
  58. {
  59. _imgGot.visible = value;
  60. }
  61. }
  62. /// <summary>
  63. /// "已拥有"显示状态
  64. /// </summary>
  65. /// <value></value>
  66. public bool TxtHasCountVisble
  67. {
  68. get
  69. {
  70. return _txtHasCount.visible;
  71. }
  72. set
  73. {
  74. _txtHasCount.visible = value;
  75. }
  76. }
  77. public bool LoaShouTongRewardVisble
  78. {
  79. get
  80. {
  81. return _loaShouTongRewardVisble.visible;
  82. }
  83. set
  84. {
  85. _loaShouTongRewardVisble.visible = value;
  86. }
  87. }
  88. }
  89. }