|
|
|
using System;
|
|
|
|
using AX.MessageSystem;
|
|
|
|
using SuperScrollView;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class UIViewBag : UIView {
|
|
|
|
|
|
|
|
public UIViewMessageBox MessageBox;
|
|
|
|
public LoopListView2 ScrollViewBag;
|
|
|
|
//关闭按钮
|
|
|
|
public CommonButton ButtonClose;
|
|
|
|
public CommonButton ButtonDelete;
|
|
|
|
public CommonButton ButtonClear;
|
|
|
|
[HideInInspector]
|
|
|
|
//总Item个数
|
|
|
|
public int TotalCount = 0;
|
|
|
|
|
|
|
|
//每行Item个数
|
|
|
|
private int RowCount = 3;
|
|
|
|
|
|
|
|
public override UIViewType ViewType
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return UIViewType.Normal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
ButtonClose.OnClicked += ButtonClose_OnClicked;
|
|
|
|
ButtonDelete.OnClicked += ButtonDelete_OnClicked;
|
|
|
|
ButtonClear.OnClicked += ButtonClear_OnClicked;
|
|
|
|
ScrollViewBag.InitListView(0, OnGetItemByIndex);
|
|
|
|
}
|
|
|
|
public override void OnDestroy()
|
|
|
|
{
|
|
|
|
base.OnDestroy();
|
|
|
|
MessageDispatcher.RemoveListener("REFRESH_UIVIEW_BAG", RefreshUI);
|
|
|
|
ButtonClose.OnClicked -= ButtonClose_OnClicked;
|
|
|
|
ButtonDelete.OnClicked -= ButtonDelete_OnClicked;
|
|
|
|
ButtonClear.OnClicked -= ButtonClear_OnClicked;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ButtonClose_OnClicked(CommonButton obj)
|
|
|
|
{
|
|
|
|
Hide();
|
|
|
|
UIManager.HideView<UIViewEquipLib>();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ButtonDelete_OnClicked(CommonButton obj)
|
|
|
|
{
|
|
|
|
MessageBox.Show("是否删除选中装备?", EquipManager.Instance.CurrentSelectedBag.DeleteSelectedEquip);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ButtonClear_OnClicked(CommonButton obj)
|
|
|
|
{
|
|
|
|
MessageBox.Show("是否清空所有装备?", EquipManager.Instance.CurrentSelectedBag.ClearEquipData);
|
|
|
|
}
|
|
|
|
|
|
|
|
private LoopListViewItem2 OnGetItemByIndex(LoopListView2 listView, int index)
|
|
|
|
{
|
|
|
|
//获取Item预设
|
|
|
|
LoopListViewItem2 item = listView.NewListViewItem("EquipRowItem_Bag");
|
|
|
|
//
|
|
|
|
EquipRowItem itemScript = item.GetComponent<EquipRowItem>();
|
|
|
|
if (item.IsInitHandlerCalled == false)
|
|
|
|
{
|
|
|
|
itemScript.Init(true);
|
|
|
|
item.IsInitHandlerCalled = true;
|
|
|
|
}
|
|
|
|
for (int i = 0; i < RowCount; ++i)
|
|
|
|
{
|
|
|
|
int itemIndex = index * RowCount + i;
|
|
|
|
if (itemIndex >= TotalCount)
|
|
|
|
{
|
|
|
|
itemScript.mItemList[i].gameObject.SetActive(false);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
//获取装备数据
|
|
|
|
Equip itemData = EquipManager.Instance.CurrentSelectedBag.EquipData[itemIndex];
|
|
|
|
if (itemData != null)
|
|
|
|
{
|
|
|
|
itemScript.mItemList[i].gameObject.SetActive(true);
|
|
|
|
itemScript.mItemList[i].SetItemData(itemData, itemIndex);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
itemScript.mItemList[i].gameObject.SetActive(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnEnable()
|
|
|
|
{
|
|
|
|
MessageDispatcher.AddListener("REFRESH_UIVIEW_BAG", RefreshUI);
|
|
|
|
}
|
|
|
|
private void OnDisable()
|
|
|
|
{
|
|
|
|
MessageDispatcher.RemoveListener("REFRESH_UIVIEW_BAG", RefreshUI);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void RefreshUI(IMessage obj)
|
|
|
|
{
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
//刷新
|
|
|
|
public override void Refresh()
|
|
|
|
{
|
|
|
|
base.Refresh();
|
|
|
|
ScrollViewBag.SetListItemCount(GetItemCount(), false);
|
|
|
|
ScrollViewBag.RefreshAllShownItem();
|
|
|
|
}
|
|
|
|
public int GetItemCount()
|
|
|
|
{
|
|
|
|
TotalCount = EquipManager.Instance.CurrentSelectedBag.EquipData.Count;
|
|
|
|
int itemCount = TotalCount / RowCount;
|
|
|
|
if (TotalCount % RowCount > 0)
|
|
|
|
{
|
|
|
|
itemCount++;
|
|
|
|
}
|
|
|
|
return itemCount;
|
|
|
|
}
|
|
|
|
}
|