//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Thursday, April 18, 2019
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace vnxbqy.UI
|
{
|
public class FairyAffinityRechargeGiftActWin : Window
|
{
|
[SerializeField] Text buyCountGiftText;
|
[SerializeField] Slider buyCountGiftSlider;
|
[SerializeField] Text buyCountGiftSliderText;
|
|
[SerializeField] List<ItemCell> freeItems;
|
[SerializeField] List<RotationTween> freeTweenList = new List<RotationTween>();
|
[SerializeField] List<ImageEx> freeGreys;
|
[SerializeField] List<ImageEx> freeLocks;
|
[SerializeField] List<ImageEx> freeHaves;
|
|
[SerializeField] List<ItemCell> buyCountGiftItems;
|
[SerializeField] List<RotationTween> buyCountGiftTweenList = new List<RotationTween>();
|
[SerializeField] List<ImageEx> buyCountGiftGreys;
|
[SerializeField] List<ImageEx> buyCountGiftLocks;
|
[SerializeField] List<ImageEx> buyCountGiftHaves;
|
|
[SerializeField] ScrollerController m_Controller;
|
[SerializeField] Text actTime;
|
FairyAffinityRechargeGiftActModel model { get { return ModelCenter.Instance.GetModel<FairyAffinityRechargeGiftActModel>(); } }
|
VipModel vipModel { get { return ModelCenter.Instance.GetModel<VipModel>(); } }
|
|
StoreModel storeModel { get { return ModelCenter.Instance.GetModel<StoreModel>(); } }
|
|
#region Built-in
|
|
int curValue = 0;
|
|
private void OnEnable()
|
{
|
model.PlayAnimationSync += OnPlaySyncAnimation;
|
if (curValue == 0)
|
return;
|
OperationRechargeGiftAct act;
|
OperationTimeHepler.Instance.TryGetOperation(FairyAffinityRechargeGiftActModel.operaType, out act);
|
if (act == null) return;
|
int awardShowIndex = GetAwardShowIndex();
|
var awardInfo = act.buyCountGifts[awardShowIndex];
|
int freeState = model.GetBuyGiftState(0);
|
int cntState = model.GetBuyGiftState(awardInfo.NeedBuyCount);
|
|
for (int i = 0; i < freeTweenList.Count; i++)
|
{
|
freeTweenList[i].Stop();
|
freeTweenList[i].SetStartState();
|
}
|
for (int i = 0; i < buyCountGiftTweenList.Count; i++)
|
{
|
buyCountGiftTweenList[i].Stop();
|
buyCountGiftTweenList[i].SetStartState();
|
}
|
|
if (freeState == 1)
|
{
|
for (int i = 0; i < freeTweenList.Count; i++)
|
{
|
freeTweenList[i].Play();
|
}
|
}
|
|
if (cntState == 1)
|
{
|
for (int i = 0; i < buyCountGiftTweenList.Count; i++)
|
{
|
buyCountGiftTweenList[i].Play();
|
}
|
}
|
}
|
|
private void OnDisable()
|
{
|
model.PlayAnimationSync -= OnPlaySyncAnimation;
|
}
|
|
protected override void BindController()
|
{
|
}
|
|
protected override void AddListeners()
|
{
|
}
|
|
protected override void OnPreOpen()
|
{
|
m_Controller.OnRefreshCell += OnRefreshCell;
|
model.UpdateRechargeGiftActEvent += DisplayAward;
|
GlobalTimeEvent.Instance.secondEvent += secondEvent;
|
vipModel.rechargeCountEvent += VipModel_rechargeCountEvent;
|
storeModel.RefreshBuyShopLimitEvent += RefreshBuyShopLimitEvent;
|
|
DisplayScroll();
|
DisplayAward();
|
secondEvent();
|
}
|
|
private void VipModel_rechargeCountEvent(int obj)
|
{
|
m_Controller.m_Scorller.RefreshActiveCellViews();
|
DisplayAward();
|
model.IsPlayAnimation = true;
|
}
|
|
protected override void OnAfterOpen()
|
{
|
model.IsPlayAnimation = true;
|
for (int i = 0; i < freeTweenList.Count; i++)
|
{
|
freeTweenList[i].Stop();
|
freeTweenList[i].SetStartState();
|
}
|
for (int i = 0; i < buyCountGiftTweenList.Count; i++)
|
{
|
buyCountGiftTweenList[i].Stop();
|
buyCountGiftTweenList[i].SetStartState();
|
}
|
OperationRechargeGiftAct act;
|
OperationTimeHepler.Instance.TryGetOperation(FairyAffinityRechargeGiftActModel.operaType, out act);
|
if (act == null) return;
|
int awardShowIndex = GetAwardShowIndex();
|
var awardInfo = act.buyCountGifts[awardShowIndex];
|
int freeState = model.GetBuyGiftState(0);
|
int cntState = model.GetBuyGiftState(awardInfo.NeedBuyCount);
|
|
for (int i = 0; i < freeTweenList.Count; i++)
|
{
|
if (freeTweenList[i].isActiveAndEnabled && freeState == 1)
|
{
|
freeTweenList[i].Play();
|
}
|
}
|
|
for (int i = 0; i < buyCountGiftTweenList.Count; i++)
|
{
|
if (buyCountGiftTweenList[i].isActiveAndEnabled && cntState == 1)
|
{
|
buyCountGiftTweenList[i].Play();
|
}
|
}
|
}
|
|
protected override void OnPreClose()
|
{
|
m_Controller.OnRefreshCell -= OnRefreshCell;
|
model.UpdateRechargeGiftActEvent -= DisplayAward;
|
GlobalTimeEvent.Instance.secondEvent -= secondEvent;
|
vipModel.rechargeCountEvent -= VipModel_rechargeCountEvent;
|
storeModel.RefreshBuyShopLimitEvent -= RefreshBuyShopLimitEvent;
|
}
|
|
protected override void OnAfterClose()
|
{
|
}
|
|
#endregion
|
|
private void RefreshBuyShopLimitEvent()
|
{
|
m_Controller.m_Scorller.RefreshActiveCellViews();
|
}
|
|
private void DisplayScroll()
|
{
|
m_Controller.Refresh();
|
OperationRechargeGiftAct act;
|
OperationTimeHepler.Instance.TryGetOperation(FairyAffinityRechargeGiftActModel.operaType, out act);
|
if (act == null) return;
|
List<StoreConfig> _list = null;
|
StoreConfig.TryGetStoreConfigs(act.shopType, out _list);
|
|
int totaleCnt = (_list == null ? 0 : _list.Count) + act.ctgIDs.Count;
|
|
for (int i = 0; i < totaleCnt; i++)
|
{
|
m_Controller.AddCell(ScrollerDataType.Header, i);
|
}
|
m_Controller.Restart();
|
m_Controller.m_Scorller.RefreshActiveCellViews();
|
m_Controller.JumpIndex(GetDefaultSelect());
|
|
//取一档商品识别 是否有商品的每日重置,与活动的每日重置判断显示
|
//var config = CTGConfig.Get(act.ctgIDs[0]);
|
//resetTip.SetActive(!act.dayReset && config.DailyBuyCount != 0);
|
}
|
|
private void DisplayAward()
|
{
|
OperationRechargeGiftAct act;
|
OperationTimeHepler.Instance.TryGetOperation(FairyAffinityRechargeGiftActModel.operaType, out act);
|
if (act == null)
|
return;
|
var awardInfo = act.buyCountGifts[0];
|
var awards = awardInfo.AwardItemList;
|
int freeState = model.GetBuyGiftState(0);
|
|
|
for (int i = 0; i < freeItems.Count; i++)
|
{
|
if (i < awards.Length)
|
{
|
var award = awards[i];
|
freeItems[i].SetActive(true);
|
var itemData = new ItemCellModel((int)award.ItemID, false, award.ItemCount);
|
freeItems[i].Init(itemData);
|
int index = i;
|
freeItems[i].button.SetListener(() =>
|
{
|
if (freeState == 1)
|
{
|
model.SendGetAward(0);
|
}
|
else
|
{
|
ItemTipUtility.Show((int)award.ItemID);
|
}
|
});
|
freeGreys[i].SetActive(freeState == 0 || freeState == 2);
|
freeLocks[i].SetActive(freeState == 0);
|
freeHaves[i].SetActive(freeState == 2);
|
}
|
else
|
{
|
freeItems[i].SetActive(false);
|
freeGreys[i].SetActive(false);
|
freeLocks[i].SetActive(false);
|
freeHaves[i].SetActive(false);
|
}
|
}
|
|
int awardShowIndex = GetAwardShowIndex();
|
awardInfo = act.buyCountGifts[awardShowIndex];
|
int cntState = model.GetBuyGiftState(awardInfo.NeedBuyCount);
|
awards = awardInfo.AwardItemList;
|
for (int i = 0; i < buyCountGiftItems.Count; i++)
|
{
|
if (i < awards.Length)
|
{
|
var award = awards[i];
|
buyCountGiftItems[i].SetActive(true);
|
var itemData = new ItemCellModel((int)award.ItemID, false, award.ItemCount);
|
buyCountGiftItems[i].Init(itemData);
|
int index = i;
|
buyCountGiftItems[i].button.SetListener(() =>
|
{
|
if (cntState == 1)
|
{
|
model.SendGetAward(awardInfo.NeedBuyCount);
|
}
|
else
|
{
|
ItemTipUtility.Show((int)award.ItemID);
|
}
|
});
|
buyCountGiftGreys[i].SetActive(cntState == 0 || cntState == 2);
|
buyCountGiftLocks[i].SetActive(cntState == 0);
|
buyCountGiftHaves[i].SetActive(cntState == 2);
|
}
|
else
|
{
|
buyCountGiftItems[i].SetActive(false);
|
buyCountGiftGreys[i].SetActive(false);
|
buyCountGiftLocks[i].SetActive(false);
|
buyCountGiftHaves[i].SetActive(false);
|
}
|
}
|
|
int totalBuyCnt = model.GetBuyTotalCnt();
|
int needBuyCount = awardInfo.NeedBuyCount;
|
buyCountGiftSlider.value = totalBuyCnt / (float)needBuyCount;
|
buyCountGiftSliderText.text = string.Format("{0}/{1}", totalBuyCnt,needBuyCount);
|
buyCountGiftText.text = Language.Get("FairyAffinity11", Mathf.Max(0, needBuyCount));
|
|
model.IsPlayAnimation = true;
|
}
|
|
|
private void OnRefreshCell(ScrollerDataType type, CellView cell)
|
{
|
if (type != ScrollerDataType.Header) return;
|
|
var _cell = cell as FairyAffinityRechargeGiftActCell;
|
|
_cell.Display(_cell.index);
|
}
|
|
private int GetDefaultSelect()
|
{
|
OperationRechargeGiftAct act;
|
OperationTimeHepler.Instance.TryGetOperation(FairyAffinityRechargeGiftActModel.operaType, out act);
|
if (act == null) return 0;
|
List<StoreConfig> _list = null;
|
StoreConfig.TryGetStoreConfigs(act.shopType, out _list);
|
|
int storeCnt = _list == null ? 0 : _list.Count;
|
|
for (int i = 0; i < storeCnt; i++)
|
{
|
int remainNum;
|
storeModel.TryGetIsSellOut(_list[i], out remainNum);
|
if (remainNum > 0)
|
return i;
|
}
|
|
//跳过已购买
|
for (int i = 0; i < act.ctgIDs.Count; i++)
|
{
|
int ctgID = act.ctgIDs[i];
|
var countInfo = model.GetBuyCntInfo(ctgID);
|
|
if (countInfo.x < countInfo.y)
|
return i + storeCnt;
|
}
|
return 0;
|
}
|
|
private void secondEvent()
|
{
|
|
actTime.text = Language.Get("FairyAffinity10", TimeUtility.SecondsToDHMSCHS(GetTime()));
|
}
|
|
public int GetTime()
|
{
|
OperationRechargeGiftAct act;
|
OperationTimeHepler.Instance.TryGetOperation(FairyAffinityRechargeGiftActModel.operaType, out act);
|
if (act == null)
|
return 0;
|
int seconds;
|
switch (act.resetType)
|
{
|
case 0:
|
{
|
DateTime endOperationTime = new DateTime(TimeUtility.Year, TimeUtility.Month,
|
TimeUtility.Day, 0, 0, 0);
|
endOperationTime = endOperationTime.AddDays(1);
|
seconds = (int)(endOperationTime - TimeUtility.ServerNow).TotalSeconds;
|
}
|
break;
|
case 1:
|
{
|
DateTime endOperationTime = new DateTime(TimeUtility.Year, TimeUtility.Month,
|
TimeUtility.Day, 5, 0, 0);
|
endOperationTime = endOperationTime.AddDays(1);
|
seconds = (int)(endOperationTime - TimeUtility.ServerNow).TotalSeconds;
|
}
|
break;
|
default:
|
return 0;
|
}
|
return seconds;
|
}
|
|
private int GetAwardShowIndex()
|
{
|
OperationRechargeGiftAct act;
|
OperationTimeHepler.Instance.TryGetOperation(FairyAffinityRechargeGiftActModel.operaType, out act);
|
if (act == null) return 0;
|
|
for (int i = 1; i < act.buyCountGifts.Count; i++)
|
{
|
if (model.GetBuyGiftState(act.buyCountGifts[i].NeedBuyCount) != 2)
|
{
|
return i;
|
}
|
}
|
return act.buyCountGifts.Count - 1;
|
}
|
|
private void OnPlaySyncAnimation()
|
{
|
for (int i = 0; i < freeTweenList.Count; i++)
|
{
|
freeTweenList[i].Stop();
|
freeTweenList[i].SetStartState();
|
}
|
for (int i = 0; i < buyCountGiftTweenList.Count; i++)
|
{
|
buyCountGiftTweenList[i].Stop();
|
buyCountGiftTweenList[i].SetStartState();
|
}
|
OperationRechargeGiftAct act;
|
OperationTimeHepler.Instance.TryGetOperation(FairyAffinityRechargeGiftActModel.operaType, out act);
|
if (act == null) return ;
|
int awardShowIndex = GetAwardShowIndex();
|
var awardInfo = act.buyCountGifts[awardShowIndex];
|
int freeState = model.GetBuyGiftState(0);
|
int cntState = model.GetBuyGiftState(awardInfo.NeedBuyCount);
|
|
for (int i = 0; i < freeTweenList.Count; i++)
|
{
|
if (freeTweenList[i].isActiveAndEnabled && freeState == 1)
|
{
|
freeTweenList[i].Play();
|
}
|
}
|
|
for (int i = 0; i < buyCountGiftTweenList.Count; i++)
|
{
|
if (buyCountGiftTweenList[i].isActiveAndEnabled && cntState == 1)
|
{
|
buyCountGiftTweenList[i].Play();
|
}
|
}
|
}
|
}
|
}
|