//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Wednesday, July 18, 2018
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
using UnityEngine.UI;
|
//限时礼包
|
namespace Snxxz.UI
|
{
|
|
public class LimitedTimePackageWin : Window
|
{
|
[SerializeField] Text m_Text_PackageName;//礼包名
|
[SerializeField] Button m_Close_Btn;//关闭按钮
|
[SerializeField] Button m_Buy_Btn;//购买按钮
|
[SerializeField] GameObject m_BoughtObj;//已购买
|
[SerializeField] Transform m_Horizontal;
|
|
[SerializeField] Text m_Money1;//原价
|
[SerializeField] Text m_Money2;//现价
|
[SerializeField] Text m_Text_ActivityTimeTo;//活动时间
|
public int CDTIME = 5;
|
private float time = 0;
|
#region Built-in
|
LimitedTimePackageItemClassModel limitedTimePackageItemModel { get { return ModelCenter.Instance.GetModel<LimitedTimePackageItemClassModel>(); } }
|
ItemTipsModel _itemTipsModel;
|
ItemTipsModel itemTipsModel { get { return _itemTipsModel ?? (_itemTipsModel = ModelCenter.Instance.GetModel<ItemTipsModel>()); } }
|
protected override void BindController()
|
{
|
}
|
|
protected override void AddListeners()
|
{
|
m_Close_Btn.AddListener(() => {
|
Close();
|
if (!WindowCenter.Instance.IsOpen<MainInterfaceWin>())
|
{
|
WindowCenter.Instance.Open <MainInterfaceWin>();
|
}
|
|
});
|
}
|
|
protected override void OnPreOpen()
|
{
|
OperationTimeHepler.Instance.operationTimeUpdateEvent += OperationTimeUpdateEvent;
|
limitedTimePackageItemModel.UpdateLimitedTimePackageItem += UpdateLimitedTimePackageItem;
|
GlobalTimeEvent.Instance.secondEvent += secondEvent;
|
time = 0;
|
m_Buy_Btn.interactable = true;
|
DisPlay();
|
}
|
|
protected override void OnAfterOpen()
|
{
|
if (limitedTimePackageItemModel.redPointStre1.state == RedPointState.Simple)
|
{
|
int GetDayOfYear = DateTime.Now.DayOfYear;
|
LocalSave.SetInt("IsOpenLimitedTime", GetDayOfYear);
|
limitedTimePackageItemModel.IsShowTip();
|
}
|
|
}
|
|
private void UpdateLimitedTimePackageItem()
|
{
|
DisPlay();
|
}
|
|
private void OperationTimeUpdateEvent(Operation type)
|
{
|
if (type == Operation.GiftPackage)
|
{
|
DisPlay();
|
}
|
}
|
|
private void DisPlay()
|
{
|
for (int i = 0; i < m_Horizontal.childCount; i++)
|
{
|
m_Horizontal.GetChild(i).gameObject.SetActive(false);
|
}
|
OperationBase operationBase;
|
if (OperationTimeHepler.Instance.TryGetOperationTime(Operation.GiftPackage, out operationBase))
|
{
|
GiftPackageClass operation = operationBase as GiftPackageClass;
|
GiftPackageClass.Gift_Package gift;
|
if (operation.TryGetGift(TimeUtility.ServerNow, out gift))
|
{
|
if (gift.gifts.Length > 0)
|
{
|
string str = string.Empty;
|
str = gift.gifts[0].rmb + Language.Get("RMB_Package_Z");
|
m_Text_PackageName.text = str;
|
m_Money1.text = gift.gifts[0].rmbOriginal + Language.Get("RMB_Z");//原价
|
m_Money2.text = gift.gifts[0].rmb + Language.Get("RMB_Z");//现价
|
int BuyCountLimit = gift.gifts[0].limitNum;//限购数量
|
int GiftID = gift.gifts[0].id;//礼包ID
|
m_Buy_Btn.RemoveAllListeners();
|
m_Buy_Btn.AddListener(() =>
|
{
|
|
if (limitedTimePackageItemModel.IsExpired())
|
{
|
if (OperationTimeHepler.Instance.SatisfyAdvanceCondition(Operation.GiftPackage))
|
{
|
var seconds = 0;
|
if (operationBase != null)
|
{
|
if (operationBase.InAdvanceTime(TimeUtility.ServerNow))
|
{
|
seconds = operationBase.GetSecondsBeforeStart(TimeUtility.ServerNow);
|
}
|
}
|
SysNotifyMgr.Instance.ShowTip("LimitGilt1", TimeUtility.SecondsToDHMSCHS(seconds));
|
return;
|
}
|
else
|
{
|
m_Buy_Btn.interactable = false;
|
time = 0;
|
limitedTimePackageItemModel.OpenFreePlat(str, gift.gifts[0].rmb, gift.gifts[0].OrderInfo);
|
return;
|
}
|
|
}
|
else
|
{
|
SysNotifyMgr.Instance.ShowTip("LimitGift9");
|
return;
|
}
|
|
});
|
if (limitedTimePackageItemModel.DicBuyPackage.ContainsKey(GiftID) && limitedTimePackageItemModel.DicBuyPackage[GiftID] >= BuyCountLimit)
|
{
|
m_Buy_Btn.gameObject.SetActive(false);
|
m_BoughtObj.SetActive(true);
|
}
|
else
|
{
|
m_Buy_Btn.gameObject.SetActive(true);
|
m_BoughtObj.SetActive(false);
|
}
|
var items = gift.gifts[0].items;
|
for (int i = 0; i < items.Length; i++)
|
{
|
int type = i;
|
if (type < m_Horizontal.childCount)
|
{
|
var LimitedTimeItem_Info = m_Horizontal.GetChild(type);
|
LimitedTimeItem_Info.gameObject.SetActive(true);
|
LimitedTimeItemInfo limitedTimeItemInfo = LimitedTimeItem_Info.GetComponent<LimitedTimeItemInfo>();
|
if (items[type].isMainItem)
|
{
|
limitedTimeItemInfo.Uieffect.gameObject.SetActive(true);
|
limitedTimeItemInfo.Uieffect.Play();
|
}
|
else
|
{
|
limitedTimeItemInfo.Uieffect.gameObject.SetActive(false);
|
}
|
var ItemCell = limitedTimeItemInfo.Item_Cell;
|
var Item = ItemConfig.Get(items[type].itemId);
|
ItemCellModel cellModel = new ItemCellModel(items[type].itemId, true, (ulong)items[type].itemCount);
|
ItemCell.Init(cellModel);
|
ItemCell.button.RemoveAllListeners();
|
ItemCell.button.AddListener(() =>
|
{
|
ItemAttrData attrData = new ItemAttrData(items[type].itemId, false, (ulong)items[type].itemCount);
|
itemTipsModel.SetItemTipsModel(attrData);
|
});
|
}
|
}
|
}
|
}
|
}
|
DisplaySurplusTime();
|
}
|
|
|
protected override void OnPreClose()
|
{
|
OperationTimeHepler.Instance.operationTimeUpdateEvent -= OperationTimeUpdateEvent;
|
limitedTimePackageItemModel.UpdateLimitedTimePackageItem -= UpdateLimitedTimePackageItem;
|
GlobalTimeEvent.Instance.secondEvent -= secondEvent;
|
}
|
|
|
protected override void OnAfterClose()
|
{
|
}
|
protected override void LateUpdate()
|
{
|
if (!m_Buy_Btn.interactable)
|
{
|
time += Time.deltaTime;
|
if (time >= CDTIME)
|
{
|
m_Buy_Btn.interactable = true;
|
time = 0;
|
}
|
}
|
}
|
private void secondEvent()
|
{
|
DisplaySurplusTime();
|
}
|
private void DisplaySurplusTime()
|
{
|
OperationBase operationBase;
|
OperationTimeHepler.Instance.TryGetOperationTime(Operation.GiftPackage, out operationBase);
|
var seconds = 0;
|
var inAdvance = false;
|
if (operationBase != null)
|
{
|
if (operationBase.InAdvanceTime(TimeUtility.ServerNow))
|
{
|
inAdvance = true;
|
seconds = operationBase.GetSecondsBeforeStart(TimeUtility.ServerNow);
|
}
|
else
|
{
|
GiftPackageClass operation = operationBase as GiftPackageClass;
|
seconds = operation.GetResetSurplusTime();
|
}
|
}
|
if (seconds > 0)
|
{
|
if (inAdvance)
|
{
|
m_Text_ActivityTimeTo.text = Language.Get("OperationAdvanceOpen", TimeUtility.SecondsToDHMSCHS(seconds));
|
}
|
else
|
{
|
m_Text_ActivityTimeTo.text = Language.Get("LimitGift1", TimeUtility.SecondsToDHMSCHS(seconds));
|
}
|
}
|
else
|
{
|
m_Text_ActivityTimeTo.text = Language.Get("ActivityEnd");
|
}
|
}
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
|