BagView.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. isReturnView = true;
  41. _valueBarController = new ValueBarController(_ui.m_comValueBar);
  42. _ui.m_btnBack.onClick.Add(OnBtnBackClick);
  43. _ui.m_list.SetVirtual();
  44. _ui.m_list.itemRenderer = ListItemRender;
  45. _ui.m_list.onClickItem.Add(OnListItemClick);
  46. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("cp_beijing");
  47. }
  48. protected override void AddEventListener()
  49. {
  50. base.AddEventListener();
  51. EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateList);
  52. }
  53. protected override void OnShown()
  54. {
  55. base.OnShown();
  56. _valueBarController.OnShown();
  57. UpdateList();
  58. }
  59. protected override void OnHide()
  60. {
  61. _valueBarController.OnHide();
  62. if (_ui.m_list.numItems > 0)
  63. {
  64. _ui.m_list.ScrollToView(0);
  65. }
  66. _ui.m_list.numItems = 0;
  67. base.OnHide();
  68. }
  69. protected override void RemoveEventListener()
  70. {
  71. base.RemoveEventListener();
  72. EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateList);
  73. }
  74. private void UpdateList()
  75. {
  76. _ui.m_list.numItems = BagDataManager.Instance.BagDatas.Count;
  77. }
  78. private void ListItemRender(int index, GObject obj)
  79. {
  80. ItemData itemData = BagDataManager.Instance.BagDatas[index];
  81. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  82. UI_ComItem item = UI_ComItem.Proxy(obj);
  83. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  84. //item.m_txtCount.SetVar("count", itemData.num.ToString()).FlushVars();
  85. item.m_txtCount.text = itemData.num.ToString();
  86. item.target.data = itemCfg;
  87. item.m_QualityType.selectedIndex = itemCfg.rarity - 1;
  88. item.m_ShowName.selectedIndex = 1;
  89. item.m_txtName.text = itemCfg.name;
  90. //是礼包就加入红点
  91. if (((itemCfg.itemType == ConstItemType.USEABLE &&
  92. itemCfg.subType == ConstItemSubType.USEABLE_GIFT_BAG_SELECTABLE) ||
  93. (itemCfg.itemType == ConstItemType.USEABLE &&
  94. itemCfg.subType == ConstItemSubType.USEABLE_GIFT_BAG_RANDOM))
  95. && itemData.id != 6003001 && itemData.id != 6003002)
  96. {
  97. RedDotController.Instance.SetComRedDot(item.target, true);
  98. }
  99. else
  100. {
  101. RedDotController.Instance.SetComRedDot(item.target, false);
  102. }
  103. UI_ComItem.ProxyEnd();
  104. }
  105. private void OnListItemClick(EventContext context)
  106. {
  107. GComponent comItem = (context.data as GComponent);
  108. ItemCfg itemCfg = comItem.data as ItemCfg;
  109. //可使用物品
  110. if (itemCfg.itemType == ConstItemType.USEABLE)
  111. {
  112. if (itemCfg.subType == ConstItemSubType.USEABLE_GIFT_BAG_SELECTABLE)
  113. {
  114. ViewManager.Show<GiftBoxSelectorView>(itemCfg.id);
  115. }
  116. else
  117. {
  118. //暂时程序走不到这里,这里是以前用来使用物品的一个界面---20230607--hxj注释
  119. ViewManager.Show<BagExchangeView>(itemCfg.id);
  120. }
  121. }
  122. else
  123. {
  124. var bagExchangeCfg = BagExchangeCfgArray.Instance.GetCfg(itemCfg.id);
  125. if (bagExchangeCfg != null)
  126. {
  127. //从背包使用物品
  128. ViewManager.Show<BagExchangeView>(itemCfg.id);
  129. }
  130. else
  131. {
  132. object[] sourceDatas = new object[]
  133. { itemCfg.id, new object[] { typeof(BagView).FullName, this.viewData } };
  134. GoodsItemTipsController.ShowItemTips(itemCfg.id, sourceDatas);
  135. }
  136. }
  137. }
  138. private void OnBtnBackClick()
  139. {
  140. ViewManager.GoBackFrom(typeof(BagView).FullName);
  141. }
  142. }
  143. }