|
@@ -0,0 +1,139 @@
|
|
|
+
|
|
|
+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 GComponent _imgSelected;
|
|
|
+ private List<ItemView> _listItemViews = new List<ItemView>();
|
|
|
+ private int _curItemId = -1;
|
|
|
+ public override void Dispose()
|
|
|
+ {
|
|
|
+ base.Dispose();
|
|
|
+ if (_valueBarController != null)
|
|
|
+ {
|
|
|
+ _valueBarController.Dispose();
|
|
|
+ _valueBarController = null;
|
|
|
+ }
|
|
|
+ for (int i = 0; i < _listItemViews.Count; i++)
|
|
|
+ {
|
|
|
+ _listItemViews[i].Dispose();
|
|
|
+ _listItemViews[i] = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (_imgSelected != null)
|
|
|
+ {
|
|
|
+ _imgSelected.RemoveFromParent();
|
|
|
+ _imgSelected.Dispose();
|
|
|
+ }
|
|
|
+ if (_ui != null)
|
|
|
+ {
|
|
|
+ _ui.Dispose();
|
|
|
+ _ui = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void OnInit()
|
|
|
+ {
|
|
|
+ base.OnInit();
|
|
|
+
|
|
|
+ packageName = UI_BagUI.PACKAGE_NAME;
|
|
|
+ _ui = UI_BagUI.Create();
|
|
|
+ this.viewCom = _ui.target;
|
|
|
+ isfullScreen = true;
|
|
|
+
|
|
|
+ _valueBarController = new ValueBarController(_ui.m_comValueBar);
|
|
|
+
|
|
|
+ _ui.m_btnback.onClick.Add(OnBtnBackClick);
|
|
|
+ _ui.m_list.itemRenderer = ListItemRender;
|
|
|
+ _ui.m_list.onClickItem.Add(OnListItemClick);
|
|
|
+
|
|
|
+ _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("mrqd_bjbj");
|
|
|
+
|
|
|
+ _imgSelected = new GComponent();
|
|
|
+ _imgSelected = UIPackage.CreateObject(UI_BagUI.PACKAGE_NAME, "ComSelect").asCom;
|
|
|
+ }
|
|
|
+ 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();
|
|
|
+ _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;
|
|
|
+ int index = BagDataManager.Instance.GetItemIndex(_curItemId, _ui.m_list.selectedIndex);
|
|
|
+
|
|
|
+ if (index >= 0)
|
|
|
+ {
|
|
|
+ _ui.m_list.selectedIndex = index;
|
|
|
+ int childIndex = _ui.m_list.ItemIndexToChildIndex(index);
|
|
|
+ GComponent comItem = _ui.m_list.GetChildAt(childIndex).asCom;
|
|
|
+ ChangeSelect(comItem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ListItemRender(int index, GObject obj)
|
|
|
+ {
|
|
|
+ ItemData itemData = BagDataManager.Instance.BagDatas[index];
|
|
|
+ if (obj.data == null)
|
|
|
+ {
|
|
|
+ ItemView itemView = new ItemView(obj as GComponent);
|
|
|
+ obj.data = itemView;
|
|
|
+ _listItemViews.Add(itemView);
|
|
|
+ }
|
|
|
+ (obj.data as ItemView).SetData(itemData);
|
|
|
+ (obj.data as ItemView).ShowName = false;
|
|
|
+ (obj.data as ItemView).ShowHasCount = false;
|
|
|
+ (obj.data as ItemView).ShowTips = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OnListItemClick(EventContext context)
|
|
|
+ {
|
|
|
+ GComponent comItem = (context.data as GComponent);
|
|
|
+ ItemView itemData = comItem.data as ItemView;
|
|
|
+ ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.ItemData.id);
|
|
|
+ if (itemCfg.useType == 0)
|
|
|
+ {
|
|
|
+ GoodsItemTipsController.ShowItemTips(itemCfg.id);
|
|
|
+ }
|
|
|
+ ChangeSelect(comItem);
|
|
|
+ }
|
|
|
+ private void ChangeSelect(GComponent comItem)
|
|
|
+ {
|
|
|
+ comItem.AddChildAt(_imgSelected, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OnBtnBackClick()
|
|
|
+ {
|
|
|
+ ViewManager.GoBackFrom(typeof(BagView).FullName);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|