ItemView.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 GGroup _grpCount;
  15. private ItemData _itemData;
  16. public ItemView(GComponent obj)
  17. {
  18. _obj = obj;
  19. _loaIcon = obj.GetChild("loaIcon") as GLoader;
  20. _loaRarity = obj.GetChild("loaRarity") as GLoader;
  21. _txtName = obj.GetChild("txtName") as GTextField;
  22. _txtCount = obj.GetChild("txtCount") as GTextField;
  23. _txtHasCount = obj.GetChild("txtHasCount") as GTextField;
  24. _imgGot = obj.GetChild("imgGot") as GImage;
  25. _loaShouTongRewardVisble = obj.GetChild("loaShouTongReward") as GLoader;
  26. _grpCount = obj.GetChild("grpCount") as GGroup;
  27. AddClickListener();
  28. }
  29. private void AddClickListener()
  30. {
  31. _obj.onClick.Add(() =>
  32. {
  33. if (!ShowTips) return;
  34. GoodsItemTipsController.ShowItemTips(_itemData.id);
  35. });
  36. }
  37. public void SetData(ItemData itemData)
  38. {
  39. _itemData = itemData;
  40. UpdateView();
  41. }
  42. private void UpdateView()
  43. {
  44. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemData.id);
  45. _loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  46. RarityIconController.UpdateRarityIcon(_loaRarity, _itemData.id, false);
  47. _imgGot.visible = false;
  48. _loaShouTongRewardVisble.visible = false;
  49. _grpCount.visible = true;
  50. _showTips = true;
  51. _txtName.text = itemCfg.name;
  52. _txtCount.SetVar("count", _itemData.num.ToString()).FlushVars();
  53. _txtHasCount.SetVar("count", "" + ItemDataManager.GetItemNum(_itemData.id)).FlushVars();
  54. }
  55. /// <summary>
  56. /// “已领取”显示状态
  57. /// </summary>
  58. /// <value></value>
  59. public bool ImgGotVisible
  60. {
  61. get
  62. {
  63. return _imgGot.visible;
  64. }
  65. set
  66. {
  67. _imgGot.visible = value;
  68. }
  69. }
  70. /// <summary>
  71. /// "已拥有"显示状态
  72. /// </summary>
  73. /// <value></value>
  74. public bool TxtHasCountVisble
  75. {
  76. get
  77. {
  78. return _txtHasCount.visible;
  79. }
  80. set
  81. {
  82. _txtHasCount.visible = value;
  83. }
  84. }
  85. public bool LoaShouTongRewardVisble
  86. {
  87. get
  88. {
  89. return _loaShouTongRewardVisble.visible;
  90. }
  91. set
  92. {
  93. _loaShouTongRewardVisble.visible = value;
  94. }
  95. }
  96. /// <summary>
  97. /// 显示数量
  98. /// </summary>
  99. /// <value></value>
  100. public bool ShowCount
  101. {
  102. set
  103. {
  104. _grpCount.visible = value;
  105. }
  106. }
  107. private bool _showTips = true;
  108. public bool ShowTips
  109. {
  110. get
  111. {
  112. return _showTips;
  113. }
  114. set
  115. {
  116. _showTips = value;
  117. }
  118. }
  119. }
  120. }