//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Wednesday, September 12, 2018 //-------------------------------------------------------- using UnityEngine; using System.Collections; using UnityEngine.UI; using System.Collections.Generic; using System; using vnxbqy.UI; //功能预告红点 public class FeatureNoticeModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk { public List FunctionList = new List(); public Dictionary DicAwardItem = new Dictionary();//奖励物品 public Dictionary DicOpenFuncState = new Dictionary(); public Dictionary DicRedPoint = new Dictionary();//红点 public event Action UpdateAwarfItem; 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; private bool Isbool=true; public override void Init() { AddList(); AddAwardItem(); AddRedPoint(); } public void OnBeforePlayerDataInitialize() { Isbool = true; FunctionForecastIndex = 0; DicOpenFuncState.Clear(); StageLoad.Instance.onStageLoadFinish -= OnStageLoadFinish; PlayerDatas.Instance.playerDataRefreshEvent -= Updatefighting; } public void OnPlayerLoginOk() { Isbool = true; StageLoad.Instance.onStageLoadFinish += OnStageLoadFinish; PlayerDatas.Instance.playerDataRefreshEvent += Updatefighting; GlobalTimeEvent.Instance.secondEvent -= secondEvent; GlobalTimeEvent.Instance.secondEvent += secondEvent; RedPoint_State(); } private void secondEvent() { if (Isbool) { RedPoint_State(); Isbool = false; } } private void Updatefighting(PlayerDataType _tCDBPlayerRefresh) { if (_tCDBPlayerRefresh == PlayerDataType.LV &&PlayerDatas.Instance.baseData.LV>=100) { Isbool = true; } } public override void UnInit() { } private void OnStageLoadFinish() { if (!(StageLoad.Instance.currentStage is DungeonStage)) { OpenFuncId = 0; RedPointChange = false; IsRedPoint = false; } } private void AddList()//添加列表信息 { if (FunctionList.Count <= 0) { var configs = FunctionForecastConfig.GetKeys(); foreach (var key in configs) { var functionForecastConfig = FunctionForecastConfig.Get(key); if (functionForecastConfig != null && functionForecastConfig.Display == 1) { FunctionList.Add(functionForecastConfig); } } } } private void AddAwardItem() { if (DicAwardItem.Count <= 0) { var configs = FunctionForecastConfig.GetKeys(); foreach (var key in configs) { var functionForecastConfig = FunctionForecastConfig.Get(key); if (!DicAwardItem.ContainsKey(functionForecastConfig.FuncId) && functionForecastConfig.Display == 1) { ImpactRankModel.RankAwardItem _award = new ImpactRankModel.RankAwardItem(); if (functionForecastConfig.Award == string.Empty) { continue; } var _jsonData = LitJson.JsonMapper.ToObject(functionForecastConfig.Award); foreach (string _key in _jsonData.Keys) { var _job = int.Parse(_key); var _itemArray = LitJson.JsonMapper.ToObject(_jsonData[_key].ToJson()); for (int j = 0; j < _itemArray.Length; j++) { _award.Add(_job, new Item(_itemArray[j][0], _itemArray[j][1])); } } DicAwardItem.Add(functionForecastConfig.FuncId, _award); } } } } private void AddRedPoint() { if (DicRedPoint.Count <= 0) { var configs = FunctionForecastConfig.GetKeys(); foreach (var key in configs) { var functionForecastConfig = FunctionForecastConfig.Get(key); if (!DicRedPoint.ContainsKey(functionForecastConfig.FuncId) && functionForecastConfig.Display == 1) { int RedPointkey = Redpoint_key1 * 10000 + functionForecastConfig.FuncId; Redpoint redPointMountStare = new Redpoint(Redpoint_key1, RedPointkey); DicRedPoint.Add(functionForecastConfig.FuncId, redPointMountStare); } } } } private void RedPoint_State() { var configs = FunctionForecastConfig.GetKeys(); foreach (var key in DicRedPoint.Keys) { DicRedPoint[key].state=RedPointState.None; } if (PlayerDatas.Instance.baseData.LV <= 19)//功能预告红点110级前不显示 { return; } foreach (var _key in DicOpenFuncState.Keys) { if (DicRedPoint.ContainsKey(_key) && DicOpenFuncState[_key].State==1 && DicOpenFuncState[_key].AwardState==0 && DicAwardItem.ContainsKey(_key)) { DicRedPoint[_key].state = RedPointState.Simple; } } } TreasureModel treasureModel { get { return ModelCenter.Instance.GetModel(); } } public IEnumerator WhetherToPlayTheBox() { yield return new WaitForSeconds(0.7f); var inDungeon = IsDungeon(); var IsOpenMaininterface = WindowCenter.Instance.IsOpen(); var IsOpenOffLineOnHook = WindowCenter.Instance.IsOpen(); var treasureModel = ModelCenter.Instance.GetModel(); var IsLoading = StageLoad.Instance.isLoading; if (NewBieCenter.Instance.inGuiding || treasureModel.newGotShowing || inDungeon || !IsOpenMaininterface || treasureModel.treasureStageUpShow || WindowCenter.Instance.ExistAnyFullScreenOrMaskWin() || IsOpenOffLineOnHook || IsLoading) { yield break; } for (int i = 0; i < FunctionList.Count; i++) { if (!FuncOpen.Instance.IsFuncOpen(FunctionList[i].FuncId)) { var functionForecastConfig = FunctionForecastConfig.Get(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.IsOpen(); if (PlayerDatas.Instance.baseData.LV >= functionForecastConfig.FrameLevel && type == 0) { LocalSave.SetInt(strKey, functionForecastConfig.FrameLevel); var IsOpenFeatureNotice = WindowCenter.Instance.IsOpen(); if (!IsOpenFeatureNotice) { WindowCenter.Instance.Close(); WindowCenter.Instance.Open(); } } } } } public bool IsShowFeatureN() { bool IsBool = false; for (int i = 0; i < FunctionList.Count; i++) { if (!FuncOpen.Instance.IsFuncOpen(FunctionList[i].FuncId)) { var functionForecastConfig = FunctionForecastConfig.Get(FunctionList[i].FuncId); if (functionForecastConfig.FrameLevel <= 0) { return false; } string strKey = "FeatureNotice" + functionForecastConfig.FrameLevel + PlayerDatas.Instance.baseData.PlayerID; int type = LocalSave.GetInt(strKey); bool IsOpenMain = WindowCenter.Instance.IsOpen(); if (PlayerDatas.Instance.baseData.LV >= functionForecastConfig.FrameLevel && type == 0) { IsBool = true; } } } return IsBool; } private bool IsDungeon() { var mapId = PlayerDatas.Instance.baseData.MapID; var mapConfig = MapConfig.Get(mapId); return mapConfig != null && mapConfig.MapFBType != 0; } List functionForecastValue = new List(); public int GetOpenLv(int Inedx) { int lv = 0; if (functionForecastValue.Count <= 0) { functionForecastValue= FunctionForecastConfig.GetValues(); } foreach (var value in functionForecastValue) { if (value.OpenNumber == Inedx) { lv = value.DisplayLevel; return lv; } } return lv; } public class OpenFuncState { public int State; public int AwardState; } public void OpenFuncAwardState(HA302_tagMCFuncOpenStateList info) { for (int i = 0; i < info.FuncCount; i++) { int FuncID = info.FuncStateList[i].FuncID; if (!DicOpenFuncState.ContainsKey(FuncID)) { OpenFuncState openFuncState = new OpenFuncState(); openFuncState.State = info.FuncStateList[i].State; openFuncState.AwardState = info.FuncStateList[i].AwardState; DicOpenFuncState.Add(FuncID, openFuncState); } else { DicOpenFuncState[FuncID].State= info.FuncStateList[i].State; DicOpenFuncState[FuncID].AwardState = info.FuncStateList[i].AwardState; } } if (UpdateAwarfItem != null) { UpdateAwarfItem(); } RedPoint_State(); } public void SendGetAward(int OpenFuncId) { CA504_tagCMPlayerGetReward getReward = new CA504_tagCMPlayerGetReward(); getReward.RewardType = (byte)GotServerRewardType.Def_RewardType_OpenFunc; getReward.DataEx = (uint)OpenFuncId; getReward.DataExStrLen = 0; getReward.DataExStr = string.Empty; GameNetSystem.Instance.SendInfo(getReward); } }