local UIDialogueLightView = UIViewClass() local SPEED_TYPER = 30 local TIME_INTERVAL = 2 local HeadImgPath = ConstAssetPathConfig.HeadImgPath function UIDialogueLightView:OnOpened(context) self.dialogueQueue ={} self:StartRepeatFunc(self.OnUpdateFun, 0) if context.dialogueID then self:Start(context.dialogueID,context.callback,context.context,context.entity) else self:StartTip(context.title,context.str,context.icon,context.duration) end self:RegistSystemEvent(EventID.Level_Pause, self.Pause) end --自定义显示对话,不走对话表 function UIDialogueLightView:StartTip(title,str,icon,duration) local dialogue = str self.duration=duration self.customIcon=icon self.title=title self:Begin(dialogue) end function UIDialogueLightView:OnClosed() self.dialogueQueue =nil self.curDialogue = nil self.duration = nil self.timer = nil self.curUniqueDialogue = nil self:StopTyper() end function UIDialogueLightView:OnUpdateFun(deltaTime, timeSinceUpdate) self.timer = timeSinceUpdate if timeSinceUpdate > self.duration then self:UpdateState() end end function UIDialogueLightView:Start(dialogueID, callback, context, entity) 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) dialogue.entity = entity self:Begin(dialogue) end end function UIDialogueLightView: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 UIDialogueLightView:Finish() self:StopRepeatFunc(self.OnUpdateFun) self.duration = nil self:StopTyper() self:CloseView() end function UIDialogueLightView:Show(dialogue) if dialogue.list then local curData = table.remove(dialogue.list,1) if string.isNilOrEmpty(curData.SpeakerName) then if dialogue.entity then UIUtils.SetLabelText(self.labLocal_Name,Const_IDS[BattleDataGetter.GetHeroName(dialogue.entity)]) else self.labLocal_Name.text = BattleDataGetter.GetPlayerName() end else UIUtils.SetLabelText(self.labLocal_Name,Const_IDS[curData.SpeakerName]) end if string.isNilOrEmpty(curData.Texture) then if dialogue.entity then UIUtils.SetImageByAssetBundle(self.sprite_Head, string.format(HeadImgPath,BattleDataGetter.GetHeroHeadIcon(dialogue.entity))) else UIUtils.SetImageByAssetBundle(self.sprite_Head, string.format(HeadImgPath,BattleDataGetter.GetMainHeroHeadIcon())) end else UIUtils.SetImageByAssetBundle(self.sprite_Head, string.format(HeadImgPath,curData.Texture)) end local content = UIUtils.GetLocalizedTxt(Const_IDS[curData.Text]) local strLength = #content local typerTime = curData.ShowTime == 0 and strLength/SPEED_TYPER or curData.ShowTime self.labLocal_Content:StartTypeWriter(content, typerTime) self.duration = curData.Duration == 0 and typerTime + TIME_INTERVAL or curData.Duration if not string.isNilOrEmpty(curData.Voice) then CTL.Sound.PlayGameSound(curData.Voice) end else --自定义对话 UIUtils.SetLabel(self.labLocal_Name,self.title) UIUtils.SetImageByAssetBundle(self.sprite_Head, string.format(HeadImgPath,self.customIcon)) self.customIcon=nil UIUtils.SetLabel(self.labLocal_Content,dialogue) end self:ResetRepeatFunc(self.OnUpdateFun) end function UIDialogueLightView: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 UIDialogueLightView:UpdateState() if self.curDialogue.list and #self.curDialogue.list>0 then self:Show(self.curDialogue) else self:Stop(self.curDialogue) end end function UIDialogueLightView:Pause(pause) if pause then self:StopRepeatFunc(self.OnUpdateFun) self:PauseTyper() else if self.timer then self.duration = self.duration - self.timer end self:StopRepeatFunc(self.OnUpdateFun) self:StartRepeatFunc(self.OnUpdateFun, 0) self:ResumeTyper() end end function UIDialogueLightView:PauseTyper() self.labLocal_Content:PauseTypeWriter() end function UIDialogueLightView:ResumeTyper() self.labLocal_Content:ResumeTypeWriter() end function UIDialogueLightView:StopTyper() self.labLocal_Content:StopTypeWriter() end return UIDialogueLightView