BagView.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. using System.Collections.Generic;
  2. using ET;
  3. using FairyGUI;
  4. using UI.Bag;
  5. using UI.CommonGame;
  6. using UnityEngine;
  7. namespace GFGGame
  8. {
  9. public class BagView : BaseWindow
  10. {
  11. private UI_BagUI _ui;
  12. private ValueBarController _valueBarController;
  13. // private List<ItemView> _listItemViews = new List<ItemView>();
  14. public override void Dispose()
  15. {
  16. if (_valueBarController != null)
  17. {
  18. _valueBarController.Dispose();
  19. _valueBarController = null;
  20. }
  21. // for (int i = 0; i < _listItemViews.Count; i++)
  22. // {
  23. // _listItemViews[i].Dispose();
  24. // _listItemViews[i] = null;
  25. // }
  26. if (_ui != null)
  27. {
  28. _ui.Dispose();
  29. _ui = null;
  30. }
  31. base.Dispose();
  32. }
  33. protected override void OnInit()
  34. {
  35. base.OnInit();
  36. packageName = UI_BagUI.PACKAGE_NAME;
  37. _ui = UI_BagUI.Create();
  38. this.viewCom = _ui.target;
  39. isfullScreen = true;
  40. _valueBarController = new ValueBarController(_ui.m_comValueBar);
  41. _ui.m_btnBack.onClick.Add(OnBtnBackClick);
  42. _ui.m_list.SetVirtual();
  43. _ui.m_list.itemRenderer = ListItemRender;
  44. _ui.m_list.onClickItem.Add(OnListItemClick);
  45. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("cp_beijing");
  46. }
  47. protected override void AddEventListener()
  48. {
  49. base.AddEventListener();
  50. EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateList);
  51. }
  52. protected override void OnShown()
  53. {
  54. base.OnShown();
  55. _valueBarController.OnShown();
  56. UpdateList();
  57. }
  58. protected override void OnHide()
  59. {
  60. _valueBarController.OnHide();
  61. if (_ui.m_list.numItems > 0)
  62. {
  63. _ui.m_list.ScrollToView(0);
  64. }
  65. _ui.m_list.numItems = 0;
  66. base.OnHide();
  67. }
  68. protected override void RemoveEventListener()
  69. {
  70. base.RemoveEventListener();
  71. EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateList);
  72. }
  73. private void UpdateList()
  74. {
  75. _ui.m_list.numItems = BagDataManager.Instance.BagDatas.Count;
  76. }
  77. private void ListItemRender(int index, GObject obj)
  78. {
  79. ItemData itemData = BagDataManager.Instance.BagDatas[index];
  80. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  81. UI_ComItem item = UI_ComItem.Proxy(obj);
  82. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  83. //item.m_txtCount.SetVar("count", itemData.num.ToString()).FlushVars();
  84. item.m_txtCount.text = itemData.num.ToString();
  85. item.target.data = itemCfg;
  86. item.m_QualityType.selectedIndex = itemCfg.rarity - 1;
  87. item.m_ShowName.selectedIndex = 1;
  88. item.m_txtName.text = itemCfg.name;
  89. //是礼包就加入红点
  90. if (((itemCfg.itemType == ConstItemType.USEABLE &&
  91. itemCfg.subType == ConstItemSubType.USEABLE_GIFT_BAG_SELECTABLE) ||
  92. (itemCfg.itemType == ConstItemType.USEABLE &&
  93. itemCfg.subType == ConstItemSubType.USEABLE_GIFT_BAG_RANDOM))
  94. && itemData.id != 6003001 && itemData.id != 6003002)
  95. {
  96. RedDotController.Instance.SetComRedDot(item.target, true);
  97. }
  98. else
  99. {
  100. RedDotController.Instance.SetComRedDot(item.target, false);
  101. }
  102. UI_ComItem.ProxyEnd();
  103. }
  104. private void OnListItemClick(EventContext context)
  105. {
  106. GComponent comItem = (context.data as GComponent);
  107. ItemCfg itemCfg = comItem.data as ItemCfg;
  108. //可使用物品
  109. if (itemCfg.itemType == ConstItemType.USEABLE)
  110. {
  111. if (itemCfg.subType == ConstItemSubType.USEABLE_GIFT_BAG_SELECTABLE)
  112. {
  113. ViewManager.Show<GiftBoxSelectorView>(itemCfg.id);
  114. }
  115. else
  116. {
  117. //暂时程序走不到这里,这里是以前用来使用物品的一个界面---20230607--hxj注释
  118. ViewManager.Show<BagExchangeView>(itemCfg.id);
  119. }
  120. }
  121. else
  122. {
  123. object[] sourceDatas = new object[]
  124. { itemCfg.id, new object[] { typeof(BagView).FullName, this.viewData } };
  125. GoodsItemTipsController.ShowItemTips(itemCfg.id, sourceDatas);
  126. }
  127. }
  128. private void OnBtnBackClick()
  129. {
  130. ViewManager.GoBackFrom(typeof(BagView).FullName);
  131. }
  132. }
  133. }