local Broadcast_Model = {} local private = {} local EventSystem = require('Event/EventSystem') local BroadcastCacheNum = DataSheetManager.ConstData:GetDataByID("BroadcastSpeedCacheNum").IntValue function Broadcast_Model.OnStartup() private.broadcastMsgList = {} private.broadcastMsgList_Top = {} private.GMBroadcastList = {} end --region -- **************** 游戏中跑马灯 ******************* -- Broadcast_Model.MapUIType = { All = 1, Town = 2, Battle = 3, } function Broadcast_Model.GetBroadcastMsg() local msg = private.broadcastMsgList[1] if msg and CTL.Broadcast.IfCanShowBroadcast(msg.mapUIType) then return msg else Broadcast_Model.RemoveBroadcastMsg() return nil end end function Broadcast_Model.InsertBroadcastMsg(msgData) table.insert(private.broadcastMsgList, msgData) local listLength = #private.broadcastMsgList --按照打断优先级和普通优先级进行排序 if listLength > 1 then table.sort(private.broadcastMsgList, private.SortMsgByPriority) end --排序后超过上限则舍弃后边的 if listLength > BroadcastCacheNum then table.remove(private.broadcastMsgList) end --比较current和新插入的msgData打断优先级,是否需要打断 local firstBroadcastMsg = private.broadcastMsgList[1] if CTL.Broadcast.IfCanShowBroadcast(firstBroadcastMsg.mapUIType) then local existedBroadcastMsg = CTL.Broadcast.GetExistedBroadcastMsg() if existedBroadcastMsg and firstBroadcastMsg then if firstBroadcastMsg.BreakPriority > existedBroadcastMsg.BreakPriority then Broadcast_Model.CutCurrentBroadcast() end end end EventSystem.Dispatch(EventID.UI_Broadcast_UpdateBroadcast) end function private.SortMsgByPriority(a, b) if a.BreakPriority ~= b.BreakPriority then return a.BreakPriority > b.BreakPriority else return a.Priority > b.Priority end end function Broadcast_Model.RemoveBroadcastMsg() table.remove(private.broadcastMsgList, 1) end function Broadcast_Model.ClearBroadcastMsg() private.broadcastMsgList = {} end function Broadcast_Model.CutCurrentBroadcast() EventSystem.Dispatch(EventID.UI_Broadcast_CutCurrentBroadcast) end --region -- **************** 顶部跑马灯 ******************* -- function Broadcast_Model.GetBroadcastMsg_Top() local msg = private.broadcastMsgList_Top[1] if msg and CTL.Broadcast.IfCanShowBroadcast(msg.mapUIType) then return msg else Broadcast_Model.RemoveBroadcastMsg_Top() return nil end end function Broadcast_Model.InsertBroadcastMsg_Top(msgData) table.insert(private.broadcastMsgList_Top, msgData) local listLength = #private.broadcastMsgList_Top --按照打断优先级和普通优先级进行排序 if listLength > 1 then table.sort(private.broadcastMsgList_Top, private.SortMsgByPriority) end --排序后超过上限则舍弃后边的 if listLength > BroadcastCacheNum then table.remove(private.broadcastMsgList_Top) end --比较current和新插入的msgData打断优先级,是否需要打断 local firstBroadcastMsg = private.broadcastMsgList_Top[1] if CTL.Broadcast.IfCanShowBroadcast(firstBroadcastMsg.mapUIType) then local existedBroadcastMsg = CTL.Broadcast.GetExistedBroadcastMsg_Top() if existedBroadcastMsg and firstBroadcastMsg then if firstBroadcastMsg.BreakPriority > existedBroadcastMsg.BreakPriority then Broadcast_Model.CutCurrentBroadcast_Top() end end end EventSystem.Dispatch(EventID.UI_Broadcast_UpdateBroadcastTop) end function Broadcast_Model.RemoveBroadcastMsg_Top() table.remove(private.broadcastMsgList_Top, 1) end function Broadcast_Model.ClearBroadcastMsg_Top() private.broadcastMsgList_Top = {} end function Broadcast_Model.CutCurrentBroadcast_Top() EventSystem.Dispatch(EventID.UI_Broadcast_CutCurrentBroadcastTop) end --endregion -- *********************************** -- --endregion --region -- **************** GM中跑马灯 ******************* -- function Broadcast_Model.GetBroadcastGM() return private.GMBroadcastList[1] end function Broadcast_Model.InsertBroadcastGM(msgData) table.insert(private.GMBroadcastList, msgData) --按照优先级排序 if #private.GMBroadcastList > 1 then table.sort(private.GMBroadcastList, function(a, b) return a.priority > b.priority end) end EventSystem.Dispatch(EventID.UI_Broadcast_UpdateGM) end function Broadcast_Model.RemoveBroadcastGM() table.remove(private.GMBroadcastList, 1) end function Broadcast_Model.ClearBroadcastGM() private.GMBroadcastList = {} end --endregion function Broadcast_Model.OnShutdown() end return Broadcast_Model