using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
using System;
|
|
namespace vnxbqy.UI
|
{
|
public class NewYearCeremonyRechargeGiftWin : Window
|
{
|
[SerializeField] Button receiveBtn;
|
[SerializeField] Button rechargeBtn;
|
[SerializeField] Text receiveBtnText;
|
[SerializeField] Image receiveBtnImg;
|
[SerializeField] Text remainTimeText;
|
[SerializeField] List<CommonItemBaisc> itemBaiscs = new List<CommonItemBaisc>();
|
|
List<NewYearFairylandCeremonyModel.AwardItem> itemlist;
|
NewYearFairylandCeremonyModel ceremonyModel { get { return ModelCenter.Instance.GetModel<NewYearFairylandCeremonyModel>(); } }
|
PackModel playerPack { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
|
protected override void BindController()
|
{
|
|
}
|
|
protected override void AddListeners()
|
{
|
rechargeBtn.AddListener(ClickRecharge);
|
receiveBtn.AddListener(OnReceiveGift);
|
}
|
|
protected override void OnPreOpen()
|
{
|
GlobalTimeEvent.Instance.secondEvent += RefreshSecond;
|
ceremonyModel.RefreshRechargeStateAct += SetReceiveBtnState;
|
itemlist = ceremonyModel.GetRechargeAwardByLv();
|
Init();
|
}
|
|
protected override void OnAfterOpen()
|
{
|
|
}
|
|
protected override void OnPreClose()
|
{
|
GlobalTimeEvent.Instance.secondEvent -= RefreshSecond;
|
ceremonyModel.RefreshRechargeStateAct -= SetReceiveBtnState;
|
}
|
|
protected override void OnAfterClose()
|
{
|
|
}
|
|
private void Init()
|
{
|
if (itemlist == null) return;
|
|
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);
|
}
|
}
|
RefreshSecond();
|
SetReceiveBtnState();
|
}
|
|
|
private void RefreshSecond()
|
{
|
int seconds = OperationTimeHepler.Instance.GetOperationSurplusTime(Operation.NewYearFairyCeremony);
|
if (seconds > 0)
|
{
|
remainTimeText.text = StringUtility.Contact("<color=#8DDC11FF>", TimeUtility.SecondsToHMS(seconds), "</color>");
|
}
|
else
|
{
|
remainTimeText.text = UIHelper.AppendColor(TextColType.Red, Language.Get("XMZZ110"));
|
}
|
}
|
|
private void SetReceiveBtnState()
|
{
|
switch (ceremonyModel.receiveState)
|
{
|
case NewYearFairylandCeremonyModel.ReceiveState.NoReach:
|
receiveBtnImg.material = MaterialUtility.GetDefaultSpriteGrayMaterial();
|
receiveBtnText.text = Language.Get("AccumulateRecharge_GetReward");
|
break;
|
case NewYearFairylandCeremonyModel.ReceiveState.Reach:
|
receiveBtnImg.material = MaterialUtility.GetUIDefaultGraphicMaterial();
|
receiveBtnText.text = Language.Get("AccumulateRecharge_GetReward");
|
break;
|
case NewYearFairylandCeremonyModel.ReceiveState.Already:
|
receiveBtnImg.material = MaterialUtility.GetDefaultSpriteGrayMaterial();
|
receiveBtnText.text = Language.Get("Z1044");
|
break;
|
}
|
}
|
|
private void OnReceiveGift()
|
{
|
if (itemlist == null) return;
|
|
switch (ceremonyModel.receiveState)
|
{
|
case NewYearFairylandCeremonyModel.ReceiveState.NoReach:
|
SysNotifyMgr.Instance.ShowTip("FairylandCermonyRecharge1");
|
break;
|
case NewYearFairylandCeremonyModel.ReceiveState.Reach:
|
bool isGrid = playerPack.GetEmptyGridCount(PackType.Item) - itemlist.Count >= 0 ? true : false;
|
if (isGrid)
|
{
|
ceremonyModel.SendReceiveAward(GotServerRewardType.Def_RewardType_NewFairyCRecharge, 0);
|
}
|
else
|
{
|
SysNotifyMgr.Instance.ShowTip("BagFull");
|
}
|
break;
|
case NewYearFairylandCeremonyModel.ReceiveState.Already:
|
SysNotifyMgr.Instance.ShowTip("FairylandCermonyRecharge2");
|
break;
|
}
|
}
|
|
private void ClickRecharge()
|
{
|
WindowJumpMgr.Instance.WindowJumpTo(JumpUIType.VipRechargeFunc1);
|
}
|
}
|
}
|