local UIDialogueTipView = UIViewClass() local AnimAppear = ConstAssetPathConfig.AnimAppear local AnimDisappear = ConstAssetPathConfig.AnimDisappear local Stage_Appear = 1 local Stage_Maintain = 2 local Stage_Disappear = 3 function UIDialogueTipView:OnOpened(context) self:SetDefaultDuration(context) self.dialogueQueue ={} if context.dialogueID then self:Start(context.dialogueID,context.callback,context.context,context.entity) else self:StartTip(context.str) end self:RegistSystemEvent(EventID.Level_Pause, self.Pause) self.stage = 0 self.timeMaintain = 0 CTL.Setting.SetPCScrollMsgViewScale(self.gameObject.transform) end function UIDialogueTipView:SetDefaultDuration(context) if context.duration then self.DefaultDuration = context.duration else self.DefaultDuration = 1 end end function UIDialogueTipView:OnClosed() if self.appearAnimID then self:StopUIAnimation(self.appearAnimID) end if self.disappearAnimID then self:StopUIAnimation(self.disappearAnimID) end self.dialogueQueue = nil self.curDialogue = nil self.appearAnimID = nil self.disappearAnimID = nil self.curUniqueDialogue = nil self.stage = 0 end function UIDialogueTipView:Start(dialogueID, callback) local dialogue if MDL.Dialogue.CheckDialogueUniqueByID(dialogueID) then if not self.curUniqueDialogue then dialogue = {} self.curUniqueDialogue = dialogue end else dialogue = {} end if dialogue then dialogue.id = dialogueID dialogue.callback = callback dialogue.list = MDL.Dialogue.GetDialogueListByID(dialogueID) self:Begin(dialogue) end end function UIDialogueTipView:StartTip(str) local dialogue = str self:Begin(dialogue) end function UIDialogueTipView:Begin(dialogue) if not self.curDialogue then UIUtils.SetActive(self.gameObject,true) self.curDialogue = dialogue self:Show(dialogue) else table.insert(self.dialogueQueue,dialogue) end end function UIDialogueTipView:Finish() self:CloseView() end function UIDialogueTipView:Show(dialogue) if dialogue.list then local curData = table.remove(dialogue.list,1) self:SetShowText(UIUtils.GetLocalizedTxt(Const_IDS[curData.Text])) self.duration = curData.Duration else self:SetShowText(dialogue) self.duration = self.DefaultDuration end -- play appear animation self.stage = Stage_Appear if self.appearAnimID then self:PlayUIAnimation(self.appearAnimID) else self.appearAnimID = self:PlayUIAnimation(AnimAppear, self.group_Tip.transform, true) end end function UIDialogueTipView:SetShowText(text) self.txt_Info:SetText(text) end function UIDialogueTipView:OnUIAnimationStoped(playingID) if playingID == self.appearAnimID then -- 出现动画结束时,开启显示计时 self.stage = Stage_Maintain self:StartRepeatFunc(self.OnUpdateFun, 0) elseif playingID == self.disappearAnimID then -- 消失动画结束时,开始下一条对话 self:UpdateState() end end function UIDialogueTipView:OnUpdateFun(deltaTime, timeSinceUpdate) self.timeMaintain = timeSinceUpdate if timeSinceUpdate > self.duration then -- play disappear animation self.stage = Stage_Disappear if self.disappearAnimID then self:PlayUIAnimation(self.disappearAnimID) else self.disappearAnimID = self:PlayUIAnimation(AnimDisappear, self.group_Tip.transform, true) end self:StopRepeatFunc(self.OnUpdateFun) end end function UIDialogueTipView:Stop(dialogue) if dialogue.callback then dialogue.callback(dialogue.id) dialogue.callback = nil end if dialogue == self.curUniqueDialogue then self.curUniqueDialogue = nil end self.curDialogue = table.remove(self.dialogueQueue,1) if self.curDialogue then self:Show(self.curDialogue, true) else self:Finish() end end function UIDialogueTipView:UpdateState() if self.curDialogue.list and #self.curDialogue.list>0 then self:Show(self.curDialogue) else self:Stop(self.curDialogue) end end function UIDialogueTipView:Pause(pause) if pause then self:PauseSequence() else self:ResumeSequence() end end function UIDialogueTipView:PauseSequence() if self.stage == Stage_Appear then self:PauseUIAnimation(self.appearAnimID) elseif self.stage == Stage_Maintain then self.duration = self.duration - self.timeMaintain self:StopRepeatFunc(self.OnUpdateFun) elseif self.stage == Stage_Disappear then self:PauseUIAnimation(self.disappearAnimID) end end function UIDialogueTipView:ResumeSequence() if self.stage == Stage_Appear then self:ResumeUIAnimation(self.appearAnimID) elseif self.stage == Stage_Maintain then self:StopRepeatFunc(self.OnUpdateFun) self:StartRepeatFunc(self.OnUpdateFun, 0) elseif self.stage == Stage_Disappear then self:ResumeUIAnimation(self.disappearAnimID) end end return UIDialogueTipView