ItemView.cs 4.4 KB

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