using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
public class DanDrugRecycleTip : MonoBehaviour
|
{
|
[SerializeField] ScrollerController shopCtrl;
|
[SerializeField] Text sumMoneyText;
|
[SerializeField] ScrollerController danDrugCtrl;
|
[SerializeField] Text getMoneyText;
|
[SerializeField] Text _resetRefreshTimeText;
|
[SerializeField] Button recycleBtn;
|
[SerializeField] UIEffect uieffect;
|
[Header("回收丹药格子数")]
|
[SerializeField] int sumGridCnt = 45;
|
|
List<StoreModel.StoreData> shoplist;
|
int SingleLineCnt = 2;
|
StoreModel _storeModel;
|
StoreModel m_storeModel
|
{
|
get { return _storeModel ?? (_storeModel = ModelCenter.Instance.GetModel<StoreModel>()); }
|
}
|
PackModelInterface modelInterface { get { return ModelCenter.Instance.GetModel<PackModelInterface>(); } }
|
PlayerPackModel playerPack { get { return ModelCenter.Instance.GetModel<PlayerPackModel>(); } }
|
BlastFurnaceModel blastFurnace { get { return ModelCenter.Instance.GetModel<BlastFurnaceModel>(); } }
|
Dictionary<string, List<ItemModel>> recycleDict;
|
List<string> recycleKeylist;
|
private void OnEnable()
|
{
|
GlobalTimeEvent.Instance.secondEvent += RefreshResetTime;
|
blastFurnace.RefreshSelectRecycleAct += RefreshRecycleGetMoney;
|
danDrugCtrl.OnRefreshCell += RefreshRecycleDan;
|
shopCtrl.OnRefreshCell += RefreshShopCell;
|
m_storeModel.RefreshBuyShopLimitEvent += CreateShopCell;
|
m_storeModel.RefreshTCBPlayerDataEvent += RefreshRecycleScore;
|
blastFurnace.RefreshMakeItemAnswerAct += OnGetRecycleResult;
|
m_storeModel.storeFuncType = StoreFunc.DanDrugStore;
|
recycleBtn.AddListener(ClickRecycle);
|
playerPack.RefreshItemCountAct += RefreshItemCnt;
|
Init();
|
}
|
private void OnDisable()
|
{
|
shopCtrl.OnRefreshCell -= RefreshShopCell;
|
danDrugCtrl.OnRefreshCell -= RefreshRecycleDan;
|
m_storeModel.RefreshTCBPlayerDataEvent -= RefreshRecycleScore;
|
blastFurnace.RefreshSelectRecycleAct -= RefreshRecycleGetMoney;
|
blastFurnace.RefreshMakeItemAnswerAct -= OnGetRecycleResult;
|
playerPack.RefreshItemCountAct -= RefreshItemCnt;
|
m_storeModel.RefreshBuyShopLimitEvent -= CreateShopCell;
|
recycleBtn.RemoveAllListeners();
|
GlobalTimeEvent.Instance.secondEvent -= RefreshResetTime;
|
}
|
|
private void RefreshItemCnt(PackType type, int index, int id)
|
{
|
if (type != PackType.rptItem || !playerPack.CheckIsDrugById(id)) return;
|
CreateRecycleDan();
|
RefreshRecycleGetMoney();
|
}
|
|
private void Init()
|
{
|
CreateShopCell();
|
CreateRecycleDan();
|
RefreshRecycleScore(PlayerDataRefresh.CDBPlayerRefresh_Danjing);
|
RefreshRecycleGetMoney();
|
RefreshResetTime();
|
}
|
|
private void RefreshResetTime()
|
{
|
if (shoplist != null && shoplist.Count > 0)
|
{
|
if (shoplist[0].storeConfig.RefreshType == 0)
|
{
|
_resetRefreshTimeText.gameObject.SetActive(false);
|
}
|
else
|
{
|
_resetRefreshTimeText.gameObject.SetActive(true);
|
_resetRefreshTimeText.text = m_storeModel.GetStoreRefreshTimeByType(shoplist[0].storeConfig.RefreshType);
|
}
|
}
|
else
|
{
|
_resetRefreshTimeText.gameObject.SetActive(false);
|
}
|
}
|
|
|
private void OnGetRecycleResult(MakeType type, int result)
|
{
|
if (type != MakeType.Def_DanRecycle || result != 1) return;
|
|
uieffect.Play();
|
}
|
|
private void RefreshRecycleScore(PlayerDataRefresh refreshType)
|
{
|
if (refreshType != PlayerDataRefresh.CDBPlayerRefresh_Danjing) return;
|
|
sumMoneyText.text = UIHelper.GetMoneyCnt(27).ToString();
|
}
|
|
private void RefreshRecycleGetMoney()
|
{
|
getMoneyText.text = blastFurnace.GetRecycleMoney().ToString();
|
}
|
|
private void CreateShopCell()
|
{
|
shopCtrl.Refresh();
|
shoplist = m_storeModel.TryGetStoreDatas((int)m_storeModel.storeFuncType);
|
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);
|
DanDrugShopCell shopCell = cell.transform.GetChild(i).GetComponent<DanDrugShopCell>();
|
if (shoplist.Count >= cellCount)
|
{
|
shopCell.gameObject.SetActive(true);
|
shopCell.SetModel(shoplist[cellCount - 1].storeConfig);
|
}
|
else
|
{
|
shopCell.gameObject.SetActive(false);
|
}
|
}
|
}
|
|
private void CreateRecycleDan()
|
{
|
recycleDict = blastFurnace.GetLookRecycleDanlist();
|
recycleKeylist = recycleDict.Keys.ToList();
|
danDrugCtrl.Refresh();
|
int i = 0;
|
int line = (int)sumGridCnt / 3;
|
for (i = 0; i < line; i++)
|
{
|
danDrugCtrl.AddCell(ScrollerDataType.Header, i);
|
}
|
danDrugCtrl.Restart();
|
}
|
|
private void RefreshRecycleDan(ScrollerDataType type, CellView cell)
|
{
|
|
for(int i = 0; i < cell.transform.childCount; i++)
|
{
|
RecycleDrugCell drugCell = cell.transform.GetChild(i).GetComponent<RecycleDrugCell>();
|
int index = (cell.transform.childCount) * cell.index + i;
|
if(index <= recycleKeylist.Count - 1)
|
{
|
drugCell.SetDisplayModel(recycleDict[recycleKeylist[index]]);
|
}
|
else
|
{
|
drugCell.SetDisplayModel(null);
|
}
|
}
|
}
|
|
private void ClickRecycle()
|
{
|
blastFurnace.SetSelectRecycleDan();
|
}
|
|
}
|
|
}
|