//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Wednesday, September 12, 2018
|
//--------------------------------------------------------
|
using UnityEngine;
|
using System.Collections;
|
using UnityEngine.UI;
|
using TableConfig;
|
using System.Collections.Generic;
|
using System;
|
using Snxxz.UI;
|
|
//功能预告红点
|
public class FeatureNoticeModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
|
{
|
public List<FunctionForecastConfig> FunctionList = new List<FunctionForecastConfig>();
|
private const int Redpoint_key1 = 38;
|
public Redpoint redPointStre1 = new Redpoint(Redpoint_key1);
|
private int OpenFuncId = 0;
|
private bool RedPointChange = false;
|
private bool IsRedPoint = false;
|
public int FunctionForecastIndex = 0;
|
public override void Init()
|
{
|
AddList();
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
PlayerDatas.Instance.PlayerDataRefreshInfoEvent -= OnPlayersUpLV;
|
FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChangeEvent;
|
treasureModel.treasureStateChangeEvent -= treasureStateChangeEvent;
|
treasureModel.treasureStageUpEvent -= treasureStageUpEvent;
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
|
PlayerDatas.Instance.PlayerDataRefreshInfoEvent += OnPlayersUpLV;
|
treasureModel.treasureStateChangeEvent += treasureStateChangeEvent;
|
treasureModel.treasureStageUpEvent += treasureStageUpEvent;
|
StageManager.Instance.onStageLoadFinish -= OnStageLoadFinish;
|
StageManager.Instance.onStageLoadFinish += OnStageLoadFinish;
|
RedDotStatus();
|
}
|
|
|
|
public override void UnInit()
|
{
|
|
}
|
private void OnStageLoadFinish()
|
{
|
if (!(StageManager.Instance.CurrentStage is DungeonStage))
|
{
|
OpenFuncId = 0;
|
RedPointChange = false;
|
IsRedPoint = false;
|
}
|
}
|
private void treasureStageUpEvent(int obj)
|
{
|
RedDotStatus();
|
}
|
|
private void treasureStateChangeEvent(int obj)
|
{
|
RedDotStatus();
|
}
|
|
private void OnFuncStateChangeEvent(int obj)
|
{
|
RedDotStatus();
|
}
|
|
private void OnPlayersUpLV(PlayerDataRefresh obj)
|
{
|
if (obj == PlayerDataRefresh.LV)
|
{
|
RedDotStatus();
|
}
|
}
|
private void AddList()//添加列表信息
|
{
|
if (FunctionList.Count <= 0)
|
{
|
var configs = Config.Instance.GetAllKeys<FunctionForecastConfig>();
|
foreach (var key in configs)
|
{
|
var functionForecastConfig = Config.Instance.Get<FunctionForecastConfig>(key);
|
if (functionForecastConfig != null && functionForecastConfig.Display == 1)
|
{
|
FunctionList.Add(functionForecastConfig);
|
}
|
}
|
}
|
}
|
|
private void RedDotStatus()
|
{
|
for (int i = 0; i < FunctionList.Count; i++)
|
{
|
if (!FuncOpen.Instance.IsFuncOpen(FunctionList[i].FuncId))
|
{
|
redPointStre1.state = RedPointState.None;
|
if (OpenFuncId != FunctionList[i].FuncId)
|
{
|
RedPointChange = false;
|
}
|
if (OpenFuncId != FunctionList[i].FuncId || !RedPointChange)
|
{
|
OpenFuncId = FunctionList[i].FuncId;
|
IsRedPoint = false;
|
TrailerClassification(FunctionList[i].FuncId);
|
}
|
return;
|
}
|
}
|
}
|
|
private void TrailerClassification(int funcID)
|
{
|
FuncOpenLVConfig funcoPenConfig = Config.Instance.Get<FuncOpenLVConfig>(funcID);
|
var functionForecastConfig = Config.Instance.Get<FunctionForecastConfig>(funcID);
|
if (funcoPenConfig.LimitMagicWeapon != 0 || funcoPenConfig.LimitMissionID != 0)
|
{
|
if (funcoPenConfig.LimitMagicWeapon != 0)//法宝
|
{
|
int faBaoID = funcoPenConfig.LimitMagicWeapon / 100;
|
MagicWeapon(faBaoID, funcID);
|
return;
|
}
|
else if (funcoPenConfig.LimitMissionID != 0)//任务
|
{
|
if (functionForecastConfig.RedPointLV <= 0)
|
{
|
return;
|
}
|
if (PlayerDatas.Instance.baseData.LV >= functionForecastConfig.RedPointLV)
|
{
|
RedPointChange = true;
|
IsRedPoint = true;
|
}
|
if (IsRedPoint)
|
{
|
redPointStre1.state = RedPointState.Simple;
|
}
|
else
|
{
|
redPointStre1.state = RedPointState.None;
|
}
|
return;
|
}
|
}
|
else//等级
|
{
|
if (functionForecastConfig.RedPointLV <= 0)
|
{
|
return;
|
}
|
if (PlayerDatas.Instance.baseData.LV >= functionForecastConfig.RedPointLV)
|
{
|
RedPointChange = true;
|
IsRedPoint = true;
|
}
|
if (IsRedPoint)
|
{
|
redPointStre1.state = RedPointState.Simple;
|
}
|
else
|
{
|
redPointStre1.state = RedPointState.None;
|
}
|
return;
|
}
|
}
|
TreasureModel treasureModel { get { return ModelCenter.Instance.GetModel<TreasureModel>(); } }
|
private void MagicWeapon(int fabaoID, int funcID)
|
{
|
var functionForecastConfig = Config.Instance.Get<FunctionForecastConfig>(funcID);
|
if (functionForecastConfig.RedPointLV > 0)//根据填的等级来
|
{
|
if (PlayerDatas.Instance.baseData.LV >= functionForecastConfig.RedPointLV)
|
{
|
RedPointChange = true;
|
IsRedPoint = true;
|
}
|
if (IsRedPoint)
|
{
|
redPointStre1.state = RedPointState.Simple;
|
}
|
else
|
{
|
redPointStre1.state = RedPointState.None;
|
}
|
return;
|
}
|
Treasure treasure;//根据解锁法宝的百分比
|
|
if (treasureModel.TryGetTreasure(fabaoID, out treasure)
|
&& treasure.state == TreasureState.Collected)
|
{
|
var list = treasure.treasureStages;
|
var funcStage = 0;
|
for (int i = 0; i < list.Count; i++)
|
{
|
if (list[i].unlockType == TreasureStageUnlock.Func &&
|
list[i].func == funcID)
|
{
|
funcStage = i;
|
break;
|
}
|
}
|
if (treasure.stage == funcStage - 1 || funcStage == 0)
|
{
|
float exp = ((float)treasure.exp / treasure.treasureStages[funcStage].exp) * 100;
|
if (functionForecastConfig.RedPointPercentage > -1)
|
{
|
if (exp >= functionForecastConfig.RedPointPercentage)
|
{
|
RedPointChange = true;
|
IsRedPoint = true;
|
}
|
if (IsRedPoint)
|
{
|
redPointStre1.state = RedPointState.Simple;
|
}
|
}
|
else
|
{
|
redPointStre1.state = RedPointState.None;
|
}
|
}
|
}
|
}
|
|
public IEnumerator WhetherToPlayTheBox()
|
{
|
yield return new WaitForSeconds(0.7f);
|
var inDungeon = IsDungeon();
|
var IsOpenMaininterface = WindowCenter.Instance.CheckOpen<MainInterfaceWin>();
|
var IsOpenOffLineOnHook = WindowCenter.Instance.CheckOpen<OffLineOnHookWin>();
|
var treasureModel = ModelCenter.Instance.GetModel<TreasureModel>();
|
if (NewBieCenter.Instance.inGuiding || treasureModel.newGotShowing || inDungeon || !IsOpenMaininterface
|
|| treasureModel.treasureStageUpShow || WindowCenter.Instance.ExitAnyFullScreenOrMaskWin() ||
|
IsOpenOffLineOnHook)
|
{
|
yield break;
|
}
|
for (int i = 0; i < FunctionList.Count; i++)
|
{
|
if (!FuncOpen.Instance.IsFuncOpen(FunctionList[i].FuncId))
|
{
|
var functionForecastConfig = Config.Instance.Get<FunctionForecastConfig>(FunctionList[i].FuncId);
|
if (functionForecastConfig.FrameLevel <= 0)
|
{
|
yield break;
|
}
|
string strKey = "FeatureNotice" + functionForecastConfig.FrameLevel + PlayerDatas.Instance.baseData.PlayerID;
|
int type = LocalSave.GetInt(strKey);
|
bool IsOpenMain = WindowCenter.Instance.CheckOpen<MainInterfaceWin>();
|
if (PlayerDatas.Instance.baseData.LV >= functionForecastConfig.FrameLevel && type == 0)
|
{
|
LocalSave.SetInt(strKey, functionForecastConfig.FrameLevel);
|
var IsOpenFeatureNotice = WindowCenter.Instance.CheckOpen<FeatureNoticeWin>();
|
if (!IsOpenFeatureNotice)
|
{
|
WindowCenter.Instance.Close<MainInterfaceWin>();
|
WindowCenter.Instance.Open<FeatureNoticeWin>();
|
}
|
}
|
}
|
}
|
}
|
private bool IsDungeon()
|
{
|
var mapId = PlayerDatas.Instance.baseData.MapID;
|
var mapConfig = Config.Instance.Get<MapConfig>(mapId);
|
return mapConfig != null && mapConfig.MapFBType != 0;
|
}
|
|
public int GetOpenLv(int Inedx)
|
{
|
int lv = 0;
|
var functionForecastValue = Config.Instance.GetAllValues<FunctionForecastConfig>();
|
foreach (var value in functionForecastValue)
|
{
|
if (value.OpenNumber == Inedx)
|
{
|
lv = value.DisplayLevel;
|
return lv;
|
}
|
}
|
return lv;
|
}
|
|
}
|