local RedPoint_Model = {} local private = {} local red_dot_pb = require 'Proto/red_dot_pb' local red_point_info_pb = require 'Proto/red_point_info_pb' local RedPointNode = require 'Modules/RedPoint/RedPointNode' local EventSystem = require('Event/EventSystem') --一次性需要发给服务器记录的红点类型,枚举由客户端定义,服务器只是存储值,再发过来,不进行处理 RedPoint_Model.RedPointType = { PVP = 1, Boss = 2, Questionnaire = 3, QQ = 4, GuildWar = 5, GuildBoss = 6, RebelStrike = 7, GuildParty = 8, MonthCard = 9, TestingGift_FaceBook = 10, TestingGift_StoreScore = 11, TestingGift_BindAccount = 12, DemonGod = 13, GuildEscort = 14, Storm = 15, GuildFamousEntry = 16, CountrySalaryReward = 17, --战利品封赏 SyncFourCountryWar = 18, AnniversaryLuckyDraw = 19, PetIllustratedHandbook = 20, --宠物图鉴 PetRuneMerge = 21, --宠物符文融合 PetRuneStudy_Slot1 = 22, --宠物槽位1学习 PetRuneStudy_Slot2 = 23, --宠物槽位2学习 PetRuneStudy_Slot3 = 24, --宠物槽位3学习 FightThrone = 25,--逐鹿中原 CountryNightBoss = 26,--烽火四起 DragonArtery = 27, --龙脉 SyncCityWar = 28, --决胜长安 DyeDrawCard = 29, --染色抽卡 } -- 登录推送红点 RedPoint_Model.EnterWorldRedPointType = { HonorOrder = red_point_info_pb.HonorOrder, -- 战令 DemonGod = red_point_info_pb.DemonGod, -- 魔神 GVGFightWarReport = red_point_info_pb.GVGFightWarReport, -- 攻城略地(GVG) 战报红点 } function RedPoint_Model.OnStartup() NetManager.RegisterMsgCB(MessageEnums.MessageChangedRedDotInfo, private.OneTimeRedPointResponse) EventSystem.Regist(EventID.FunctionUnlockUpdate, private.OnFunctionUnlockUpdate) private.OneTimeRedPointInfo = {} private.isClickActivitiesBtn = false private.EnterWorldRedPointList = {} for funcName, func in pairs(RedPointNode) do RedPoint_Model[funcName] = func end end function private.OnFunctionUnlockUpdate(funcID, isComplete) if funcID == MDL.Unlock.FunctionType.EntryRedPoint then RedPoint_Model.ForceRefreshAllNodes() end end function RedPoint_Model.GetIsClickActivities() return private.isClickActivitiesBtn end function RedPoint_Model.SetActivitiesRedPoint() private.isClickActivitiesBtn = true end --region 终身一次性红点 function RedPoint_Model.GetOneTimeRedPointInfoByType(redPointType) return private.OneTimeRedPointInfo[redPointType] and private.OneTimeRedPointInfo[redPointType].valueOfRedDot or 0 end function RedPoint_Model.GetRedPointTimeByType(redPointType) return private.OneTimeRedPointInfo[redPointType] and private.OneTimeRedPointInfo[redPointType].lastTime end function RedPoint_Model.SetOneTimeRedPointInfo(msgRedPointInfo) for i, v in ipairs(msgRedPointInfo) do private.OneTimeRedPointInfo[v.indexOfRedDot] = v end end ---协议相关 function RedPoint_Model.OneTimeRedPointRequest(redPointType, state, isNeedTime, activityType) local msg = red_dot_pb.ChangedRedDotInfoReq() msg.indexOfRedDot = redPointType msg.valueOfRedDot = state --0为未点击,需要显示红点,1为已经点击,不需要显示红点 if isNeedTime then msg.updateTime = true end NetManager.SendMessage(MessageEnums.MessageChangedRedDotInfo, msg) if activityType then EventSystem.Dispatch(EventID.UI_Activity_Refresh_Single_RedPoint, activityType, false) end end function private.OneTimeRedPointResponse(msgResp) if msgResp.Resp.Code == 0 then for i, v in ipairs(msgResp.AllRedDotInfo.infos) do private.OneTimeRedPointInfo[v.indexOfRedDot] = v if v.indexOfRedDot == RedPoint_Model.RedPointType.MonthCard then CTL.MonthCard.CheckAllMonthCardShopRedPoint() end end end end --endregion --region ************************* 用于主界面有红点需求的功能 ******************************* -- 用于主界面有红点需求的功能 -- 因为红点依赖系统数据,而登录时可能拿不到服务器下发的系统数据。 -- 这里是服务器下发的红点状态,如果系统有红点会下发系统对应的ID function RedPoint_Model.SetEnterWorldRedPointList(redPointList) for _, v in ipairs(redPointList) do table.insert(private.EnterWorldRedPointList, v) end end function RedPoint_Model.UpdateEnterWorldRedPointList(redPointList) -- 设置新的红点 for _, v in ipairs(redPointList) do if not table.containValue(private.EnterWorldRedPointList, v) then table.insert(private.EnterWorldRedPointList, v) EventSystem.Dispatch(EventID.ServerRedPoint_Changed, v, true) end end -- 移除老的红点(倒序移除防止遍历错误) for i = #private.EnterWorldRedPointList, 1 -1 do local rpType = private.EnterWorldRedPointList[i] if not table.containValue(redPointList, rpType) then table.remove(private.EnterWorldRedPointList, i) EventSystem.Dispatch(EventID.ServerRedPoint_Changed, rpType, false) end end end function RedPoint_Model.GetEnterWorldRedPoint(rpType) if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.EntryRedPoint) then for _, v in ipairs(private.EnterWorldRedPointList) do if v == rpType then return true end end end return false end function RedPoint_Model.RemoveEnterWorldRedPoint(rpType) for i,v in ipairs(private.EnterWorldRedPointList) do if v == rpType then table.remove(private.EnterWorldRedPointList, i) EventSystem.Dispatch(EventID.ServerRedPoint_Changed, v, false) return end end end --endregion ************************* 登录红点 ******************************* return RedPoint_Model