local UICommonProgressBar = UIViewClass() local EventSystem = require('Event/EventSystem') -- context的数据包括 callback, duration, titleStr function UICommonProgressBar:OnOpened(context) self.context = context self.isRunning = false self.amount = 0 self.duration = context.duration or 3 self.timeEla = 0 self.timeStr = UIUtils.GetLocalizedTxt(Const_IDS.IDS_Map_Transmitting_Time) self.lab_Move.text = context.titleStr self:SetPushStyle(LuaConst.PushStyleEnum.HIDE) self:Refresh() self:Start() if context.breakEvent then self:RegistSystemEvent(context.breakEvent, self.ProgressBarBreak) end end function UICommonProgressBar:Refresh() self.slider_ProgressBar.value = self.amount self.lab_Time.text = string.format(self.timeStr, self.timeEla, self.duration) end function UICommonProgressBar:Start() self.isRunning = true self:StartRepeatFunc(self.OnUpdateFun, 0) end function UICommonProgressBar:ResetTimeEla() self.timeEla = 0 self:Refresh() end function UICommonProgressBar:SetTimeEla(timeEla) self.timeEla = timeEla self.amount = self.timeEla / self.duration end function UICommonProgressBar:OnProgressFinish() self.isRunning = false if self.context.callback then self.context.callback() end self:CloseView() end function UICommonProgressBar:OnUpdateFun(deltaTime, timeSinceUpdate) if self.isRunning then self:SetTimeEla(self.timeEla + deltaTime) self:Refresh() if self.amount >= 1 then self:OnProgressFinish() end end end function UICommonProgressBar:ProgressBarBreak() if self.context.breakCallback then self.context.breakCallback() end self.isRunning = false self:CloseView() end function UICommonProgressBar:OnClosed() if self.isRunning then if self.context.breakCallback then self.context.breakCallback() end end end return UICommonProgressBar