local UIHonorSignetMain = UIViewClass() function UIHonorSignetMain:OnOpened(context) self:RegistSystemEvent(EventID.UI_HonorSignet_InfoRefresh, self.RefreshHonorSignet) self:RegistSystemEvent(EventID.UI_HonorSignet_ActiveSuccess, self.PlayActiveSuccessEffect) if not self.context then self.context = {} end self.context.selectId = context and context.selectId self:RefreshHonorSignet() end function UIHonorSignetMain:OnBackButtonPressed() self:OnButtonClicked(self.btn_Close) end function UIHonorSignetMain:OnButtonClicked(comp) if comp == self.btn_Close then self.context = nil self:CloseView() elseif comp == self.btn_TotalAttr then UIManager.OpenView(Const_UI_Lua.UIEnum.UIHonorSignetAttrTips, {comp = self.btn_TotalAttr.transform, isSelf = true}) elseif comp == self.btn_Equip then MDL.HonorSignet.HonorSignetReq(MDL.HonorSignet.OpType.Wear, self.context.selectId) elseif comp == self.btn_Active then MDL.HonorSignet.HonorSignetReq(MDL.HonorSignet.OpType.Active, self.context.selectId) elseif comp == self.btn_Disboard then MDL.HonorSignet.HonorSignetReq(MDL.HonorSignet.OpType.Disboard, self.context.selectId) end end function UIHonorSignetMain:PlayActiveSuccessEffect(id) for i, v in ipairs(self.list) do if v.ID == id then self.activeSignetId = id self.loop_HonorSignet:UpdateIndex(i - 1) self.loop_HonorSignet:SelectIndex(i - 1) return end end end function UIHonorSignetMain:RefreshHonorSignet() if self.loop_HonorSignet.Count > 0 then self.loop_HonorSignet:ClearCells() end self.list = MDL.HonorSignet.GetSortedHonorSignetList() for i, v in ipairs(self.list) do if self.context.selectId == v.ID then self.selectIndex = i - 1 end self.loop_HonorSignet:AddData(v, 0) end self.loop_HonorSignet:SelectIndex(self.selectIndex or 0, true) end function UIHonorSignetMain:RefreshSignetInfo(data) UIUtils.SetImageByAssetBundle(self.img_Icon, data.HonorSignetIcon) local quality = data.HonorSignetQuality self.txt_Name.text = UTL.Color.FormatQualityText(UIUtils.GetLocalizedTxt(Const_IDS[data.HonorSignetTitle]), quality) self.loop_Attr:ReloadAll(data.Attr_Table) self.loop_Prerequisites:ReloadAll(data.PreAchievement_Table) local id = data.ID if CTL.HonorSignet.IsActive(id) then self.txt_ActiveTime.text = os.date(UTL.Time.FormatDateEnum.YMDHM, MDL.HonorSignet.GetActiveInfo(id)) if CTL.HonorSignet.IsEquip(id) then self.state_Btn:SetState(1) else self.state_Btn:SetState(0) end else self.txt_ActiveTime.text = "" if CTL.HonorSignet.IsCanUnlock(id) then self.btn_Active:SetRedPoint(true) self.state_Btn:SetState(3) else self.state_Btn:SetState(2) local progressNum = 0 for i, v in ipairs(data.PreAchievement_Table) do if CTL.Achievement.IsAchievementCompleted(v.PreAchievementID) then progressNum = progressNum + 1 end end self.txt_ActiveHint.text = UIUtils.GetLocalizedTxt(Const_IDS.IDS_HonorSignet_Hint_4) .. string.format("(%s/%s)", progressNum, #data.PreAchievement_Table) end end end function UIHonorSignetMain:OnCellSelect(scrollRect, index, cellTable, data) if scrollRect == self.loop_HonorSignet then self.context.selectId = data.ID self:RefreshSignetInfo(data) end end function UIHonorSignetMain:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_Attr then UTL.Attr.SetAttrItemByCompName(cellTable, data.AttrType, data.AttrNum, true, true) elseif scrollRect == self.loop_Prerequisites then local id = data.PreAchievementID local achievementData = MDL.Achievement.GetAchievementItemByID(id) local itemName, itemDes = CTL.Achievement.GetAchievementTitleAndDesc(achievementData) cellTable.txt_AchievementName.text = itemName cellTable.state_Achieved:SetState(CTL.Achievement.IsAchievementCompleted(id) and 1 or 0) elseif scrollRect == self.loop_HonorSignet then local iconPath = data.HonorSignetIcon UIUtils.SetImageByAssetBundle(cellTable.img_Icon, iconPath) UIUtils.SetImageByAssetBundle(cellTable.img_IconMask, iconPath) local id = data.ID UIUtils.SetActive(cellTable.img_Equip, CTL.HonorSignet.IsEquip(id)) if CTL.HonorSignet.IsCanUnlock(id) then if not CTL.HonorSignet.IsActive(id) then cellTable.effect_Unlockable:PlayUIEffect() cellTable.cell:SetRedPoint(true) else cellTable.effect_Unlockable:StopUIEffect() cellTable.cell:SetRedPoint(false) end cellTable.state_Lock:SetState(0) else cellTable.cell:SetRedPoint(false) cellTable.effect_Unlockable:StopUIEffect() cellTable.state_Lock:SetState(1) end if self.activeSignetId and self.activeSignetId == id then cellTable.effect_ActiveSuccess:PlayUIEffect() self.activeSignetId = nil else cellTable.effect_ActiveSuccess:StopUIEffect() end end end function UIHonorSignetMain:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loop_Prerequisites then if target == cellTable.btn_Achievement and not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Achievement) then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Formation_RelationShip_Closed"]) CTL.Sound.PlayGameSound("UI_invalid") elseif target == cellTable.btn_Achievement then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIAchievementBase, {achievementId = data.PreAchievementID}) end end end return UIHonorSignetMain