using System;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
|
namespace Snxxz.UI
|
{
|
public class XBStoreWin : Window
|
{
|
[SerializeField] ScrollerController shopCtrl;
|
[SerializeField] Toggle equipToggle;
|
[SerializeField] Toggle runeToggle;
|
[SerializeField] Toggle toolToggle;
|
[SerializeField] Text soreValueText;
|
|
List<StoreFunc> storeFuncEnables = new List<StoreFunc>();
|
|
StoreModel _storeModel;
|
StoreModel m_storeModel
|
{
|
get { return _storeModel ?? (_storeModel = ModelCenter.Instance.GetModel<StoreModel>()); }
|
}
|
|
List<StoreModel.StoreData> shoplist;
|
int SingleLineCnt = 2;
|
|
protected override void BindController()
|
{
|
shopCtrl.OnRefreshCell += RefreshShopCell;
|
shopCtrl.lockType = EnhanceLockType.KeepVertical;
|
}
|
|
protected override void AddListeners()
|
{
|
equipToggle.onValueChanged.AddListener((bool isOn) => { OnClickEquipToggle(isOn); });
|
runeToggle.onValueChanged.AddListener((bool isOn) => { OnClickRuneToggle(isOn); });
|
toolToggle.onValueChanged.AddListener((bool isOn) => { OnClickToolToggle(isOn); });
|
}
|
|
protected override void OnPreOpen()
|
{
|
m_storeModel.RefreshBuyShopLimitEvent += UpdateStore;
|
|
storeFuncEnables.Clear();
|
shoplist = m_storeModel.TryGetStoreDatas(StoreFunc.XBEquipStore);
|
if (shoplist.Count > 0)
|
{
|
storeFuncEnables.Add(StoreFunc.XBEquipStore);
|
}
|
shoplist = m_storeModel.TryGetStoreDatas(StoreFunc.XBToolStore);
|
if (shoplist.Count > 0)
|
{
|
storeFuncEnables.Add(StoreFunc.XBToolStore);
|
}
|
shoplist = m_storeModel.TryGetStoreDatas(StoreFunc.XBRuneStore);
|
if (shoplist.Count > 0)
|
{
|
storeFuncEnables.Add(StoreFunc.XBRuneStore);
|
}
|
|
equipToggle.SetActive(storeFuncEnables.Contains(StoreFunc.XBEquipStore));
|
runeToggle.SetActive(storeFuncEnables.Contains(StoreFunc.XBRuneStore));
|
toolToggle.SetActive(storeFuncEnables.Contains(StoreFunc.XBToolStore));
|
|
PlayerDatas.Instance.playerDataRefreshEvent += RefreshXBScore;
|
RefreshXBScore(PlayerDataType.CDBPlayerRefresh_TreasureScore);
|
if (m_storeModel.jumpStoreFuncType != 0
|
&& storeFuncEnables.Contains((StoreFunc)m_storeModel.jumpStoreFuncType))
|
{
|
m_storeModel.storeFuncType = (StoreFunc)m_storeModel.jumpStoreFuncType;
|
m_storeModel.jumpStoreFuncType = 0;
|
}
|
else
|
{
|
m_storeModel.storeFuncType = storeFuncEnables[0];
|
}
|
}
|
|
protected override void OnAfterOpen()
|
{
|
switch (m_storeModel.storeFuncType)
|
{
|
case StoreFunc.XBEquipStore:
|
equipToggle.isOn = true;
|
OnClickEquipToggle(true);
|
break;
|
case StoreFunc.XBRuneStore:
|
runeToggle.isOn = true;
|
OnClickRuneToggle(true);
|
break;
|
case StoreFunc.XBToolStore:
|
toolToggle.isOn = true;
|
OnClickToolToggle(true);
|
break;
|
}
|
|
}
|
|
protected override void OnPreClose()
|
{
|
m_storeModel.RefreshBuyShopLimitEvent -= UpdateStore;
|
PlayerDatas.Instance.playerDataRefreshEvent -= RefreshXBScore;
|
}
|
protected override void OnAfterClose()
|
{
|
|
}
|
|
private void RefreshXBScore(PlayerDataType refreshType)
|
{
|
if (refreshType != PlayerDataType.CDBPlayerRefresh_TreasureScore) return;
|
|
soreValueText.text = ItemLogicUtility.Instance.OnChangeCoinsUnit(UIHelper.GetMoneyCnt(25));
|
|
}
|
|
private void UpdateStore()
|
{
|
CreateShopCell();
|
}
|
|
private void OnClickToolToggle(bool isOn)
|
{
|
if (isOn)
|
{
|
m_storeModel.storeFuncType = StoreFunc.XBToolStore;
|
CreateShopCell();
|
}
|
}
|
|
private void OnClickRuneToggle(bool isOn)
|
{
|
if (isOn)
|
{
|
m_storeModel.storeFuncType = StoreFunc.XBRuneStore;
|
CreateShopCell();
|
}
|
}
|
|
private void OnClickEquipToggle(bool isOn)
|
{
|
if(isOn)
|
{
|
m_storeModel.storeFuncType = StoreFunc.XBEquipStore;
|
CreateShopCell();
|
}
|
}
|
|
private void CreateShopCell()
|
{
|
shopCtrl.Refresh();
|
List<StoreModel.StoreData> resultList = new List<StoreModel.StoreData>();
|
shoplist.Clear();
|
resultList = m_storeModel.TryGetStoreDatas(m_storeModel.storeFuncType);
|
|
//隐藏已售罄物品
|
int remainCnt = 0;
|
foreach(var item in resultList)
|
{
|
if (!_storeModel.TryGetIsSellOut(item.storeConfig, out remainCnt))
|
{
|
shoplist.Add(item);
|
}
|
}
|
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);
|
XBShopCell shopCell = cell.transform.GetChild(i).GetComponent<XBShopCell>();
|
if(shoplist.Count >= cellCount)
|
{
|
shopCell.SetActive(true);
|
shopCell.SetModel(shoplist[cellCount-1].storeConfig);
|
}
|
else
|
{
|
shopCell.SetActive(false);
|
}
|
}
|
}
|
|
}
|
}
|