using System; using System.Collections.Generic; using TableConfig; using UnityEngine; using UnityEngine.UI; namespace Snxxz.UI { public class ToHiAwardCell : CellView { [SerializeField] Text titleText; [SerializeField] Button receiveBtn; [SerializeField] GameObject noReachImg; [SerializeField] GameObject alreadyImg; [SerializeField] List itemBaiscs = new List(); List itemlist; ItemTipsModel tipsModel { get { return ModelCenter.Instance.GetModel(); } } FairylandCeremonyModel.ReceiveState receiveState = FairylandCeremonyModel.ReceiveState.NoReach; PlayerPackModel playerPack { get { return ModelCenter.Instance.GetModel(); } } FairylandCeremonyModel ceremonyModel { get { return ModelCenter.Instance.GetModel(); } } AllPeoplePartyAwardConfig awardConfig; private void OnEnable() { ceremonyModel.RefreshHiAwardStateAct += SetAwardState; } private void OnDisable() { ceremonyModel.RefreshHiAwardStateAct -= SetAwardState; } public void Init(AllPeoplePartyAwardConfig 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].gameObject.SetActive(true); FairylandCeremonyModel.AwardItem itemData = itemlist[i]; ItemCellModel cellModel = new ItemCellModel(itemData.itemId, true,(ulong)itemData.itemCount, itemData.isBind); itemBaiscs[i].Init(cellModel); itemBaiscs[i].cellBtn.RemoveAllListeners(); itemBaiscs[i].cellBtn.AddListener(() => { ItemAttrData attrData = new ItemAttrData(itemData.itemId, true, (ulong)itemData.itemCount,-1,itemData.isBind); tipsModel.SetItemTipsModel(attrData); }); } else { itemBaiscs[i].gameObject.SetActive(false); } } SetAwardState(); } private void SetAwardState() { if (awardConfig == null) return; if(ceremonyModel.GetPeopleAwardRecordByIndex(awardConfig.Index)) { receiveState = FairylandCeremonyModel.ReceiveState.Already; } else { if(ceremonyModel.sumHiPoint >= awardConfig.NeedPoint) { receiveState = FairylandCeremonyModel.ReceiveState.Reach; } else { receiveState = FairylandCeremonyModel.ReceiveState.NoReach; } } RefreshAwardStateUI(); } private void RefreshAwardStateUI() { receiveBtn.RemoveAllListeners(); switch (receiveState) { case FairylandCeremonyModel.ReceiveState.NoReach: noReachImg.SetActive(true); alreadyImg.SetActive(false); receiveBtn.gameObject.SetActive(false); break; case FairylandCeremonyModel.ReceiveState.Reach: noReachImg.SetActive(false); alreadyImg.SetActive(false); receiveBtn.gameObject.SetActive(true); receiveBtn.AddListener(OnReceiveGift); break; case FairylandCeremonyModel.ReceiveState.Already: noReachImg.SetActive(false); alreadyImg.SetActive(true); receiveBtn.gameObject.SetActive(false); break; } } private void OnReceiveGift() { bool isGrid = playerPack.GetReaminGridCount(PackType.rptItem) - itemlist.Count >= 0 ? true : false; if (isGrid) { ceremonyModel.SendReceiveAward(GotServerRewardType.Def_RewardType_FCParty, awardConfig.Index); } else { SysNotifyMgr.Instance.ShowTip("BagFull"); } } } }