//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Wednesday, November 01, 2017
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Linq;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace vnxbqy.UI
|
{
|
|
public class ActStoreWin : Window
|
{
|
[SerializeField] ScrollerController shopCtrl;
|
[SerializeField] Text moneyText;
|
[SerializeField] Image moneyIcon;
|
[SerializeField] Text actInfoText;
|
[SerializeField] Text actTimeText;
|
|
StoreModel model { get { return ModelCenter.Instance.GetModel<StoreModel>(); } }
|
|
List<StoreModel.StoreData> shoplist;
|
int SingleLineCnt = 2;
|
int selectedGoodId = 0;
|
protected override void BindController()
|
{
|
|
}
|
|
protected override void AddListeners()
|
{
|
|
}
|
|
|
protected override void OnPreOpen()
|
{
|
shopCtrl.OnRefreshCell += OnRefreshCell;
|
model.RefreshBuyShopLimitEvent += RefreshStore;
|
PlayerDatas.Instance.playerDataRefreshEvent += OnPlayerDataRefreshEvent;
|
|
model.storeFuncType = (StoreFunc)model.rankActStore_StoreType;
|
Display();
|
}
|
|
|
|
protected override void OnAfterOpen()
|
{
|
CheckJumpToModel();
|
}
|
|
|
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();
|
}
|
}
|
|
protected override void OnPreClose()
|
{
|
shopCtrl.OnRefreshCell -= OnRefreshCell;
|
PlayerDatas.Instance.playerDataRefreshEvent -= OnPlayerDataRefreshEvent;
|
model.RefreshBuyShopLimitEvent -= RefreshStore;
|
|
}
|
|
protected override void OnAfterClose()
|
{
|
}
|
|
void RefreshStore()
|
{
|
shopCtrl.m_Scorller.RefreshActiveCellViews();
|
}
|
|
void OnRefreshCell(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<ActStoreCell>();
|
if (shoplist.Count >= cellCount)
|
{
|
shopCell.SetActive(true);
|
shopCell.SetDisplay(shoplist[cellCount - 1].storeConfig, selectedGoodId);
|
}
|
else
|
{
|
shopCell.SetActive(false);
|
}
|
}
|
}
|
|
void OnPlayerDataRefreshEvent(PlayerDataType type)
|
{
|
if (type == PlayerDataType.default34 || type == PlayerDataType.default37)
|
{
|
moneyText.text = UIHelper.GetMoneyCnt(model.rankActStore_MoneyType).ToString();
|
}
|
}
|
void Display()
|
{
|
OperationBase act;
|
OperationTimeHepler.Instance.TryGetOperation(model.rankActStore_ActType, out act);
|
actTimeText.text = Language.Get("BossFHLanguage2", act.ToDisplayTime());
|
|
moneyText.text = UIHelper.GetMoneyCnt(model.rankActStore_MoneyType).ToString();
|
moneyIcon.SetIconWithMoneyType(model.rankActStore_MoneyType);
|
shoplist = model.TryGetStoreDatas(model.storeFuncType);
|
if (shoplist == null)
|
{
|
DebugEx.Log("商店数据为空");
|
return;
|
}
|
|
shoplist.Sort(CmpStore);
|
|
shopCtrl.Refresh();
|
if (shoplist.Count > 0)
|
{
|
int remain = shoplist.Count % SingleLineCnt;
|
int line = (int)shoplist.Count / SingleLineCnt;
|
if (remain > 0)
|
{
|
line += 1;
|
}
|
|
for (int i = 0; i < line; i++)
|
{
|
shopCtrl.AddCell(ScrollerDataType.Header, i);
|
}
|
}
|
shopCtrl.Restart();
|
|
}
|
|
//售罄商品排在最后
|
int CmpStore(StoreModel.StoreData a, StoreModel.StoreData b)
|
{
|
bool isSellOutA = BuyItemController.Instance.IsSellOut(a.storeConfig.ID, 0);
|
bool isSellOutB = BuyItemController.Instance.IsSellOut(b.storeConfig.ID, 0);
|
|
if (isSellOutA != isSellOutB)
|
return isSellOutA.CompareTo(isSellOutB);
|
|
|
return a.storeConfig.ShopSort.CompareTo(b.storeConfig.ShopSort);
|
|
}
|
}
|
|
}
|
|
|
|
|