using System;
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace vnxbqy.UI
|
{
|
|
public class NewYearToHiAwardCell : CellView
|
{
|
[SerializeField] Text titleText;
|
[SerializeField] Button receiveBtn;
|
[SerializeField] GameObject noReachImg;
|
[SerializeField] GameObject alreadyImg;
|
[SerializeField] List<CommonItemBaisc> itemBaiscs = new List<CommonItemBaisc>();
|
|
List<NewYearFairylandCeremonyModel.AwardItem> itemlist;
|
|
NewYearFairylandCeremonyModel.ReceiveState receiveState = NewYearFairylandCeremonyModel.ReceiveState.NoReach;
|
PackModel playerPack { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
NewYearFairylandCeremonyModel ceremonyModel { get { return ModelCenter.Instance.GetModel<NewYearFairylandCeremonyModel>(); } }
|
NewAllPeoplePartyAwardConfig awardConfig;
|
|
private void OnEnable()
|
{
|
ceremonyModel.RefreshHiAwardStateAct += SetAwardState;
|
}
|
|
private void OnDisable()
|
{
|
ceremonyModel.RefreshHiAwardStateAct -= SetAwardState;
|
}
|
public void Init(NewAllPeoplePartyAwardConfig awardConfig)
|
{
|
this.awardConfig = awardConfig;
|
titleText.text = Language.Get("CeremoneyToHiAward", awardConfig.NeedPoint);
|
itemlist = ceremonyModel.GetPeoplePartyAwardById(awardConfig.ID);
|
for (int i = 0; i < itemBaiscs.Count; i++)
|
{
|
if (i < itemlist.Count)
|
{
|
itemBaiscs[i].SetActive(true);
|
NewYearFairylandCeremonyModel.AwardItem itemData = itemlist[i];
|
ItemCellModel cellModel = new ItemCellModel(itemData.itemId, true,(ulong)itemData.itemCount);
|
itemBaiscs[i].Init(cellModel);
|
itemBaiscs[i].button.RemoveAllListeners();
|
itemBaiscs[i].button.AddListener(() =>
|
{
|
ItemTipUtility.Show(itemData.itemId);
|
});
|
}
|
else
|
{
|
itemBaiscs[i].SetActive(false);
|
}
|
}
|
|
SetAwardState();
|
}
|
|
private void SetAwardState()
|
{
|
if (awardConfig == null) return;
|
|
if(ceremonyModel.GetPeopleAwardRecordByIndex(awardConfig.Index))
|
{
|
receiveState = NewYearFairylandCeremonyModel.ReceiveState.Already;
|
}
|
else
|
{
|
if(ceremonyModel.sumHiPoint >= awardConfig.NeedPoint)
|
{
|
receiveState = NewYearFairylandCeremonyModel.ReceiveState.Reach;
|
}
|
else
|
{
|
receiveState = NewYearFairylandCeremonyModel.ReceiveState.NoReach;
|
}
|
}
|
RefreshAwardStateUI();
|
}
|
|
private void RefreshAwardStateUI()
|
{
|
receiveBtn.RemoveAllListeners();
|
switch (receiveState)
|
{
|
case NewYearFairylandCeremonyModel.ReceiveState.NoReach:
|
noReachImg.SetActive(true);
|
alreadyImg.SetActive(false);
|
receiveBtn.SetActive(false);
|
break;
|
case NewYearFairylandCeremonyModel.ReceiveState.Reach:
|
noReachImg.SetActive(false);
|
alreadyImg.SetActive(false);
|
receiveBtn.SetActive(true);
|
receiveBtn.AddListener(OnReceiveGift);
|
break;
|
case NewYearFairylandCeremonyModel.ReceiveState.Already:
|
noReachImg.SetActive(false);
|
alreadyImg.SetActive(true);
|
receiveBtn.SetActive(false);
|
break;
|
}
|
}
|
|
private void OnReceiveGift()
|
{
|
bool isGrid = playerPack.GetEmptyGridCount(PackType.Item) - itemlist.Count >= 0 ? true : false;
|
if (isGrid)
|
{
|
ceremonyModel.SendReceiveAward(GotServerRewardType.Def_RewardType_NewFairyCParty, awardConfig.Index);
|
}
|
else
|
{
|
SysNotifyMgr.Instance.ShowTip("BagFull");
|
}
|
}
|
|
}
|
}
|