local UIChapterGoal = UIViewClass() local progressStr = "%s/%s" local EventSystem = require('Event/EventSystem') ------------------------------ 系统函数 -------------------------------- function UIChapterGoal:OnCreated() self.heroImageTrans = self.img_ChapterHeroLihui.transform self.heroImageRect = self.img_ChapterHeroLihui.rectTransform self.heroAnchorPosX, self.heroAnchorPosY = self.heroImageRect:GetAnchoredPosition() self.scroll_Reward.enabled = false if self.loc_Title.CurState == 0 then UIUtils.SetLocalizationImage(self.img_Title, "zjjl_msz_jiangliyulan.png") end end function UIChapterGoal:OnOpened(context) self:RegistSystemEvent(EventID.UI_Chapter_ClaimAward, self.UpdatePanel) self:RegistSystemEvent(EventID.UI_ChapterGoal_RewardPanelClose, self.PlayUnlockEft) self.showIndex = MDL.LevelSelect.GetChapterAwardShowIndex() and MDL.LevelSelect.GetChapterAwardShowIndex() or MDL.LevelSelect.GetChapterGoalShowIndex(MDL.LevelSelect.GetCurChapterGoalId()) self:RefreshPanel() end function UIChapterGoal:OnClosed() -- 缓存参数重置 MDL.LevelSelect.SetChapterAwardShowIndex(nil) MDL.LevelSelect.SetCurrentRewardChapterID(nil) EventSystem.Dispatch(EventID.UI_ChapterGoal_RefreshChapterAward) end function UIChapterGoal:OnBackButtonPressed() self:OnButtonClicked(self.event_Close) end function UIChapterGoal:OnButtonClicked(cmp) if cmp == self.event_Close then -- TODO播放动画 -- self:PlayUIAnimation(CloseViewAnimPath, self.UICommonPopView.group_window.transform, true) self:CloseView() elseif cmp == self.event_Receive then local chapterCache = MDL.LevelSelect.GetChapterGoalCacheByIndex(self.showIndex) if not chapterCache then return end local completeCount = MDL.LevelSelect.GetCompleteLevelCount(chapterCache.chapterGoalId) local amountCount = chapterCache.amountLevel if completeCount == amountCount then MDL.LevelSelect.ClaimChapterAwardRequest(chapterCache.chapterGoalId) else self:CloseView() for _, v in pairs (MDL.Task.GetTaskList(MDL.Task.Enum_TaskType.Major)) do CTL.Task.DoTask(v) break end end elseif cmp == self.ico_Info then local chapterCache = MDL.LevelSelect.GetChapterGoalCacheByIndex(self.showIndex) if not chapterCache then return end local data = DataSheetManager.ChapterGoalData:GetDataByChapterGoalID(chapterCache.chapterGoalId) if data and data.IsDisplayDetails then local context = {showHeroID = data.DisplayHeroID} UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIHeroSelectShowPanel, context) end elseif cmp == self.btn_Before then self.showIndex = self.showIndex - 1 self:RefreshPanel() elseif cmp == self.btn_Next then self.showIndex = self.showIndex + 1 self:RefreshPanel() end end function UIChapterGoal:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.scroll_Reward then UTL.Item.SetItemCell(cellTable.item, data.ItemID, data.ItemNum) UIUtils.SetActive(cellTable.item.obj_Stamp, false) end end function UIChapterGoal:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.scroll_Reward then UTL.ItemTips.ShowCommonTipsById(data.ItemID) end end function UIChapterGoal:OnUIAnimationStoped(playingID) self:CloseView() end ------------------------------------------------------------------------ function UIChapterGoal:RefreshPanel() if self.showIndex == 0 then self.showIndex = 1 return elseif self.showIndex > MDL.LevelSelect.GetChapterGoalLength() then self.showIndex = MDL.LevelSelect.GetChapterGoalLength() return end MDL.LevelSelect.SetChapterAwardShowIndex(self.showIndex) local chapterCache = MDL.LevelSelect.GetChapterGoalCacheByIndex(self.showIndex) if not chapterCache then return end local data = DataSheetManager.ChapterGoalData:GetDataByChapterGoalID(chapterCache.chapterGoalId) if not data then return end UIUtils.SetActive(self.btn_Before, self.showIndex > 1) UIUtils.SetActive(self.btn_Next, self.showIndex < MDL.LevelSelect.GetChapterGoalLength()) UIUtils.SetActive(self.group_Info, data.IsDisplayDetails == 1) self:RefreshJumpBtnRp(self.btn_Before, self.showIndex - 1) self:RefreshJumpBtnRp(self.btn_Next, self.showIndex + 1) UIUtils.SetLabelText(self.txt_AimTask, Const_IDS[data.ChapterGoalDes1]) -- UIUtils.SetLabelText(self.txt_StrongHero, Const_IDS[data.ChapterGoalDes2]) UIUtils.SetLabelText(self.txt_HeroName, Const_IDS[data.ChapterGoalDes3]) UIUtils.SetSpritePivotPos(self.img_ChapterHeroLihui, data.DisplayHeroPicture, 1) self.heroImageRect:SetAnchoredPosition(self.heroAnchorPosX + data.DisplayHeroOffset_X, self.heroAnchorPosY + data.DisplayHeroOffset_Y) local scaleX = data.DisplayHeroSmallMirror == 1 and -1 or 1 self.heroImageTrans:SetLocalScale(scaleX, 1, 1) self.scroll_Reward:ClearCells() local itemData = DataSheetManager.ChapterGoalReward:GetDataByID(data.ChapterGoalReward) local itemTable = itemData.Item_Table if itemTable and #itemTable > 0 then for _, v in ipairs (itemTable) do self.scroll_Reward:AddData(v, 0) end end local completeCount = MDL.LevelSelect.GetCompleteLevelCount(chapterCache.chapterGoalId) local amountCount = chapterCache.amountLevel self.slider_XP.value = completeCount / amountCount self.txt_ChapterNum.text = string.format(progressStr, completeCount, amountCount) local isUnlock = MDL.Unlock.IsComplete(data.Unlock_Table[1].UnlockCondition, data.Unlock_Table[1].UnlockConditionParam) self.event_Receive.enabled = isUnlock self.event_Receive:SetGray(not isUnlock) self.event_Receive:SetRedPoint(isUnlock and completeCount == amountCount) if not isUnlock then UIUtils.SetLabelText(self.Text_Local, Const_IDS["IDS_Unlock"]) 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.txt_StoryDes.text = string.FormatByIdsId(Const_IDS["IDS_ChapterGoal_Hint13"], UIUtils.GetLocalizedTxt(Const_IDS[brief])) elseif data.Unlock_Table[1].UnlockCondition == LuaConst.UnlockConditionType.TeamLevel then self.txt_StoryDes.text = string.FormatByIdsId(Const_IDS["IDS_ChapterGoal_Hint9"], data.Unlock_Table[1].UnlockConditionParam) end else if completeCount < amountCount then UIUtils.SetLabelText(self.Text_Local, Const_IDS["IDS_ChapterGoal_Hint15"]) else UIUtils.SetLabelText(self.Text_Local, Const_IDS["IDS_AwardReceive"]) end UIUtils.SetLabelText(self.txt_StoryDes, Const_IDS[data.ChapterDes]) end end function UIChapterGoal:UpdatePanel() if not MDL.LevelSelect.GetChapterAwardShowIndex() then -- TODO播放动画 -- self:PlayUIAnimation(CloseViewAnimPath, self.UICommonPopView.group_window.transform, true) EventSystem.Dispatch(EventID.UI_ChapterGoal_RefreshChapterAward) self:CloseView() else self.showIndex = MDL.LevelSelect.GetChapterAwardShowIndex() -- 播放章节领取特效 self:RefreshPanel() end end function UIChapterGoal:PlayUnlockEft(rewardDataDict) if not rewardDataDict then return end -- 判断是否为章节奖励 if not MDL.LevelSelect.GetCurrentRewardChapterID() then return end local rewardData = DataSheetManager.ChapterGoalData:GetDataByChapterGoalID(MDL.LevelSelect.GetCurrentRewardChapterID()) local itemData = DataSheetManager.ChapterGoalReward:GetDataByID(rewardData.ChapterGoalReward) local itemTable = itemData.Item_Table for _, v in ipairs (itemTable) do if not rewardDataDict[v.ItemID] or rewardDataDict[v.ItemID] ~= v.ItemNum then return end end local chapterCache = MDL.LevelSelect.GetChapterGoalCacheByIndex(MDL.LevelSelect.GetChapterAwardShowIndex()) if chapterCache then -- 下一个显示的章节奖励是否解锁 local data = DataSheetManager.ChapterGoalData:GetDataByChapterGoalID(chapterCache.chapterGoalId) if MDL.Unlock.IsComplete(data.Unlock_Table[1].UnlockCondition, data.Unlock_Table[1].UnlockConditionParam) then chapterCache.isUnlock = true UIManager.RecoverTopView() CTL.HomeMain.CloseOpenView() UIManager.OpenView(Const_UI_Lua.UIEnum.UIChapterGoalUnlockShow, {chapterGoalId = chapterCache.chapterGoalId}) end end EventSystem.Dispatch(EventID.UI_ChapterGoal_RefreshChapterAward) end function UIChapterGoal:RefreshJumpBtnRp(btn, index) if index < 1 or index > MDL.LevelSelect.GetChapterGoalLength() then btn:SetRedPoint(false) return end local chapterCache = MDL.LevelSelect.GetChapterGoalCacheByIndex(index) if not chapterCache then btn:SetRedPoint(false) return end local data = DataSheetManager.ChapterGoalData:GetDataByChapterGoalID(chapterCache.chapterGoalId) local completeCount = MDL.LevelSelect.GetCompleteLevelCount(chapterCache.chapterGoalId) local amountCount = chapterCache.amountLevel local isUnlock = MDL.Unlock.IsComplete(data.Unlock_Table[1].UnlockCondition, data.Unlock_Table[1].UnlockConditionParam) btn:SetRedPoint(isUnlock and completeCount == amountCount) end return UIChapterGoal