ItemView.cs 3.9 KB

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