You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
226 lines
6.2 KiB
226 lines
6.2 KiB
using System; |
|
using System.Collections.Generic; |
|
using AX.MessageSystem; |
|
using Newtonsoft.Json; |
|
using SuperScrollView; |
|
using UnityEngine; |
|
using UnityEngine.UI; |
|
/// <summary> |
|
/// 装备仓库 |
|
/// </summary> |
|
public class UIViewEquipLib : UIView |
|
{ |
|
//分组按钮 |
|
public List<CommonToggle> GroupButtons = new List<CommonToggle>(); |
|
//类型按钮 |
|
public List<CommonToggle> TypeButtons = new List<CommonToggle>(); |
|
//循环列表 |
|
public LoopListView2 EquipLoopList; |
|
//提交按钮 |
|
public CommonButton CommitButton; |
|
//关闭按钮 |
|
public CommonButton ButtonClose; |
|
//当前激活的按钮 |
|
private CommonToggle ActiveTypeToggle; |
|
private CommonToggle ActiveGroupToggle; |
|
//展示的装备数据 |
|
private List<string> IDList = new List<string>(); |
|
[HideInInspector] |
|
//总Item个数 |
|
public int TotalCount = 0; |
|
[HideInInspector] |
|
//每行Item个数 |
|
public int RowCount = 4; |
|
|
|
public override UIViewType ViewType |
|
{ |
|
get |
|
{ |
|
return UIViewType.Normal; |
|
} |
|
} |
|
|
|
//初始化 |
|
public void Awake() |
|
{ |
|
EquipLoopList.InitListView(GetItemCount(), OnGetItemByIndex); |
|
|
|
InitButtonsOnClick(); |
|
|
|
ChangedGroupButton(GroupButtons[0]); |
|
|
|
SerchEquipData(); |
|
} |
|
// 初始化按钮OnClick |
|
private void InitButtonsOnClick() |
|
{ |
|
foreach (var item in TypeButtons) |
|
{ |
|
item.OnClicked = TypeButtonClicked; |
|
} |
|
foreach (var item in GroupButtons) |
|
{ |
|
item.OnClicked = GroupButtonClicked; |
|
} |
|
CommitButton.OnClicked = CommitButon_OnClicked; |
|
ButtonClose.OnClicked = ButtonClose_OnClicked; |
|
} |
|
|
|
public override void OnDestroy() |
|
{ |
|
base.OnDestroy(); |
|
MessageDispatcher.RemoveListener("REFRESH_UIVIEW_EQUIPLIB", RefreshUI); |
|
CommitButton.OnClicked -= CommitButon_OnClicked; |
|
ButtonClose.OnClicked -= ButtonClose_OnClicked; |
|
} |
|
//关闭按钮事件 |
|
private void ButtonClose_OnClicked(CommonButton obj) |
|
{ |
|
//初始化购物车数据 |
|
EquipManager.Instance.InitData(); |
|
Hide(); |
|
} |
|
//提交按钮事件 |
|
private void CommitButon_OnClicked(CommonButton obj) |
|
{ |
|
//添加装备到背包 |
|
EquipManager.Instance.AddSelectedEquipToBag(); |
|
//初始化购物车数据 |
|
EquipManager.Instance.InitData(); |
|
//刷新UI |
|
Refresh(); |
|
} |
|
private void OnEnable() |
|
{ |
|
MessageDispatcher.AddListener("REFRESH_UIVIEW_EQUIPLIB", RefreshUI); |
|
} |
|
private void OnDisable() |
|
{ |
|
MessageDispatcher.RemoveListener("REFRESH_UIVIEW_EQUIPLIB", RefreshUI); |
|
} |
|
|
|
private void RefreshUI(IMessage obj) |
|
{ |
|
Refresh(); |
|
} |
|
|
|
public LoopListViewItem2 OnGetItemByIndex(LoopListView2 listView, int index) |
|
{ |
|
//获取Item预设 |
|
LoopListViewItem2 item = listView.NewListViewItem("EquipRowItem"); |
|
// |
|
EquipRowItem itemScript = item.GetComponent<EquipRowItem>(); |
|
if (item.IsInitHandlerCalled == false) |
|
{ |
|
itemScript.Init(false); |
|
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; |
|
} |
|
string id = IDList[itemIndex]; |
|
//获取装备数据 |
|
Equip itemData = EquipManager.Instance.GetEquipByID(id); |
|
if (itemData != null) |
|
{ |
|
itemScript.mItemList[i].gameObject.SetActive(true); |
|
itemScript.mItemList[i].SetItemData(itemData, itemIndex); |
|
} |
|
else |
|
{ |
|
itemScript.mItemList[i].gameObject.SetActive(false); |
|
} |
|
} |
|
return item; |
|
} |
|
#region 初始化按钮 |
|
private void InitTypeButtons() |
|
{ |
|
|
|
} |
|
|
|
private void TypeButtonClicked(CommonToggle arg1, bool arg2) |
|
{ |
|
if (arg2) |
|
{ |
|
ActiveTypeToggle = arg1; |
|
SerchEquipData(); |
|
} |
|
} |
|
|
|
private void ChangedGroupButton(CommonToggle toggle) |
|
{ |
|
//设置激活的组按钮 |
|
ActiveGroupToggle = toggle; |
|
//查询组按钮下需要激活的类型按钮 |
|
List<string> types = EquipManager.Instance.Groups[ActiveGroupToggle.LableText]; |
|
//激活组按钮下的类型按钮 |
|
foreach (var item in TypeButtons) |
|
{ |
|
item.IsOn = false; |
|
item.gameObject.SetActive(false); |
|
} |
|
for (int i = 0; i < types.Count; i++) |
|
{ |
|
TypeButtons[i].LableText = types[i]; |
|
TypeButtons[i].gameObject.SetActive(true); |
|
} |
|
//这是当前激活按钮 |
|
TypeButtons[0].IsOn = true; |
|
ActiveTypeToggle = TypeButtons[0]; |
|
} |
|
|
|
private void GroupButtonClicked(CommonToggle arg1, bool arg2) |
|
{ |
|
if (arg2) |
|
{ |
|
ActiveGroupToggle = arg1; |
|
ChangedGroupButton(arg1); |
|
//SerchEquipData();改变类型按钮时会查询数据,不用再次查询 |
|
} |
|
} |
|
#endregion |
|
// 查询要展示的装备 |
|
public void SerchEquipData() |
|
{ |
|
IDList.Clear(); |
|
IDList = EquipManager.Instance.Serch(ActiveTypeToggle.LableText, ActiveGroupToggle.LableText); |
|
Refresh(); |
|
} |
|
//刷新 |
|
public override void Refresh() |
|
{ |
|
base.Refresh(); |
|
EquipLoopList.SetListItemCount(GetItemCount(), false); |
|
EquipLoopList.RefreshAllShownItem(); |
|
} |
|
public int GetItemCount() |
|
{ |
|
TotalCount = IDList.Count; |
|
int itemCount = TotalCount / RowCount; |
|
if (TotalCount % RowCount > 0) |
|
{ |
|
itemCount++; |
|
} |
|
return itemCount; |
|
} |
|
//////TODO |
|
//void SetListItemTotalCount(int count) |
|
//{ |
|
// int count1 = ViewModel.EquipData.Count / mItemCountPerRow; |
|
// if (ViewModel.EquipData.Count % mItemCountPerRow > 0) |
|
// { |
|
// count1++; |
|
// } |
|
|
|
// EquipLoopList.SetListItemCount(count1, false); |
|
// EquipLoopList.RefreshAllShownItem(); |
|
//} |
|
|
|
|
|
}
|
|
|