123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- using System.Collections.Generic;
- using ET;
- using FairyGUI;
- using UI.Bag;
- using UI.CommonGame;
- using UnityEngine;
- namespace GFGGame
- {
- public class BagView : BaseWindow
- {
- private UI_BagUI _ui;
- private ValueBarController _valueBarController;
- // private List<ItemView> _listItemViews = new List<ItemView>();
- public override void Dispose()
- {
- if (_valueBarController != null)
- {
- _valueBarController.Dispose();
- _valueBarController = null;
- }
- // for (int i = 0; i < _listItemViews.Count; i++)
- // {
- // _listItemViews[i].Dispose();
- // _listItemViews[i] = null;
- // }
- if (_ui != null)
- {
- _ui.Dispose();
- _ui = null;
- }
- base.Dispose();
- }
- protected override void OnInit()
- {
- base.OnInit();
- packageName = UI_BagUI.PACKAGE_NAME;
- _ui = UI_BagUI.Create();
- this.viewCom = _ui.target;
- isfullScreen = true;
- isReturnView = true;
- _valueBarController = new ValueBarController(_ui.m_comValueBar);
- _ui.m_btnBack.onClick.Add(OnBtnBackClick);
- _ui.m_list.SetVirtual();
- _ui.m_list.itemRenderer = ListItemRender;
- _ui.m_list.onClickItem.Add(OnListItemClick);
- _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("cp_beijing");
- }
- protected override void AddEventListener()
- {
- base.AddEventListener();
- EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateList);
- }
- protected override void OnShown()
- {
- base.OnShown();
- _valueBarController.OnShown();
- UpdateList();
- }
- protected override void OnHide()
- {
- _valueBarController.OnHide();
- if (_ui.m_list.numItems > 0)
- {
- _ui.m_list.ScrollToView(0);
- }
- _ui.m_list.numItems = 0;
- base.OnHide();
- }
- protected override void RemoveEventListener()
- {
- base.RemoveEventListener();
- EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateList);
- }
- private void UpdateList()
- {
- _ui.m_list.numItems = BagDataManager.Instance.BagDatas.Count;
- }
- private void ListItemRender(int index, GObject obj)
- {
- ItemData itemData = BagDataManager.Instance.BagDatas[index];
- ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
- UI_ComItem item = UI_ComItem.Proxy(obj);
- item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
- //item.m_txtCount.SetVar("count", itemData.num.ToString()).FlushVars();
- item.m_txtCount.text = itemData.num.ToString();
- item.target.data = itemCfg;
- item.m_QualityType.selectedIndex = itemCfg.rarity - 1;
- item.m_ShowName.selectedIndex = 1;
- item.m_txtName.text = itemCfg.name;
- //是礼包就加入红点
- if (((itemCfg.itemType == ConstItemType.USEABLE &&
- itemCfg.subType == ConstItemSubType.USEABLE_GIFT_BAG_SELECTABLE) ||
- (itemCfg.itemType == ConstItemType.USEABLE &&
- itemCfg.subType == ConstItemSubType.USEABLE_GIFT_BAG_RANDOM))
- && itemData.id != 6003001 && itemData.id != 6003002)
- {
- RedDotController.Instance.SetComRedDot(item.target, true);
- }
- else
- {
- RedDotController.Instance.SetComRedDot(item.target, false);
- }
- UI_ComItem.ProxyEnd();
- }
- private void OnListItemClick(EventContext context)
- {
- GComponent comItem = (context.data as GComponent);
- ItemCfg itemCfg = comItem.data as ItemCfg;
- //可使用物品
- if (itemCfg.itemType == ConstItemType.USEABLE)
- {
- if (itemCfg.subType == ConstItemSubType.USEABLE_GIFT_BAG_SELECTABLE)
- {
- ViewManager.Show<GiftBoxSelectorView>(itemCfg.id);
- }
- else
- {
- //暂时程序走不到这里,这里是以前用来使用物品的一个界面---20230607--hxj注释
- ViewManager.Show<BagExchangeView>(itemCfg.id);
- }
- }
- else
- {
- var bagExchangeCfg = BagExchangeCfgArray.Instance.GetCfg(itemCfg.id);
- if (bagExchangeCfg != null)
- {
- //从背包使用物品
- ViewManager.Show<BagExchangeView>(itemCfg.id);
- }
- else
- {
- object[] sourceDatas = new object[]
- { itemCfg.id, new object[] { typeof(BagView).FullName, this.viewData } };
- GoodsItemTipsController.ShowItemTips(itemCfg.id, sourceDatas);
- }
- }
- }
- private void OnBtnBackClick()
- {
- ViewManager.GoBackFrom(typeof(BagView).FullName);
- }
- }
- }
|