local UITreasureSoulCrystalProperty = UIViewClass() local TreasurePreciousCrystalAdd = DataSheetManager.ConstData:GetDataByID("TreasurePreciousCrystalAdd").IntListValue -- 排序(id大小排序) local function SortAttr(a, b) return a.AttrType < b.AttrType end -------------------- function UITreasureSoulCrystalProperty:OnOpened(context) self.treasureId = context.treasureId self:InitPanel() end function UITreasureSoulCrystalProperty:OnBackButtonPressed() self:OnButtonClicked(self.btn_Close) end function UITreasureSoulCrystalProperty:OnButtonClicked(comp) if comp == self.btn_Close then self:CloseView() end end function UITreasureSoulCrystalProperty:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.group_RecommendSoulCrystal then local soulCrystalTypeData = DataSheetManager.TreasureSoulCrystalType:GetDataByCrystalType(data.crystalType) if soulCrystalTypeData then UIUtils.SetImageByAssetBundle(cellTable.img_RecommendSoulCrystaliconLight, soulCrystalTypeData.LightIconName) cellTable.img_RecommendSoulCrystaliconLight:SetNativeSize() if data.active then cellTable.effect_SCLight:PlayUIEffect(CTL.Treasure.SoulCrystalEffect[data.crystalType], -1) else cellTable.effect_SCLight:StopUIEffect() end else logging.error(LTAG.ERROR, "宝物赋魂[UITreasureSoulCrystalProperty:OnCellInit] : 没有找到 CrystalType = ", data.crystalType, " 的赋魂系别数据") end elseif scrollRect == self.Loop_SoulCrystalTips then if type(data) == "table" then UTL.Attr.SetAttrItemByCompName(cellTable, data.AttrType, data.AttrNum, true, true) else UIUtils.SetLabelText(cellTable.lab_Title, data) end end end -------------------- function UITreasureSoulCrystalProperty:InitPanel() -- 设置倾好展示 local treasureData = DataSheetManager.TreasureData:GetDataByTreasureID(self.treasureId) local recommendList = {} local recommendActiveCount = 0 for i, v in ipairs(treasureData.CrystalPour) do local active = CTL.Treasure.RecommendIndexIsActive(self.treasureId, i) if active then recommendActiveCount = recommendActiveCount + 1 end table.insert(recommendList, {crystalType = v, active = active}) end self.group_RecommendSoulCrystal:ReloadAll(recommendList) -- 设置倾好加成 local recommendAdd = TreasurePreciousCrystalAdd[recommendActiveCount] recommendAdd = recommendAdd and recommendAdd or 0 UIUtils.SetLabel(self.lab_Addition, string.FormatByIdsId(Const_IDS.IDS_TreasureSoul_QingHaoJiaCheng, recommendAdd)) -- 清空属性列表 if self.Loop_SoulCrystalTips.Count > 0 then self.Loop_SoulCrystalTips:ClearCells() end -- 设置基础属性 local basicAttrList = self:InitBasicAttr() -- 设置洗练属性 local soulSlotAttrList = self:InitSoulSlotAttr() -- 设置倾好加成属性 self:InitRecommendAttr(basicAttrList, recommendAdd) -- 设置战斗力 local allGS = self:CalculateGS(basicAttrList) -- 基础属性战力 allGS = allGS * (1 + recommendAdd / 100) -- 倾好加成战力 allGS = allGS + self:CalculateGS(soulSlotAttrList) -- 洗练属性战力 UIUtils.SetLabel(self.txt_PowerNumber, math.floor(allGS + 0.5)) end function UITreasureSoulCrystalProperty:InitBasicAttr() local equipDic = MDL.Treasure.GetEquipDicByTreasureId(self.treasureId) local attrList = {} for id, _ in pairs(equipDic) do local soulInfo = MDL.Treasure.GetSoulCrystalById(id) for _, attr in ipairs(soulInfo.baseAttrList) do local attrDic for _, attrData in ipairs(attrList) do if attrData.AttrType == attr.AttrType then attrDic = attrData break end end if attrDic then attrDic.AttrNum = attrDic.AttrNum + attr.AttrNum else table.insert(attrList, {AttrType = attr.AttrType, AttrNum = attr.AttrNum}) end end end table.sort(attrList, SortAttr) self.Loop_SoulCrystalTips:AddData(Const_IDS.IDS_TreasureSoul_JiChuShuXing, 0) for _, v in ipairs(attrList) do self.Loop_SoulCrystalTips:AddData(v, 1) end return attrList end function UITreasureSoulCrystalProperty:InitSoulSlotAttr() local attrList = {} local treasureInfo = MDL.Treasure.GetTreasureInfo(self.treasureId) if not treasureInfo then return attrList end for i, v in ipairs(treasureInfo.TreasureInfo.soulSlotInfos) do if not string.isNilOrEmpty(v.soulCrystalId) then for _, attr in ipairs(v.slotAttrs) do if attr.state == MDL.Treasure.SoulSlotAttrState.Effective then local attrDic for _, attrData in ipairs(attrList) do if attrData.AttrType == attr.attrType then attrDic = attrData break end end if attrDic then attrDic.AttrNum = attrDic.AttrNum + attr.attrValue else table.insert(attrList, {AttrType = attr.attrType, AttrNum = attr.attrValue}) end end end end end if #attrList > 0 then table.sort(attrList, SortAttr) self.Loop_SoulCrystalTips:AddData(Const_IDS.IDS_TreasureSoul_XiLianShuXing, 0) for _, v in ipairs(attrList) do self.Loop_SoulCrystalTips:AddData(v, 1) end end return attrList end function UITreasureSoulCrystalProperty:InitRecommendAttr(basicAttrList, recommendAdd) local recommendAttrList = {} if recommendAdd > 0 then local hasAttrNum = false for _, v in ipairs(basicAttrList) do local attr = {AttrType = v.AttrType, AttrNum = math.floor(v.AttrNum * recommendAdd / 100 + 0.5)} table.insert(recommendAttrList, attr) if attr.AttrNum > 0 then hasAttrNum = true end end if hasAttrNum then self.Loop_SoulCrystalTips:AddData(Const_IDS.IDS_TreasureSoul_GongMingShuXing, 0) for _, v in ipairs(recommendAttrList) do -- 属性值为0的不展示 if v.AttrNum > 0 then self.Loop_SoulCrystalTips:AddData(v, 1) end end end end end function UITreasureSoulCrystalProperty:CalculateGS(attrList) local allGS = 0 for i, v in ipairs(attrList) do allGS = allGS + UTL.Attr.CalculateSingleFight(v.AttrType, v.AttrNum) end return allGS end return UITreasureSoulCrystalProperty