using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using TableConfig;
|
using UnityEngine;
|
namespace Snxxz.UI
|
{
|
public class OSGiftModel : Model, IPlayerLoginOk, IBeforePlayerDataInitialize
|
{
|
public override void Init()
|
{
|
PlayerDatas.Instance.PlayerDataRefreshInfoEvent += PlayerDataRefreshInfoEvent;
|
storeModel.RefreshBuyShopLimitEvent += RefreshBuyShopLimitEvent;
|
vipModel.firstChargeRewardEvent += firstChargeRewardEvent;
|
}
|
|
public override void UnInit()
|
{
|
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
activate = CheckActivate();
|
if (OnOSGiftStateChange != null)
|
{
|
OnOSGiftStateChange();
|
}
|
}
|
|
public event Action OnOSGiftStateChange;
|
|
public bool activate { get; private set; }
|
|
private bool m_GiftGetNotify = false;
|
public bool giftGetNotify
|
{
|
get { return m_GiftGetNotify; }
|
set
|
{
|
m_GiftGetNotify = value;
|
OSGiftRedpoint.state = value ? RedPointState.Simple : RedPointState.None;
|
if (OnOSGiftStateChange != null)
|
{
|
OnOSGiftStateChange();
|
}
|
}
|
}
|
|
StoreModel storeModel
|
{
|
get
|
{
|
return ModelCenter.Instance.GetModel<StoreModel>();
|
}
|
}
|
|
VipModel vipModel { get { return ModelCenter.Instance.GetModel<VipModel>(); } }
|
|
public bool CheckOpen()
|
{
|
if (!login)
|
{
|
return false;
|
}
|
login = false;
|
if (!PreFightMission.Instance.IsFinished()
|
|| DayRemind.Instance.GetDayRemind(DayRemind.OSGIFT_TIP) || PlayerDatas.Instance.baseData.coinPointTotal == 0
|
|| !ModelCenter.Instance.GetModel<VipModel>().firstChargeRewardGet)
|
{
|
return false;
|
}
|
var _list = StoreConfig.GetTypeStoreModel((int)StoreFunc.OSGift);
|
for (int i = 0; i < _list.Count; i++)
|
{
|
var _limit = storeModel.GetBuyShopLimit((uint)_list[i].ID);
|
if (_limit == null || _limit.BuyCnt < _list[i].PurchaseNumber[0])
|
{
|
if (!WindowCenter.Instance.CheckOpen<OpenServerGiftWin>())
|
{
|
DayRemind.Instance.SetDayRemind(DayRemind.OSGIFT_TIP, true);
|
WindowCenter.Instance.Open<OpenServerGiftWin>();
|
return true;
|
}
|
break;
|
}
|
}
|
return false;
|
}
|
|
private void RefreshBuyShopLimitEvent()
|
{
|
bool _activate = CheckActivate();
|
if (activate != _activate)
|
{
|
activate = _activate;
|
if (OnOSGiftStateChange != null)
|
{
|
OnOSGiftStateChange();
|
}
|
}
|
}
|
|
private void firstChargeRewardEvent()
|
{
|
bool _activate = CheckActivate();
|
if (activate != _activate)
|
{
|
activate = _activate;
|
if (OnOSGiftStateChange != null)
|
{
|
OnOSGiftStateChange();
|
}
|
}
|
}
|
|
public bool CheckActivate()
|
{
|
if (PlayerDatas.Instance.baseData.coinPointTotal == 0
|
|| !ModelCenter.Instance.GetModel<VipModel>().firstChargeRewardGet)
|
{
|
return false;
|
}
|
var _list = StoreConfig.GetTypeStoreModel((int)StoreFunc.OSGift);
|
for (int i = 0; i < _list.Count; i++)
|
{
|
var _limit = storeModel.GetBuyShopLimit((uint)_list[i].ID);
|
if (_limit == null || _limit.BuyCnt < _list[i].PurchaseNumber[0])
|
{
|
return true;
|
}
|
}
|
return false;
|
}
|
|
private void PlayerDataRefreshInfoEvent(PlayerDataRefresh _type)
|
{
|
bool _activate = CheckActivate();
|
if (_type == PlayerDataRefresh.ChangeCoinPointTotal && activate != _activate)
|
{
|
activate = _activate;
|
if (OnOSGiftStateChange != null)
|
{
|
OnOSGiftStateChange();
|
}
|
}
|
}
|
|
private bool login = false;
|
public void OnBeforePlayerDataInitialize()
|
{
|
giftGetNotify = false;
|
if (!(StageManager.Instance.CurrentStage is DungeonStage))
|
{
|
login = true;
|
}
|
else
|
{
|
login = false;
|
}
|
}
|
|
public Redpoint OSGiftRedpoint = new Redpoint(2, 36);
|
}
|
}
|