using UnityEngine;
|
using UnityEngine.UI;
|
|
using System;
|
using vnxbqy.UI;
|
|
public class MergeServerFlashRushToBuyItemCell : ILBehaviour
|
{
|
CommonItemBaisc itemBaisc;
|
Text originalPrice;
|
Image originalMoneyIcon;
|
Text presentPrice;
|
Image presentMoneyIcon;
|
Image stateImg;
|
Button flashSaleBtn;
|
Image btnBgImg;
|
Text btnStateText;
|
Text cdText;
|
Text fullServerRemainNum;
|
Text personalRemainNum;
|
public const int RefreshFullServerBuyType = 8;
|
|
MergeServerFlashRushToBuyModel rushToBuyModel = MergeServerFlashRushToBuyModel.Instance;
|
StoreModel storeModel { get { return ModelCenter.Instance.GetModelEx<StoreModel>(); } }
|
|
|
OperationFlashRushToBuy.FlashSaleItem saleItem;
|
int buyState = -1;
|
int cdTime = 0;
|
int code = 0;
|
protected override void Awake()
|
{
|
itemBaisc = proxy.GetWidgtEx<CommonItemBaisc>("Item");
|
originalPrice = proxy.GetWidgtEx<Text>("originalPrice");
|
originalMoneyIcon = proxy.GetWidgtEx<Image>("originalIcon");
|
presentPrice = proxy.GetWidgtEx<Text>("presentPrice");
|
presentMoneyIcon = proxy.GetWidgtEx<Image>("presentIcon");
|
stateImg = proxy.GetWidgtEx<Image>("Img_Complete");
|
flashSaleBtn = proxy.GetWidgtEx<Button>("Btn_Buy");
|
btnBgImg = proxy.GetWidgtEx<Image>("Btn_BuyImg");
|
btnStateText = proxy.GetWidgtEx<Text>("BuyStateText");
|
cdText = proxy.GetWidgtEx<Text>("CDText");
|
fullServerRemainNum = proxy.GetWidgtEx<Text>("FullTxt_CostValue");
|
personalRemainNum = proxy.GetWidgtEx<Text>("PersonalTxt_CostValue");
|
}
|
|
protected override void OnEnable()
|
{
|
rushToBuyModel.UpdateAppointmentEvent += UpdateAppointmentInfo;
|
KnapsackTimeCDMgr.Instance.RefreshNormalCDAct += RefreshCD;
|
rushToBuyModel.UpdateFullSeverBuyEvent += UpdateFullServerBuy;
|
}
|
|
protected override void OnDisable()
|
{
|
rushToBuyModel.UpdateAppointmentEvent -= UpdateAppointmentInfo;
|
KnapsackTimeCDMgr.Instance.RefreshNormalCDAct -= RefreshCD;
|
rushToBuyModel.UpdateFullSeverBuyEvent -= UpdateFullServerBuy;
|
}
|
|
|
private void UpdateFullServerBuy(int shopId)
|
{
|
if (saleItem == null || saleItem.shopId != shopId) return;
|
UpdateSaleItemSellState();
|
}
|
|
|
|
private void UpdateAppointmentInfo(int shopGuid)
|
{
|
if (saleItem == null || shopGuid != saleItem.shopGuid) return;
|
|
if (saleItem.isAppointment == 1)
|
{
|
cdTime = 10;
|
KnapsackTimeCDMgr.Instance.Register(this.code, cdTime);
|
}
|
UpdateSaleItem();
|
}
|
|
public void SetDisplayModel(int index)
|
{
|
if (rushToBuyModel.presentFlashShop == null) return;
|
|
saleItem = rushToBuyModel.presentFlashShop.items[index];
|
code = rushToBuyModel.presentFlashShop.dayIndex * 1000 + rushToBuyModel.presentFlashShop.timeIndex * 100 + index;
|
ItemCellModel cellModel = new ItemCellModel(saleItem.itemId,true,(ulong)saleItem.itemCount);
|
itemBaisc.Init(cellModel);
|
itemBaisc.button.RemoveAllListeners();
|
itemBaisc.button.AddListener(()=>
|
{
|
ItemTipUtility.Show(saleItem.itemId);
|
});
|
originalMoneyIcon.SetIconWithMoneyType(saleItem.moneyType);
|
presentMoneyIcon.SetIconWithMoneyType(saleItem.moneyType);
|
originalPrice.text = saleItem.moneyOriginal.ToString();
|
presentPrice.text = saleItem.moneyNumber.ToString();
|
UpdateSaleItem();
|
UpdateSaleItemSellState();
|
}
|
|
private void UpdateSaleItem()
|
{
|
if (rushToBuyModel.presentFlashShop == null) return;
|
|
flashSaleBtn.RemoveAllListeners();
|
var operation = rushToBuyModel.GetOperationFlashRushToBuy();
|
int seconds = 0;
|
buyState = operation.GetBuyTimeState(TimeUtility.ServerNow,rushToBuyModel.presentFlashShop.dayIndex,
|
rushToBuyModel.presentFlashShop.timeIndex,out seconds);
|
|
btnBgImg.SetSprite("SecondBtn1");
|
btnStateText.SetActiveIL(true);
|
cdText.SetActiveIL(false);
|
btnBgImg.material = MaterialUtility.GetUIDefaultGraphicMaterial();
|
switch (buyState)
|
{
|
case -1:
|
if(saleItem.isAppointment == 0)
|
{
|
btnStateText.text = Language.Get("FlashRushToBuy101");
|
flashSaleBtn.AddListener(() => { rushToBuyModel.SendFlashSaleAppointment(saleItem.shopGuid, 1); });
|
}
|
else
|
{
|
btnBgImg.SetSprite("BlackBtn");
|
RefreshCD(code, KnapsackTimeCDMgr.Instance.GetNormalCDTime(code));
|
btnStateText.SetActiveIL(false);
|
cdText.SetActiveIL(true);
|
flashSaleBtn.AddListener(CancelAppointment);
|
}
|
break;
|
case 0:
|
btnStateText.text = Language.Get("FlashRushToBuy102");
|
flashSaleBtn.AddListener(SendBuyShopItem);
|
break;
|
}
|
}
|
|
public void SendBuyShopItem()
|
{
|
if (saleItem == null) return;
|
|
if(UIHelper.GetMoneyCnt(saleItem.moneyType) >= (ulong)saleItem.moneyNumber)
|
{
|
CA310_tagCMBuyItem buyShop = new CA310_tagCMBuyItem();
|
buyShop.BuyItemIndex = (ushort)saleItem.shopId;
|
buyShop.BuyCount = 1;
|
GameNetSystem.Instance.SendInfo(buyShop);
|
}
|
else
|
{
|
WindowCenter.Instance.Open<RechargeTipWin>();
|
}
|
}
|
|
private void RefreshCD(int code,int time)
|
{
|
if (this.code != code) return;
|
|
cdTime = time;
|
if (cdTime <= 0)
|
{
|
btnBgImg.material = MaterialUtility.GetUIDefaultGraphicMaterial();
|
cdText.text = Language.Get("FlashRushToBuy103");
|
}
|
else
|
{
|
btnBgImg.material = MaterialUtility.GetDefaultSpriteGrayMaterial();
|
cdText.text = Language.Get("FlashRushToBuy104",time);
|
}
|
}
|
|
private void CancelAppointment()
|
{
|
if(cdTime == 0)
|
{
|
rushToBuyModel.SendFlashSaleAppointment(saleItem.shopGuid, 0);
|
}
|
else
|
{
|
|
}
|
|
}
|
|
private void UpdateSaleItemSellState()
|
{
|
int fullSeverRemain = 0;
|
int personalRemain = 0;
|
int sellState = GetSellSate(out fullSeverRemain,out personalRemain);
|
string fullSeverRemainStr = fullSeverRemain > 0 ? UIHelper.AppendColor(TextColType.Green, fullSeverRemain.ToString(),true) : UIHelper.AppendColor(TextColType.Red, fullSeverRemain.ToString());
|
string personalRemainStr = personalRemain > 0 ? UIHelper.AppendColor(TextColType.Green, personalRemain.ToString(),true) : UIHelper.AppendColor(TextColType.Red, personalRemain.ToString());
|
fullServerRemainNum.text = fullSeverRemainStr;
|
personalRemainNum.text = personalRemainStr;
|
switch (sellState)
|
{
|
case 0:
|
stateImg.SetActiveIL(false);
|
flashSaleBtn.SetActiveIL(true);
|
break;
|
case 1:
|
stateImg.SetActiveIL(true);
|
stateImg.SetSprite("XT_KF_80");
|
flashSaleBtn.SetActiveIL(false);
|
break;
|
case 2:
|
stateImg.SetActiveIL(true);
|
stateImg.SetSprite("XT_KF_81");
|
flashSaleBtn.SetActiveIL(false);
|
break;
|
}
|
|
}
|
/// <summary>
|
/// 0 秒杀 1个人购买次数已用光 2 全服已抢光
|
/// </summary>
|
/// <returns></returns>
|
private int GetSellSate(out int fullRemainNum,out int personalRemainNum)
|
{
|
fullRemainNum = 0;
|
personalRemainNum = 0;
|
var buyInfo = storeModel.GetBuyShopLimit((uint)saleItem.shopId);
|
if (buyState != -1)
|
{
|
personalRemainNum = saleItem.limitNum;
|
fullRemainNum = saleItem.fullServerLimitNum - rushToBuyModel.GetFullServerBuyCntById(saleItem.shopId);
|
if (buyInfo != null)
|
{
|
personalRemainNum -= buyInfo.BuyCnt;
|
}
|
if (personalRemainNum <= 0)
|
{
|
personalRemainNum = 0;
|
return 1;
|
}
|
|
if (fullRemainNum <= 0)
|
{
|
fullRemainNum = 0;
|
return 2;
|
}
|
}
|
else
|
{
|
personalRemainNum = saleItem.limitNum;
|
fullRemainNum = saleItem.fullServerLimitNum;
|
}
|
return 0;
|
}
|
}
|