local UIChapterGoalGet = UIViewClass() --富文本的处理常量 local NumberGradient1 = "06555a" local NumberGradient2 = "54ffd1" local FormatGradient1 = "6A141E" local FormatGradient2 = "DC3E32" local SizeFormat = "%s" local Delimiter = "%s" function UIChapterGoalGet:OnOpened(context) self.autoExitLevelTime = DataSheetManager.ConstData:GetDataByID("AutoExitBarrier").IntValue self:Init(context.amountCount, context.completeCount) self:StartRepeatFunc(self.OnUpdateFun, 0) end function UIChapterGoalGet:OnButtonClicked(comp) if comp == self.event_Close then self:OnClickToTownButton() end end function UIChapterGoalGet:Init(amountCount, completeCount) self.slider_Score.value = completeCount / amountCount UIUtils.SetLocalizationImage(self.img_title01, "dqplt_msz_02.png") self:ProcessRichTxt(amountCount - completeCount) end --对进度说明文本的单独处理,一个文本,中间插了个数字,需要数字有自己的渐变、大小、阴影,剩余的有自己的渐变色 function UIChapterGoalGet:ProcessRichTxt(num) local formatTxt local txtContent if num <= 0 then formatTxt = UIUtils.GetLocalizedTxt(Const_IDS.IDS_ChapterGoal_DQGet_Hint6) txtContent = UTL.Color.FormatGradient(FormatGradient1, FormatGradient2, formatTxt) UIUtils.SetActive(self.lab_Time.gameObject, false) UIUtils.SetActive(self.txt_Else.gameObject, true) UIUtils.SetLabel(self.txt_Else, txtContent) else formatTxt = UIUtils.GetLocalizedTxt(Const_IDS.IDS_ChapterGoal_DQGet_Hint3) local numStr = string.format(SizeFormat, num) local colorNumStr = UTL.Color.FormatGradient(NumberGradient1, NumberGradient2, numStr) local splitTxt = string.split(formatTxt, Delimiter) local colorFormatTxt --按占位符位置的三种可能性还原 if string.sub(formatTxt, 1, string.len(Delimiter)) == Delimiter then --占位符在开头 colorFormatTxt = Delimiter .. UTL.Color.FormatGradient(FormatGradient1, FormatGradient2, splitTxt[2]) elseif string.sub(formatTxt, -string.len(Delimiter)) == Delimiter then --占位符在结尾 colorFormatTxt = UTL.Color.FormatGradient(FormatGradient1, FormatGradient2, splitTxt[1]) .. Delimiter else --占位符在中间,中文就是这样 colorFormatTxt = UTL.Color.FormatGradient(FormatGradient1, FormatGradient2, splitTxt[1]) .. Delimiter .. UTL.Color.FormatGradient(FormatGradient1, FormatGradient2, splitTxt[2]) end txtContent = string.format(colorFormatTxt, " " .. colorNumStr .. " ") --UE希望数字左右要空开些 UIUtils.SetActive(self.lab_Time.gameObject, true) UIUtils.SetActive(self.txt_Else.gameObject, false) UIUtils.SetLabel(self.lab_Time, txtContent) end end function UIChapterGoalGet:OnUpdateFun(_, timeSinceUpdate) UIUtils.SetLabel(self.labLocal_Timer, string.format(UIUtils.GetLocalizedTxt(Const_IDS.IDS_AutoExit), math.abs(math.ceil(self.autoExitLevelTime - timeSinceUpdate)))) if timeSinceUpdate > self.autoExitLevelTime then self:OnClickToTownButton() end end function UIChapterGoalGet:OnClickToTownButton() MDL.Level.SendRoleLeaveFuben() self:StopRepeatFunc(self.OnUpdateFun) end return UIChapterGoalGet