BagView.cs 5.3 KB

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