local UIAchievementInfo = UIViewClass() local EventSystem = require('Event/EventSystem') local achievement = require 'Proto.achievement_pb' local FilterSortType = { All = 1, Done = 2, NotDone = 3 } local ScoreStr = "%d/%d" ------------------------------- 系统函数 ---------------------------- function UIAchievementInfo:OnOpened(context) self:RegistSystemEvent(EventID.UI_AchievementInfo_Refresh, self.RefreshPanel) self:RegistSystemEvent(EventID.UI_AchievementInfo_UpdateItems, self.RefreshAchievementItems) self.showItemList = {} self:RefreshPanel(context) end function UIAchievementInfo:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_Info then local achievementItem = self.showItemList[data] local itemName, itemDes = CTL.Achievement.GetAchievementTitleAndDesc(achievementItem) UIUtils.SetLabel(cellTable.txt_Name, itemName) UIUtils.SetLabel(cellTable.txt_Detail, itemDes) UIUtils.SetLabel(cellTable.txt_Score, achievementItem.configData.ChildScore) for i, rewardData in ipairs(achievementItem.itemTable) do local contentItem = cellTable.Content[i] if not contentItem then contentItem = self:InstantiateCellCollection(cellTable.cell.gameObject, cellTable.Content, self.itemTemplate_Reward.gameObject) end UTL.Item.SetItemCell(contentItem, rewardData.ItemID, rewardData.ItemNum) UIUtils.SetActive(contentItem.gameObject, true) end for i = #achievementItem.itemTable + 1, #cellTable.Content do UIUtils.SetActive(cellTable.Content[i].gameObject, false) end UIUtils.SetActive(cellTable.group_Get.gameObject, achievementItem.state == achievement.Achieve) UIUtils.SetActive(cellTable.group_Reached.gameObject, achievementItem.state == achievement.Done) UIUtils.SetActive(cellTable.group_NotReached.gameObject, achievementItem.state == achievement.Doing) if achievementItem.state == achievement.Achieve then UIUtils.SetLabel(cellTable.group_Get.txt_Time, os.date(UTL.Time.FormatDateEnum.YMDHM, achievementItem.achieveTime)) elseif achievementItem.state == achievement.Done then UIUtils.SetLabel(cellTable.group_Reached.txt_Time, os.date(UTL.Time.FormatDateEnum.YMDHM, achievementItem.achieveTime)) elseif achievementItem.state == achievement.Doing then local showStr, progress = CTL.Achievement.GetAchievementProgress(achievementItem) cellTable.group_NotReached.slider_Score.value = progress UIUtils.SetLabel(cellTable.group_NotReached.txt_Time, showStr) end end end function UIAchievementInfo:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loop_Info then local item = self.showItemList[data] if target == cellTable.group_Get.Button then MDL.Achievement.RequestClaimAchievementReward(item.configData.ID) elseif target == cellTable.group_Reached.btn_Share or target == cellTable.group_Get.btn_Share then -- 分享 UIManager.OpenView(Const_UI_Lua.UIEnum.UIAchievementShare, item) else for i, v in ipairs (cellTable.Content) do if target == v.event_Click then UTL.ItemTips.ShowCommonTipsById(item.itemTable[i].ItemID) return end end -- if MDL.Achievement.IsSpecialChildType(self.curChildType) then -- -- 跳转到具体分类显示 -- local jumpIndex = MDL.Achievement.FindIndexInSortedAchievements(item) -- EventSystem.Dispatch(EventID.UI_AchievementBase_Refresh, item.configData.MainType, item.configData.ChildType, jumpIndex) -- end end end end function UIAchievementInfo:OnButtonClicked(comp) if comp == self.group_Level.btn_Choose then local isShow = not self.group_Choose.gameObject.activeSelf UIUtils.SetActive(self.group_Choose.gameObject, isShow) UIUtils.SetActive(self.group_Level.img_ArrowDOWN, not isShow) UIUtils.SetActive(self.group_Level.img_ArrowUP, isShow) elseif comp == self.group_Choose.btn_All then self:RefreshGroupChoose(FilterSortType.All) elseif comp == self.group_Choose.btn_Done then self:RefreshGroupChoose(FilterSortType.Done) elseif comp == self.group_Choose.btn_NotDone then self:RefreshGroupChoose(FilterSortType.NotDone) elseif comp == self.get_All_Button then MDL.Achievement.ReqAllAchievementReward() end end ---------------------------------------------------------------------- function UIAchievementInfo:RefreshPanel(infoParams) -- 重置数据显示 if not infoParams then return end self.curMainType = infoParams.mainType self.curChildType = infoParams.childType self.filterSortType = FilterSortType.All UIUtils.SetActive(self.get_All_Button, self.curMainType == 1 and MDL.Achievement.IsShowChildTypeRedPoint(self.curMainType, self.curChildType)) if MDL.Achievement.IsSpecialChildType(self.curChildType) then self:RefreshSpecialChildType() else self:RefreshGroupLevel() self:RefreshGroupChoose(self.filterSortType) end if infoParams.jumpIndex then self.loop_Info:MoveIndex(infoParams.jumpIndex - 1) end end function UIAchievementInfo:RefreshSpecialChildType() UIUtils.SetActive(self.group_Level.gameObject, false) self.loop_Info:ClearCells() self.showItemList = {} for _, v in ipairs (MDL.Achievement.GetAchievementItems(self.curMainType, self.curChildType)) do table.insert(self.showItemList, v) self.loop_Info:AddData(#self.showItemList, 0) end UIUtils.SetLabelText(self.lab_Empty, self.curChildType == 3 and Const_IDS["IDS_Achievement_NoAlreadyReached"] or Const_IDS["IDS_Achievement_NoNotReached"]) UIUtils.SetActive(self.group_EmptySpecialType, #self.showItemList == 0) UIUtils.SetActive(self.group_Empty, false) end function UIAchievementInfo:RefreshGroupLevel() local group_Level = self.group_Level UIUtils.SetActive(group_Level.gameObject, true) local cfg = DataSheetManager.AchievementType:GetDataByMainType_ChildType(self.curMainType, self.curChildType) local childAchievement = MDL.Achievement.GetChildAchievement(self.curMainType, self.curChildType) if childAchievement then UIUtils.SetImageByAssetBundle(group_Level.img_Icon, cfg.Icon) UIUtils.SetLabelText(group_Level.txt_Now, Const_IDS[cfg.TypeName]) local curScore, amountScore = childAchievement.curScore, childAchievement.amountScore UIUtils.SetLabel(group_Level.txt_Score, string.format(ScoreStr, curScore, amountScore)) group_Level.slider_Score.value = curScore / amountScore end end function UIAchievementInfo:RefreshGroupChoose(filterSortType) self.filterSortType = filterSortType UIUtils.SetActive(self.group_Choose.img_Selected_All, self.filterSortType == FilterSortType.All) UIUtils.SetActive(self.group_Choose.img_Selected_Done, self.filterSortType == FilterSortType.Done) UIUtils.SetActive(self.group_Choose.img_Selected_NotDone, self.filterSortType == FilterSortType.NotDone) self.group_Choose.TextChangeState_All:SetState(self.filterSortType == FilterSortType.All and 1 or 0) self.group_Choose.TextChangeState_Done:SetState(self.filterSortType == FilterSortType.Done and 1 or 0) self.group_Choose.TextChangeState_NotDone:SetState(self.filterSortType == FilterSortType.NotDone and 1 or 0) if self.filterSortType == FilterSortType.All then UIUtils.SetLabelText(self.group_Level.txt_Choose, Const_IDS["IDS_TeamUI_ActiveInvitation_ALL"]) elseif self.filterSortType == FilterSortType.Done then UIUtils.SetLabelText(self.group_Level.txt_Choose, Const_IDS["IDS_Achievement_AlreadyReached"]) elseif self.filterSortType == FilterSortType.NotDone then UIUtils.SetLabelText(self.group_Level.txt_Choose, Const_IDS["IDS_Achievement_NotReached"]) end UIUtils.SetActive(self.group_Level.img_ArrowDOWN, true) UIUtils.SetActive(self.group_Level.img_ArrowUP, false) UIUtils.SetActive(self.group_Choose.gameObject, false) self.loop_Info:ClearCells() self.showItemList = {} local itemList = MDL.Achievement.GetAchievementItems(self.curMainType, self.curChildType) if itemList and #itemList > 0 then for _, v in ipairs (MDL.Achievement.GetAchievementItems(self.curMainType, self.curChildType)) do if self:CheckAchievementItemByFilter(v) then table.insert(self.showItemList, v) self.loop_Info:AddData(#self.showItemList, 0) end end end UIUtils.SetActive(self.group_EmptySpecialType, false) UIUtils.SetActive(self.group_Empty, #self.showItemList == 0) end function UIAchievementInfo:RefreshAchievementItems() if self.loop_Info.Count > 0 then -- 重置滑动项数据列表 self.showItemList = {} for _, v in ipairs (MDL.Achievement.GetAchievementItems(self.curMainType, self.curChildType)) do if self:CheckAchievementItemByFilter(v) then table.insert(self.showItemList, v) end end if #self.showItemList == 0 then self.loop_Info:ClearCells() return end -- 删除多余项 while (self.loop_Info.Count > #self.showItemList) do self.loop_Info:RemoveIndex(self.loop_Info.Count - 1) end -- 重置显示列表 self.loop_Info:RefreshCells(false) -- 添加新增项 if self.loop_Info.Count < #self.showItemList then for i = self.loop_Info.Count + 1, #self.showItemList do self.loop_Info:AddData(i, 0) end end end UIUtils.SetActive(self.get_All_Button, self.curMainType == 1 and MDL.Achievement.IsShowChildTypeRedPoint(self.curMainType, self.curChildType)) end function UIAchievementInfo:CheckAchievementItemByFilter(item) if not item then return false end if MDL.Achievement.IsSpecialChildType(self.curChildType) then return true end local isComplete = item.state == achievement.Achieve or item.state == achievement.Done return self.filterSortType == FilterSortType.All or (self.filterSortType == FilterSortType.Done and isComplete) or (self.filterSortType == FilterSortType.NotDone and not isComplete) end return UIAchievementInfo