local UIDialogueNormalView = UIViewClass() local SPEED_TYPER = 15 local TIME_INTERVAL = 2.8 function UIDialogueNormalView:OnOpened(context) self.isNeedActiveUIModle = false self.dialogueQueue ={} if context.taskChildData then self:StartTask(context.taskChildData, context.callback, context.entity) else self:Start(context.dialogueID,context.callback,context.context,context.entity) end self:RegistSystemEvent(EventID.Level_Pause, self.Pause) self:RegistSystemEvent(EventID.Task_StartTask, self.StartTask) self:RegistSystemEvent(EventID.FunctionUnlockUpdate, self.OnCloseGamePlay) end function UIDialogueNormalView:OnClosed() self.dialogueQueue =nil self.curDialogue = nil self.duration = nil self.curUniqueDialogue = nil end function UIDialogueNormalView:OnCloseGamePlay(funcId, isUnlock) --破袭曲阳、诸侯讨董 玩法关闭时,关闭相应的对话 if self.contextParam and self.contextParam.ID == LuaConst.NpcID.TeamDungeon and funcId == MDL.Unlock.FunctionType.TeamDungeon then if not isUnlock then self:OnButtonClicked(self.event_Btn2) --采用模拟点击按钮2的方法关闭 return end end if self.contextParam and self.contextParam.ID == LuaConst.NpcID.TeamDungeon2 and funcId == MDL.Unlock.FunctionType.TeamDungeon2 then if not isUnlock then self:OnButtonClicked(self.event_Btn2) --采用模拟点击按钮2的方法关闭 return end end end function UIDialogueNormalView:OnUpdateFun(deltaTime, timeSinceUpdate) self.timer = timeSinceUpdate if timeSinceUpdate > self.duration then self:UpdateState() end end function UIDialogueNormalView: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.entity = entity dialogue.callback = callback dialogue.list = MDL.Dialogue.GetDialogueListByID(dialogueID) if context then if not string.isNilOrEmpty(context.Func1Name) then dialogue.button1 = {} if context.Func1[2] == "UIGoldenHeroStory" then context.Func1[5] = MDL.GoldenHeroStory.GetActivityIDByTaskLineID(context.TaskLineID) elseif context.Func1[2] == "UISuperGoldStoryMain" then context.Func1[5] = MDL.SuperGoldStory.GetActivityIDByTaskLineID(context.TaskLineID) end dialogue.button1.func = context.Func1 dialogue.button1.name = context.Func1Name end if not string.isNilOrEmpty(context.Func2Name) then dialogue.button2 = {} dialogue.button2.func = context.Func2 dialogue.button2.name = context.Func2Name end self.contextParam = context --这里缓存一下,在外部需要关闭对话时使用 end self:Begin(dialogue) end end function UIDialogueNormalView:StartTask(taskChildData, callback, entity) if string.isNilOrEmpty(taskChildData.Factor) then return end local factorList = string.split(taskChildData.Factor,',') local dialogueID = factorList[1] local dialogue = {} dialogue.id = dialogueID dialogue.entity = entity dialogue.callback = callback dialogue.list = MDL.Dialogue.GetDialogueListByID(dialogueID) local btn1Name = factorList[2] if not string.isNilOrEmpty(btn1Name) then dialogue.button1 = {} dialogue.button1.name = btn1Name dialogue.button1.value = 0 end local btn2Name = factorList[3] if not string.isNilOrEmpty(btn2Name) then dialogue.button2 = {} dialogue.button2.name = btn2Name dialogue.button2.value = 1 end self:Begin(dialogue) end function UIDialogueNormalView:Begin(dialogue) if not self.curDialogue then UIUtils.SetActive(self.gameObject,true) self.curDialogue = dialogue self:Show(dialogue,true) else table.insert(self.dialogueQueue,dialogue) end end function UIDialogueNormalView:Finish() self:RefreshStartUpdate(false) --self:StopTyper() CameraController.Instance:SetTalkSystem(false, nil) if self.isNeedActiveUIModle then UIManager.ActiveUIModle(true, "UIDialogueNormalView") self.isNeedActiveUIModle = false end self:CloseView(true) end function UIDialogueNormalView:Show(dialogue,first) if first then UIUtils.SetActive(self.event_Btn1.gameObject,false) UIUtils.SetActive(self.event_Btn2.gameObject,false) if dialogue.entity then CameraController.Instance:SetTalkSystem(true, dialogue.entity.ExpEntity:GetRenderEntity()) if not self.isNeedActiveUIModle then UIManager.ActiveUIModle(false, "UIDialogueNormalView") self.isNeedActiveUIModle = true end end end local withBtn = false if #dialogue.list == 1 then if dialogue.button1 then UIUtils.SetActive(self.event_Btn1.gameObject,true) UIUtils.SetLabelText(self.labLocal_Btn1,Const_IDS[dialogue.button1.name]) withBtn = true end if dialogue.button2 then UIUtils.SetActive(self.event_Btn2.gameObject,true) UIUtils.SetLabelText(self.labLocal_Btn2,Const_IDS[dialogue.button2.name]) withBtn = true end end 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 --self:StopTyper() UIUtils.SetLabelText(self.labLocal_Content,Const_IDS[curData.Text]) --[[ UIUtils.SetLabel(self.labLocal_Content,'') local content = UIUtils.GetLocalizedTxt(Const_IDS[curData.Text]) local strLength = #content self.typerTime = curData.ShowTime == 0 and strLength/SPEED_TYPER or curData.ShowTime self.labLocal_Content:StartTypeWriter(content, self.typerTime) ]]-- if self.duration then self:RefreshStartUpdate(false) end if not withBtn then self:RefreshStartUpdate(true, curData.Duration) --curData.Duration == 0 and self.typerTime + TIME_INTERVAL or curData.Duration end end function UIDialogueNormalView:RefreshStartUpdate(isStart, duration) if isStart then self.duration = duration self:StartRepeatFunc(self.OnUpdateFun, 0) else self:StopRepeatFunc(self.OnUpdateFun) self.duration = nil end end function UIDialogueNormalView:Stop(dialogue,value) if dialogue.callback then dialogue.callback(dialogue.id,value) 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 UIDialogueNormalView:UpdateState() if self.curDialogue.list and #self.curDialogue.list>0 then self:Show(self.curDialogue) else if self.curDialogue.button1 and self.curDialogue.button2 then return end self:Stop(self.curDialogue) end end function UIDialogueNormalView:OnBackButtonPressed() if BattleDataGetter.IsNoBattleLevel() then self:OnButtonClicked(self.event_Btn2) end end function UIDialogueNormalView:OnButtonClicked(obj) if obj==self.event_Btn1 then self:OnButtonFunction(self.curDialogue.button1) elseif obj==self.event_Btn2 then self:OnButtonFunction(self.curDialogue.button2) elseif obj==self.event_Next then self:UpdateState() --[[ if self:InTyper() then self:EndTyper() else self:UpdateState() end ]]-- end end function UIDialogueNormalView:OnButtonFunction(button) self:Stop(self.curDialogue,button.value) if button.func then self:DoButtonFunction(unpack(button.func)) end end function UIDialogueNormalView:DoButtonFunction(funcName,...) if funcName then local buttonFunc = CTL.Dialogue[funcName] if not buttonFunc then return end buttonFunc(...) end end function UIDialogueNormalView:Pause(pause) if pause then self:RefreshStartUpdate(false) --self:PauseTyper() else if self.timer and self.duration then self:RefreshStartUpdate(true, self.duration - self.timer) end --self:ResumeTyper() end end function UIDialogueNormalView:InTyper() return self.labLocal_Content:IsPlayingTypeWriter() end function UIDialogueNormalView:PauseTyper() self.labLocal_Content:PauseTypeWriter() end function UIDialogueNormalView:ResumeTyper() self.labLocal_Content:ResumeTypeWriter() end function UIDialogueNormalView:EndTyper() self.labLocal_Content:StopTypeWriter() if not self.duration then return end local leftTime = self.duration - self.typerTime self:RefreshStartUpdate(true, leftTime > 0 and leftTime or 0) end function UIDialogueNormalView:StopTyper() self.labLocal_Content:StopTypeWriter() end return UIDialogueNormalView