using System;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
|
namespace vnxbqy.UI
|
{
|
public class CrossServerOneVsOneHonorStoreWin : Window
|
{
|
[SerializeField] ScrollerController shopCtrl;
|
|
StoreModel model { get { return ModelCenter.Instance.GetModel<StoreModel>(); } }
|
|
List<StoreModel.StoreData> shoplist;
|
int SingleLineCnt = 2;
|
int selectedGoodId = 0;
|
|
protected override void BindController()
|
{
|
shopCtrl.OnRefreshCell += RefreshShopCell;
|
shopCtrl.lockType = EnhanceLockType.KeepVertical;
|
}
|
|
protected override void AddListeners()
|
{
|
|
}
|
|
protected override void OnPreOpen()
|
{
|
model.RefreshBuyShopLimitEvent += CreateShopCell;
|
model.storeFuncType = StoreFunc.CrossOneVsOneHonor;
|
CreateShopCell();
|
}
|
|
protected override void OnAfterOpen()
|
{
|
CheckJumpToModel();
|
}
|
|
protected override void OnPreClose()
|
{
|
selectedGoodId = 0;
|
model.RefreshBuyShopLimitEvent -= CreateShopCell;
|
}
|
protected override void OnAfterClose()
|
{
|
|
}
|
|
private void CheckJumpToModel()
|
{
|
if (model.jumpToItemId != 0)
|
{
|
var p_shopItemlist = model.TryGetStoreDatas(model.storeFuncType);
|
for (int i = 0; i < p_shopItemlist.Count; i++)
|
{
|
var storeData = p_shopItemlist[i];
|
if (storeData.storeConfig.ItemID == model.jumpToItemId)
|
{
|
selectedGoodId = storeData.shopId;
|
int index = i / 2;
|
shopCtrl.JumpIndex(index);
|
shopCtrl.m_Scorller.RefreshActiveCellViews();
|
break;
|
}
|
}
|
|
model.ClearJump();
|
}
|
}
|
|
private void CreateShopCell()
|
{
|
shoplist = model.TryGetStoreDatas(model.storeFuncType);
|
if (shoplist == null)
|
{
|
DebugEx.Log("跨服商店数据为空");
|
return;
|
}
|
|
shopCtrl.Refresh();
|
if (shoplist.Count > 0)
|
{
|
int i = 0;
|
int remain = shoplist.Count % SingleLineCnt;
|
int line = (int)shoplist.Count / SingleLineCnt;
|
if (remain > 0)
|
{
|
line += 1;
|
}
|
|
for (i = 0; i < line; i++)
|
{
|
shopCtrl.AddCell(ScrollerDataType.Header, i);
|
}
|
}
|
shopCtrl.Restart();
|
|
shopCtrl.JumpIndex(0);
|
}
|
|
private void RefreshShopCell(ScrollerDataType type, CellView cell)
|
{
|
int length = cell.transform.childCount;
|
for (int i = 0; i < length; i++)
|
{
|
int cellCount = length * cell.index + (i + 1);
|
var shopCell = cell.transform.GetChild(i).GetComponent<CrossServerOneVsOneHonorShopCell>();
|
if (shoplist.Count >= cellCount)
|
{
|
shopCell.SetActive(true);
|
shopCell.SetDisplay(shoplist[cellCount - 1].storeConfig ,selectedGoodId);
|
}
|
else
|
{
|
shopCell.SetActive(false);
|
}
|
}
|
}
|
|
}
|
}
|