local UIGMBroadcast = UIViewClass() -- GM跑马灯数值参数 local START_SHOW_TIME = FP.tonumberV1(DataSheetManager.ConstData:GetDataByID("BroadcastStartSeconds").FloatValue) local END_DELAY_TIME = FP.tonumberV1(DataSheetManager.ConstData:GetDataByID("BroadcastEndSeconds").FloatValue) local ANIMATION_END_TIME = 0.1 local SCROLLING_SPEED = DataSheetManager.ConstData:GetDataByID("BroadCastSpeedHigh").IntValue function UIGMBroadcast:OnOpened() self:RegistSystemEvent(EventID.UI_Broadcast_UpdateGM, self.RecoverGMBroadcast) self.imgTf = self.img_Bg.transform self.bgLength = self.ScrollingBg:GetSizeDelta() local GMMsg = MDL.Broadcast.GetBroadcastGM() if GMMsg then self:ShowBroadcastGM(GMMsg) end end function UIGMBroadcast:OnClosed() self:StopCurrentBroadcastGM() end function UIGMBroadcast:RecoverGMBroadcast() --判断当前是否正在广播消息,如果有则直接返回 if CTL.Broadcast.GetExistedBroadcastGM() then return end local GMMsg = MDL.Broadcast.GetBroadcastGM() if GMMsg then self:ShowBroadcastGM(GMMsg) self:PlayShowAnim() end end function UIGMBroadcast:RefreshGMBroadcast(deltaTime, timeSinceUpdate) local gmMsg = MDL.Broadcast.GetBroadcastGM() if gmMsg and CTL.Broadcast.GetExistedBroadcastGM() then self:StopCurrentBroadcastGM() self:ShowBroadcastGM(gmMsg) else self:StopRepeatFunc(self.RefreshBroadcast) self:PlayEndAnim() end end function UIGMBroadcast:ShowBroadcastGM(GMMsg) self:PlayShowAnim() self:SetBroadcastGM(GMMsg) MDL.Broadcast.RemoveBroadcastGM() end function UIGMBroadcast:SetBroadcastGM(textData) if textData then local objLength = self.scrollingGMText:PlayBroadcastMsg(textData.content, SCROLLING_SPEED, START_SHOW_TIME, self.bgLength) local deltaLength = objLength - self.bgLength < 0 and 0 or objLength - self.bgLength local deltaTime = deltaLength / SCROLLING_SPEED local requireTime = deltaTime + START_SHOW_TIME + END_DELAY_TIME + ANIMATION_END_TIME CTL.Broadcast.SetExistedBroadcastGM(textData) self:StartRepeatFunc(self.RefreshGMBroadcast, requireTime, 1) else self:RefreshGMBroadcast() end end function UIGMBroadcast:StopCurrentBroadcastGM() if CTL.Broadcast.GetExistedBroadcastGM() then self.scrollingGMText:StopBroadcastMsg() CTL.Broadcast.ClearExistedBroadcastGM() end end function UIGMBroadcast:PlayShowAnim() if self.animShow then self:PlayUIAnimation(self.animShow) else self.animShow = self:PlayUIAnimation("GMBroadcastShow") end end function UIGMBroadcast:PlayEndAnim() local _, sy = self.imgTf:GetLocalScale() if sy ~= 0 then if self.animEnd then self:PlayUIAnimation(self.animEnd) else self.animEnd = self:PlayUIAnimation("GMBroadcastEnd", true) end end end function UIGMBroadcast:OnUIAnimationStoped(playingID) if playingID == self.animEnd then self:StopCurrentBroadcastGM() CTL.Broadcast.RecoverTopBroadcast() end end return UIGMBroadcast