local UITownTaskGuide = UIViewClass() local SLECT_EFFECT_NORMALIZED_SIZE = 285 local REFRESH_EFFECT_NORMALIZED_SIZE = 133 local progressStr = "%s/%s" local EventSystem = require('Event/EventSystem') function UITownTaskGuide:OnCreated() self.heroImageTrans = self.img_HeroHead.transform self.heroImageRect = self.img_HeroHead.rectTransform self.heroAnchorPosX, self.heroAnchorPosY = self.heroImageRect:GetAnchoredPosition() self.countDownTime = 0 self.countDownTaskInfo = {} self.selectIndex = 0 end function UITownTaskGuide:OnOpened() self.taskCellList = {} self:UpdateTaskList() self:RegistSystemEvent(EventID.UI_Task_Update, self.UpdateTaskList) self:RegistSystemEvent(EventID.UI_Task_SetAuto, self.UpdateTaskList) self:RegistSystemEvent(EventID.UI_Task_BreakAuto, self.OnBreakAutoTask) self:RegistSystemEvent(EventID.UI_Task_MoveTo, self.MoveToTask) -- 功能解锁 等级变化 主线子任务完成 都要刷新章节奖励 self:RegistSystemEvent(EventID.FunctionUnlockUpdate, self.RefreshChapterGoal) self:RegistSystemEvent(EventID.FunctionUnlockUpdate, self.UpdateTaskList) self:RegistSystemEvent(EventID.ChildTaskFinish, self.RefreshChapterGoal) self:RegistSystemEvent(EventID.UI_UpdateRoleInfo, self.RefreshChapterGoal) self:RegistSystemEvent(EventID.UI_ChapterGoal_NewUnlock,self.PlayChapterGoalUnlock) self:RegistSystemEvent(EventID.UI_ChapterGoal_SetParent, self.SetChapterGoalParent) self:RegistSystemEvent(EventID.UI_ChapterGoal_FirstUnlockPlayStart, self.PlayChapterGoalNewUnlockStart) self:RegistSystemEvent(EventID.UI_ChapterGoal_NewUnlockPlayEnd,self.PlayChapterGoalUnlockEnd) self:RegistSystemEvent(EventID.UI_ChapterGoal_RefreshChapterAward, self.RefreshChapterGoal) self:RefreshChapterGoal() end function UITownTaskGuide:OnUpdateFun(deltaTime, timeSinceUpdate) if self.countDownTime < timeSinceUpdate then self:StopRepeatFunc(self.OnUpdateFun) MDL.Task.TaskClientTimeFinishRequest(self.countDownTaskInfo.taskMainId, self.countDownTaskInfo.childInfo[1].taskChildId) end end function UITownTaskGuide:UpdateTaskList() if self.allTaskList == nil then self.allTaskList = {} else table.clearArray(self.allTaskList) end for _, type in ipairs(MDL.Task.List_TaskType) do local taskList = MDL.Task.GetTaskList(type) if type == MDL.Task.Enum_TaskType.Wanted then taskList = CTL.CountryWantedTask.GetSortedTask(taskList) end if taskList then for __, task in pairs(taskList) do if task.TaskData.Type ~= MDL.Task.Enum_TaskType.GoldHeroActivity or MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.GoldHeroActivity) or task.TaskData.Type ~= MDL.Task.Enum_TaskType.SuperGoldHero or MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.SuperGoldActivity) then table.insert(self.allTaskList, task) end end end end -- 检查是否有计时任务 local haveConstDown = false -- 是否有倒计时, 倒计时, 有倒计时的任务数据 haveConstDown, self.countDownTime, self.countDownTaskInfo = MDL.Task.GetCountdown() if haveConstDown and self.countDownTime > 0 then self:StartRepeatFunc(self.OnUpdateFun, 1) else self:StopRepeatFunc(self.OnUpdateFun) end self.loopScroll_Panel:ReloadAll(self.allTaskList) --没有正在选中的任务,有悬赏任务时,选中悬赏任务 中的采集任务 for i,v in ipairs(self.allTaskList) do if MDL.Task.DoingTask then if MDL.Task.DoingTask == v then self.selectIndex = i - 1 break end else if v.TaskData.Type == MDL.Task.Enum_TaskType.Wanted and v.taskChildData[1].ActionType == MDL.Task.Enum_ActionType.Collection then self.selectIndex = i - 1 break end end end self.loopScroll_Panel:MoveIndex(self.selectIndex); if self.selectCell then self:FitSelectEffectHeight(self.selectCell) end if self.refreshCell then self:FitRefreshEffectHeight(self.refreshCell) self.refreshCell = nil end end function UITownTaskGuide:MoveToTask(task) local moveIndex = 0 for i,v in ipairs(self.allTaskList) do if task then if task == v then moveIndex = i - 1 break end end end if moveIndex >= 0 then self.loopScroll_Panel:MoveIndex(moveIndex); end end function UITownTaskGuide:OnButtonClicked(obj) if obj == self.img_Bg then UIManager.OpenView(Const_UI_Lua.UIEnum.UIChapterGoal) end end --region -- **************** cell ******************* -- function UITownTaskGuide:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loopScroll_Panel then self:SetTaskCell(cellTable, data, index) self:CacheCellPos(cellTable) end end function UITownTaskGuide:CacheCellPos(cellTable) if CTL.CountryWantedTask.GetCacheTaskCellPos() == nil then local cellPos = {} local x,y = cellTable.cell.transform.parent:GetLocalPosition() cellPos.x = x + cellTable.cell.transform.rect.width cellPos.y = y CTL.CountryWantedTask.CacheTaskCellPos(cellPos) end end function UITownTaskGuide:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loopScroll_Panel then if target == cellTable.event_Item then self:OnTaskItemClick(data) elseif target == cellTable.btn_LaterEnter then --没下完所有分包不允许跳过剧情,防止资源错误 if CTL.HotFix.Get_IfAllDownload() == false then CTL.Tips.AddTipsMsg(Const_IDS["IDS_LaterEnter_Hint_9"]) CTL.HotFix.OpenStageDownloadUI() return end local taskMainId = data.taskInfo.taskMainId local taskFatherData = DataSheetManager.TaskFatherData:GetDataByID(taskMainId) local chapterData = DataSheetManager.TaskChapterData:GetDataByID(taskFatherData.BelongToChapter) UTL.MessageBox.ShowOKCancelBox( string.FormatByIdsKey("IDS_LaterEnter_Hint_5", taskFatherData.BelongToChapter), UIUtils.GetLocalizedTxt(Const_IDS[chapterData.Synopsis]), function() MDL.Task.QuickFinishChapterTaskReq(taskMainId) end, nil, UIUtils.GetLocalizedTxt(Const_IDS["IDS_LaterEnter_Hint_6"]) ) else self:OnTaskCellClick(cellTable,data,index) end end end function UITownTaskGuide:SetTaskCell(cellTable, task, index) if cellTable == nil then return end UIUtils.SetActive(cellTable.group_Tag.gameObject,false) UIUtils.SetActive(cellTable.group_Star.gameObject,false) local taskTypeEnum = MDL.Task.Enum_TaskType local titile = UIUtils.GetLocalizedTxt(Const_IDS[DataSheetManager.TaskTypeData:GetDataByID(task.TaskData.Type).TaskText]) local taskProgressStr = "" if task.TaskData.Type == taskTypeEnum.RingDaily then -- 日常环任务 titile = UIUtils.GetLocalizedTxt(Const_IDS[DataSheetManager.TaskTypeData:GetDataByID(task.TaskData.Type).TaskText]) local dailyRingConfig = DataSheetManager.RingTaskRefresh:GetDataByID(MDL.Task.Enum_RingTaskType.RingDaily) if dailyRingConfig then taskProgressStr = string.format("(%s/%s)",MDL.Task.CurRingDailyNum,dailyRingConfig.TimesNum) end elseif task.TaskData.Type == taskTypeEnum.GoldHeroActivity then -- 金将活动任务 for k,v in DataSheetManager.GoldHeroActivityTask:GetEnumerator() do if v.TaskChainID == task.TaskData.ID then UIUtils.SetActive(cellTable.group_Tag.gameObject,true) UIUtils.SetLabelText(cellTable.txt_Tag, Const_IDS[v.Des]) cellTable.state_TxtBg:SetState(v.BasePictureID - 1) end end elseif task.TaskData.Type == taskTypeEnum.SuperGoldHero then -- 彩金将活动任务 for k,v in DataSheetManager.SuperGoldStoryTask:GetEnumerator() do if v.TaskChainID == task.TaskData.ID then UIUtils.SetActive(cellTable.group_Tag.gameObject,true) UIUtils.SetLabelText(cellTable.txt_Tag, Const_IDS[v.Des]) cellTable.state_TxtBg:SetState(v.BasePictureID - 1) end end elseif task.TaskData.Type == taskTypeEnum.Wanted then --悬赏任务 --需要显示进度的 if task.taskChildData[1].ShowTaskRate then local completeCondition = CTL.CountryWantedTask.GetTaskCompleteConditionPrams(task.taskChildData[1].TaskLineID,task.taskChildData[1].TaskChildID) local completeNum = completeCondition ==nil and 0 or tonumber(completeCondition) local taskProgress = 0 if task.taskInfo.childInfo[1].process then taskProgress = task.taskInfo.childInfo[1].process.param end if taskProgress >= completeNum then taskProgress = completeNum end taskProgressStr = string.format("(%s/%s)",taskProgress,completeCondition) end --任务星级 local taskWantedData = MDL.CountryWantedTask.GetTaskStarForShow(task.taskChildData[1].TaskLineID) if taskWantedData then UIUtils.SetActive(cellTable.group_Star.gameObject,true) UIUtils.SetLabel(cellTable.txt_Star,tostring(taskWantedData.TaskQuality)) end end -- 任务标题 if GameAppInfo.IsVietnamPackage() then UIUtils.SetLabel(cellTable.localLab_Title, string.Concat(titile, " ",UIUtils.GetLocalizedTxt(Const_IDS[task.TaskData.Brief]), taskProgressStr)) else UIUtils.SetLabel(cellTable.localLab_Title, string.Concat(titile, UIUtils.GetLocalizedTxt(Const_IDS[task.TaskData.Brief]), taskProgressStr)) end for i=1,3 do if task.taskInfo.childInfo[i] then UIUtils.SetActive(cellTable.localLab_Array[i].gameObject,true) -- 显示任务目标 UIUtils.SetActive(cellTable.localLab_Array[i].cdTimer.gameObject,false) -- 倒计时先隐藏 UIUtils.SetActive(cellTable.localLab_Array[i].localLab_Content.gameObject, true) if task.taskInfo.childInfo[i].taskState == MDL.Task.Enum_TaskState.Finish then UIUtils.SetActive(cellTable.localLab_Array[i].img_Done,true) -- 目标完成标记 UIUtils.SetActive(cellTable.localLab_Array[i].img_Doing,false) -- 任务标记 -- 目标描述 cellTable.localLab_Array[i].localLab_Content.text = UTL.Color.FormatTextByColor("86FA4D",CTL.Task.GetChildTaskDesc(task,i)) else UIUtils.SetActive(cellTable.localLab_Array[i].img_Done,false) UIUtils.SetActive(cellTable.localLab_Array[i].img_Doing,true) cellTable.localLab_Array[i].localLab_Content.text = UTL.Color.FormatTextByColor("D0D2D8",CTL.Task.GetChildTaskDesc(task,i)) end if task.TaskData.IsOrder then UIUtils.SetActive(cellTable.localLab_Array[i].img_Done,false) UIUtils.SetActive(cellTable.localLab_Array[i].img_Doing,false) end else -- 不用的任务目标隐藏 UIUtils.SetActive(cellTable.localLab_Array[i].gameObject,false) end end -- 固定时间完成的任务,如:开服X天自动完成 if task.taskChildData[1].CompleteCondition == 102 then local endTime = task.taskInfo.childInfo[1].autoFinishTime endTime = endTime - UTL.Time.GetServerTimestamp() if endTime <= 0 then MDL.Task.TaskClientTimeFinishRequest(task.taskChildData[1].TaskLineID, task.taskChildData[1].TaskChildID) end UIUtils.SetActive(cellTable.localLab_Array[1].labLocal_.gameObject, endTime > 0) UIUtils.SetActive(cellTable.localLab_Array[1].localLab_Content.gameObject, not (endTime > 0)) cellTable.localLab_Array[1].cdTimer:ResetAndBeginCustomTimer(false, endTime + UTL.Time.TotalSecondsOneMinute, 0, UIUtils.GetLocalizedTxt(Const_IDS[task.taskChildData[1].Des]), 1) self.countDownTime = endTime self.countDownTaskInfo = task.taskInfo if self.countDownTime > 0 then self:StartRepeatFunc(self.OnUpdateFun, 1) else self:StopRepeatFunc(self.OnUpdateFun) end else UIUtils.SetActive(cellTable.localLab_Array[1].labLocal_.gameObject, false) end -- 任务状态 if task.State == MDL.Task.Enum_TaskState.Doing then cellTable.state:SetState(2) elseif task.State == MDL.Task.Enum_TaskState.Failure then cellTable.state:SetState(1) else cellTable.state:SetState(0) end -- 倒计时 if task.TaskData.IsOrder and task.taskInfo.childInfo[1].expireTime>0 then local timeValue = task.taskInfo.childInfo[1].expireTime - UTL.Time.GetServerTimestamp() if timeValue > 0 then cellTable.cdTimer:ResetAndBeginTimer(false,timeValue) end elseif task.TaskData.IsOrder and task.taskChildData[1].ActionType == MDL.Task.Enum_ActionType.WaitTime then local timeValue = task.taskInfo.childInfo[1].acceptTime + tonumber(task.taskChildData[1].Factor) - UTL.Time.GetServerTimestamp() if timeValue>0 then cellTable.cdTimer:ResetAndBeginTimer(false,timeValue) else CTL.Task.DoTask(task) end elseif task.taskChildData[1].CompleteCondition == 101 and self.countDownTaskInfo ~= nil and self.countDownTaskInfo.taskMainId == task.taskChildData[1].TaskLineID and self.countDownTime > 0 then for k,v in pairs(task.taskChildData) do local endTime = task.taskInfo.childInfo[k].autoFinishTime endTime = endTime - UTL.Time.GetServerTimestamp() cellTable.cdTimer:ResetAndBeginTimer(false, endTime) break end else cellTable.cdTimer:EndTimer() end if task.ItemData then UIUtils.SetActive(cellTable.event_Item.gameObject,true) UTL.Item.ItemSquareIcon(cellTable.tex_Item, cellTable.sprite_Rank, task.ItemData.ID) else UIUtils.SetActive(cellTable.event_Item.gameObject,false) end if MDL.Task.DoingTask and MDL.Task.DoingTask == task then local curIndex = CTL.Task.GetTaskCurDoingData(task); if task.taskChildData[curIndex] and task.taskChildData[curIndex].ActionType ~= MDL.Task.Enum_ActionType.Open then self.selectCell = cellTable end self.selectIndex = index else cellTable.effect_Select:StopUIEffect() end --播放刷新特效 if task.IsRefresh then task.IsRefresh = false self.refreshCell = cellTable end --UIUtils.SetActive(cellTable.btn_LaterEnter, task.taskInfo.canFastPass and MDL.LaterEnter.IsLaterEnterOpen()) UIUtils.SetActive(cellTable.btn_LaterEnter,false) end --停止自动任务 function UITownTaskGuide:OnBreakAutoTask(entity) if entity ~= LogicUpdateManager._curEntity then return end if self.selectCell then self.selectCell.effect_Select:StopUIEffect() self.selectCell = nil self.selectIndex = 0 end end function UITownTaskGuide:OnTaskCellClick(cellTable,task,index) if BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.CrossHeroMatchTown) or BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.CrossHeroMatchTown3V3) or BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.TeamFairChampionshipTown) then -- 某些玩法的匹配大厅退出提示 CTL.HeroMatch1v1.QuitFromMatchLobby() return elseif MDL.Team.IsFollowing() then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Team_FollowCanNotDoThis"]) return end if self.selectCell and self.selectCell ~= cellTable then self.selectCell.effect_Select:StopUIEffect() end CTL.Sound.PlayGameSound("UI_daily") local mainID = task.taskInfo.taskMainId local childID = task.taskChildData[1].TaskChildID EventSystem.Dispatch(EventID.BI_ViewClick, BIManager.ViewBIEvent.UITownTaskGuide_Cell, mainID, childID) if task.TaskData.Type == MDL.Task.Enum_TaskType.GoldHeroActivity then -- 金将活动任务 for k,v in DataSheetManager.GoldHeroActivityTask:GetEnumerator() do if v.TaskChainID == task.TaskData.ID then local activityId = MDL.GoldenHeroMain.GetActivityIDByHeroType(v.HeroType) CTL.GoldenHeroStory.ShowSkipTaskPopUp(activityId, v.HeroType, function() CTL.Task.DoTask(task, true) end) end end else CTL.Task.DoTask(task, true) end end function UITownTaskGuide:FitSelectEffectHeight(cellTable) local bgWidth, bgHeight = cellTable.sprite_Bg.rectTransform:GetSizeDelta() cellTable.effect_Select.transform:SetLocalScale(1,bgHeight/ SLECT_EFFECT_NORMALIZED_SIZE,1) cellTable.effect_Select:PlayUIEffect() end function UITownTaskGuide:FitRefreshEffectHeight(cellTable) local bgWidth, bgHeight = cellTable.sprite_Bg.rectTransform:GetSizeDelta() cellTable.effect_Refresh.transform:SetLocalScale(1,bgHeight/ REFRESH_EFFECT_NORMALIZED_SIZE,1) cellTable.effect_Refresh:PlayUIEffect() end function UITownTaskGuide:OnTaskItemClick(task) UTL.ItemTips.ShowCommonTipsById(task.ItemData.ID) end --endregion cell function UITownTaskGuide:RefreshChapterGoal() if not MDL.LevelSelect.IsUnlockChapterGoalAward() then UIUtils.SetActive(self.group_ChapterAim, false) return end -- 检测是否有新章节解锁 MDL.LevelSelect.TriggerNewChapterAwardEft() -- 首次解锁特殊处理 local chapterGoalCache = MDL.LevelSelect.GetChapterGoalCache(1) local isFunctionUnlock = chapterGoalCache and chapterGoalCache.isUnlock and not self.group_ChapterAim.gameObject.activeSelf local chapterGoalId = MDL.LevelSelect.GetCurChapterGoalId() UIUtils.SetActive(self.group_ChapterAim, not isFunctionUnlock and chapterGoalId ~= -1) if chapterGoalId ~= -1 then local data = DataSheetManager.ChapterGoalData:GetDataByChapterGoalID(chapterGoalId) local cache = MDL.LevelSelect.GetChapterGoalCache(chapterGoalId) local completeCount = MDL.LevelSelect.GetCompleteLevelCount(chapterGoalId) local amountCount = cache.amountLevel UIUtils.SetImageByAssetBundle(self.img_HeroHead, data.TownDisplayBossPicture) self.heroImageRect:SetAnchoredPosition(self.heroAnchorPosX + data.TownDisplayBossSmallOffset_X,self.heroAnchorPosY + data.TownDisplayBossSmallOffset_Y) local scaleX = data.TownDisplayBossSmallMirror == 1 and -1 or 1 self.heroImageTrans:SetLocalScale(scaleX, 1, 1) UIUtils.SetLabelText(self.localLab_Title, Const_IDS[data.ChapterGoalName]) local isUnlock = MDL.Unlock.IsComplete(data.Unlock_Table[1].UnlockCondition, data.Unlock_Table[1].UnlockConditionParam) UIUtils.SetActive(self.group_ChapterProgress, isUnlock) self.img_Bg:SetRedPoint(isUnlock and completeCount == amountCount) if not isUnlock then if data.Unlock_Table[1].UnlockCondition == LuaConst.UnlockConditionType.CompleteMainAndSubStory then local paramList = string.split(data.Unlock_Table[1].UnlockConditionParam, ";") local brief = DataSheetManager.TaskFatherData:GetDataByID(tonumber(paramList[1])).Brief self.localLab_LockTip.text = string.FormatByIdsId(Const_IDS["IDS_ChapterGoal_Hint12"], UIUtils.GetLocalizedTxt(Const_IDS[brief])) elseif data.Unlock_Table[1].UnlockCondition == LuaConst.UnlockConditionType.TeamLevel then self.localLab_LockTip.text = string.FormatByIdsId(Const_IDS["IDS_ChapterGoal_Hint11"], data.Unlock_Table[1].UnlockConditionParam) end return end self.localLab_LockTip.text = nil self.slider_ChapterNum.value = completeCount / amountCount self.txt_ChapterNum.text = string.format(progressStr, completeCount, amountCount) end end function UITownTaskGuide:SetChapterGoalParent(target) if target then target:SetParent(self.group_ChapterAim, false) end end function UITownTaskGuide:PlayChapterGoalNewUnlockStart() -- 首次解锁章节奖励 self.group_ChapterAim:SetLocalScale(0, 0, 1) UIUtils.SetActive(self.group_ChapterAim, true) end -- 播放章节奖励解锁特效 function UITownTaskGuide:PlayChapterGoalUnlock(chapterGoalId) -- 播放特效前 关闭UIHomeTown层级以上的全部界面 UIManager.RecoverTopView() CTL.HomeMain.CloseOpenView() UIManager.OpenView(Const_UI_Lua.UIEnum.UIChapterGoalUnlockShow, {chapterGoalId = chapterGoalId}) end function UITownTaskGuide:PlayChapterGoalUnlockEnd(chapterGoalId) self.group_ChapterAim:SetLocalScale(1, 1, 1) UIUtils.SetActive(self.group_ChapterAim, true) UIManager.OpenView(Const_UI_Lua.UIEnum.UIChapterGoal) end return UITownTaskGuide