BagView.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. base.Dispose();
  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. }
  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. }
  103. private void OnListItemClick(EventContext context)
  104. {
  105. GComponent comItem = (context.data as GComponent);
  106. ItemCfg itemCfg = comItem.data as ItemCfg;
  107. //可使用物品
  108. if (itemCfg.itemType == ConstItemType.USEABLE)
  109. {
  110. if (itemCfg.subType == ConstItemSubType.USEABLE_GIFT_BAG_SELECTABLE)
  111. {
  112. ViewManager.Show<GiftBoxSelectorView>(itemCfg.id);
  113. }
  114. else
  115. {
  116. //暂时程序走不到这里,这里是以前用来使用物品的一个界面---20230607--hxj注释
  117. ViewManager.Show<BagExchangeView>(itemCfg.id);
  118. }
  119. }
  120. else
  121. {
  122. object[] sourceDatas = new object[]
  123. { itemCfg.id, new object[] { typeof(BagView).FullName, this.viewData } };
  124. GoodsItemTipsController.ShowItemTips(itemCfg.id, sourceDatas);
  125. }
  126. }
  127. private void OnBtnBackClick()
  128. {
  129. ViewManager.GoBackFrom(typeof(BagView).FullName);
  130. }
  131. }
  132. }