using vnxbqy.UI;
|
using System;
|
using System.Collections.Generic;
|
using UnityEngine.UI;
|
using System.Linq;
|
using LitJson;
|
|
|
public class OnlineRechargeModel : ILModel<OnlineRechargeModel>
|
{
|
public int changeSeconds;
|
public int[] ctgArray;
|
public int[][] awards;
|
public int state; //奖励是否已领取
|
public Redpoint redpoint = new Redpoint(MainRedPoint.zxthRedPoint);
|
public event Action updateEvent;
|
|
public bool openyet = false; //默认红点,打开界面消失
|
|
VipModel vipModel { get { return ModelCenter.Instance.GetModelEx<VipModel>(); } }
|
|
protected override void Init()
|
{
|
GameEvent.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitialize;
|
vipModel.rechargeCountEvent += RechargeCountEvent;
|
FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
|
ParseConfig();
|
}
|
protected override void UnInit()
|
{
|
GameEvent.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitialize;
|
vipModel.rechargeCountEvent -= RechargeCountEvent;
|
FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChangeEvent;
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
state = 0;
|
}
|
|
public void ParseConfig()
|
{
|
var OnlineRechargeTH = FuncConfigConfig.Get("OnlineRechargeTH");
|
changeSeconds = int.Parse(OnlineRechargeTH.Numerical1)*60;
|
|
|
ctgArray = JsonMapper.ToObject<int[]>(OnlineRechargeTH.Numerical2);
|
awards = JsonMapper.ToObject<int[][]>(OnlineRechargeTH.Numerical3);
|
}
|
|
|
public void GetAward()
|
{
|
var SendInfo = new CA504_tagCMPlayerGetReward();
|
SendInfo.RewardType = 44;
|
GameNetSystem.Instance.SendInfo(SendInfo);
|
}
|
|
|
|
//奖励领取后关闭
|
public bool IsOpen()
|
{
|
if (!FuncOpen.Instance.IsFuncOpen(193))
|
{
|
return false;
|
}
|
if (state == 1)
|
{
|
return false;
|
}
|
return true;
|
}
|
|
|
// c#底层调用 是否在底部显示
|
public bool IsBottomButtonOpen()
|
{
|
bool isbuy = false;
|
VipModel.RechargeCount rechargeCount;
|
for (int i = 0; i < ctgArray.Length; i++)
|
{
|
if (vipModel.TryGetRechargeCount(ctgArray[i], out rechargeCount))
|
{
|
if (rechargeCount.totalCount > 0)
|
{
|
isbuy = true;
|
break;
|
}
|
}
|
}
|
if (!isbuy)
|
{
|
if (IL_DTCA109_tagMCOnLineTimeTotal.onlineSeconds < changeSeconds)
|
{
|
return true;
|
}
|
else
|
{
|
//限时降价后 点击一次才消失
|
if (!LocalSave.GetBool(StringUtility.Contact(PlayerDatas.Instance.PlayerId, "zxth15"), false))
|
{
|
return true;
|
}
|
}
|
}
|
return false;
|
}
|
|
|
public void UpdateRedpoint()
|
{
|
redpoint.state = RedPointState.None;
|
if (!IsOpen()) return;
|
if (!openyet)
|
{
|
//未打开界面 默认红点
|
redpoint.state = RedPointState.Simple;
|
return;
|
}
|
|
//未领取
|
VipModel.RechargeCount rechargeCount;
|
for (int i = 0; i < ctgArray.Length; i++)
|
{
|
if (vipModel.TryGetRechargeCount(ctgArray[i], out rechargeCount))
|
{
|
if (rechargeCount.totalCount > 0)
|
{
|
redpoint.state = RedPointState.Simple;
|
break;
|
}
|
}
|
}
|
|
}
|
|
public void UpdateState(IL_HAA04_tagMCOnlineRechargeTH pack)
|
{
|
state = pack.AwardState;
|
updateEvent?.Invoke();
|
UpdateRedpoint();
|
}
|
|
private void RechargeCountEvent(int id)
|
{
|
if (ctgArray.Contains(id))
|
{
|
UpdateRedpoint();
|
updateEvent?.Invoke();
|
}
|
}
|
|
private void OnFuncStateChangeEvent(int id)
|
{
|
if (id == 193)
|
{
|
UpdateRedpoint();
|
}
|
}
|
}
|