local Attr_Utility = {} Attr_Utility.SpecialAttr = { Speed = "zq_icon_sudu", } local FightIcon = "zq_icon_zhanli" --战力icon --战力:attrType传0 --图片:img_Attr --文本:lab_Attr --数字:txt_Attr --withPlus 是否带+号 --数字(上一级): txt_Attr_Before function Attr_Utility.SetAttrItemByCompName(attrComp, attrType, attrNum, showIcon, withPlus, oldAttrNum) local withPlus = withPlus or false local isFight = attrType == 0 if isFight then if showIcon then UTL.Item.SetAtlasSprite(attrComp.img_Attr, "UI_Common", FightIcon) end UIUtils.SetLabelText(attrComp.lab_Attr, Const_IDS["IDS_Team_TotalCapacity"]) attrComp.txt_Attr.text = withPlus and "+" .. attrNum or attrNum if attrComp.txt_Attr_Before then attrComp.txt_Attr_Before.text = oldAttrNum end else local attrData = DataSheetManager.AttrData:GetDataByID(attrType) local attrName = attrData.Name if showIcon then local attrIcon = attrData.Icon Attr_Utility.SetAttrIconByAttrIcon(attrComp.img_Attr, attrIcon) end UIUtils.SetLabelText(attrComp.lab_Attr, Const_IDS[attrName]) local attrValue = attrData.IsPercentShow and Attr_Utility.FormatNumberToPercentage(attrNum, 0) or attrNum attrComp.txt_Attr.text = withPlus and "+" .. attrValue or attrValue if attrComp.txt_Attr_Before then attrComp.txt_Attr_Before.text = attrData.IsPercentShow and Attr_Utility.FormatNumberToPercentage(oldAttrNum, 0) or oldAttrNum end end end --战力:attrType传0 --带图片:attrComp{[1] = icon,[2] = nameLabel,[3] = numLabel --不带图片:attrComp[1] = nameLabel, attrComp[2] = numLabel function Attr_Utility.SetAttrItem(attrComp, attrType, attrNum, showIcon) local isFight = attrType == 0 if isFight then if showIcon then UTL.Item.SetAtlasSprite(attrComp[1], "UI_Common", FightIcon) UIUtils.SetLabelText(attrComp[2],Const_IDS["IDS_Team_TotalCapacity"]) attrComp[3].text = attrNum else UIUtils.SetLabelText(attrComp[1],Const_IDS["IDS_Team_TotalCapacity"]) attrComp[2].text = attrNum end else local attrData = DataSheetManager.AttrData:GetDataByID(attrType) local attrName = attrData.Name local attrValue = attrData.IsPercentShow and Attr_Utility.FormatNumberToPercentage(attrNum, 0) or attrNum if showIcon then local attrIcon = attrData.Icon Attr_Utility.SetAttrIconByAttrIcon(attrComp[1], attrIcon) UIUtils.SetLabelText(attrComp[2],Const_IDS[attrName]) attrComp[3].text = attrValue else UIUtils.SetLabelText(attrComp[1],Const_IDS[attrName]) attrComp[2].text = attrValue end end end --attrComp{[1] = icon,[2] = nameLabel,[3] = numLabel} function Attr_Utility.SetSpecialAttrItem(attrComp,iconPath,attrName,attrNum) UTL.Item.SetAtlasSprite(attrComp[1], "UI_Common", iconPath) UIUtils.SetLabelText(attrComp[2],Const_IDS[attrName]) attrComp[3].text = attrNum end function Attr_Utility.SetAttrIcon(icon, attrType) local attrIcon = DataSheetManager.AttrData:GetDataByID(attrType).Icon Attr_Utility.SetAttrIconByAttrIcon(icon, attrIcon) end function Attr_Utility.SetAttrIconByAttrIcon(icon, attrIcon) if attrIcon then UTL.Item.SetAtlasSprite(icon, "UI_Common", attrIcon) else--没有属性对应资源用战力图标 UTL.Item.SetAtlasSprite(icon, "UI_Common", FightIcon) end end --显示为:图标 属性+xxx function Attr_Utility.SetAttrItemOneLabel(icon, label, attrType, attrNum) local attrData = DataSheetManager.AttrData:GetDataByID(attrType) local attrIcon = attrData.Icon Attr_Utility.SetAttrIconByAttrIcon(icon, attrIcon) label.text = "+" .. (attrData.IsPercentShow and Attr_Utility.FormatNumberToPercentage(attrNum, 0) or attrNum) end --{attr[AttrType,AttrNum]} function Attr_Utility.CalculateFight(attrList) local fight = 0 for i = 1, #attrList do fight = fight + Attr_Utility.CalculateSingleFight(attrList[i].AttrType, attrList[i].AttrNum) end return math.floor(fight + 0.5) end function Attr_Utility.CalculateSingleFight(attrType, attrNum, round) local attrData = DataSheetManager.AttrData:GetDataByID(attrType) local fight = attrNum * attrData.GSParam if round then return math.floor(fight + 0.5) else return fight end end local PercentRatio = 100 local PercentageFormatStringZero = "%.0f%%" local PercentageFormatStringOne = "%.1f%%" local PercentageFormatStringTwo = "%.2f%%" function Attr_Utility.FormatNumberToPercentage(number, n) local formatStr if n == 0 then formatStr = PercentageFormatStringZero elseif n == 1 then formatStr = PercentageFormatStringOne elseif n == 2 then formatStr = PercentageFormatStringTwo else formatStr = "%."..tostring(n).."f%%" end return string.format(formatStr, (number * PercentRatio)) end function Attr_Utility.ProcessProtoAttrTable(attrTable) --proto数组从0开始,服务器在处理attr数据的时候,将数组下标直接映射属性ID进行赋值,index为0的位置即为空 --在proto发过来转成luaTable(从1开始的数组)的时候,proto中的0位置变成了luaTable的1位置,是一个无效值 --所以需要在收到的时候将其删掉,方便客户端统一规则使用,不用二次处理 table.remove(attrTable, 1) end function Attr_Utility.GetAttrText(type, num, numColor, reserveNum) if reserveNum == nil then reserveNum = 0 end if not numColor then numColor = UTL.Color.ModelNameColor.White end local attrData = DataSheetManager.AttrData:GetDataByID(type) local name = UIUtils.GetLocalizedTxt(Const_IDS[attrData.Name]) return string.format("%s+%s", name, numColor, attrData.IsPercentShow and Attr_Utility.FormatNumberToPercentage(num, reserveNum) or num) end -- 武将突破指定目标等级可提升天赋等级 -- return 指定等级 function Attr_Utility.GetHeroBreakTargetLevelByTalentId(heroId, talentId) for _, v in DataSheetManager.HeroStar:GetDataByHeroID_Star(heroId) do if v.RemoveDevelopEffectID == talentId then return v.Star end end logging.log(LTAG,LOG, "没有找到对应突破等级 : ", talentId) end -- 武将和神兵突破指定目标等级可提升技能等级 -- return 指定等级 function Attr_Utility.GetHeroBreakTargetLevelBySkillId(heroId, skillId) local heroInfo = MDL.HeroSelect.GetHeroInfo(heroId) local weaponData = DataSheetManager.MagicWeaponStar:GetDataByMagicWeaponID_Star(heroId, heroInfo and heroInfo.magicWeaponLevel or 0) local musouLevel = weaponData.MusouLevel for _, v in DataSheetManager.MagicWeaponStar:GetEnumerator() do if v.MusouLevel > musouLevel then return v.Star end end logging.log(LTAG,LOG, "没有找到对应突破等级 : ", heroId, " ",skillId) end -- 宝物突破指定目标等级可提升的宝物技能等级 -- return 指定等级 function Attr_Utility.GetTreasureBreakTargetLevelById(treasureId, treasureSkillId) for _, v in DataSheetManager.TreasureStar:GetEnumerator() do if treasureId == v.TreasureID and v.TreasureSkill > treasureSkillId then return v.Star + 1 end end logging.log(LTAG,LOG, "没有找到对应宝物技能ID突破等级 : ", treasureSkillId) end function Attr_Utility.GetAttrStrById(id, attrValue) local attrData = DataSheetManager.AttrData:GetDataByID(id) if attrData.Type then return attrValue else local value = math.ceil(attrValue*1000) if value == 0 then return value elseif value % 10 == 0 then return string.format("%.0f%%",value/10) else return string.format("%.1f%%",value/10) end end end function Attr_Utility.SetWarHorseScrollingAttr(attrComp, attrType, attrNum, showIcon, withPlus, oldAttrNum) local withPlus = withPlus or false local isFight = attrType == 0 local content if isFight then if showIcon then UTL.Item.SetAtlasSprite(attrComp.img_Attr, "UI_Common", FightIcon) end content = UIUtils.GetLocalizedTxt(Const_IDS["IDS_Team_TotalCapacity"]) .. UTL.Color.FormatTextByColor(ATTR_TXT_COLOR, withPlus and "+" .. attrNum or attrNum) if attrComp.txt_Attr_Before then content = content .. UTL.Color.FormatTextByColor(ATTR_TXT_COLOR, oldAttrNum) end else local attrData = DataSheetManager.AttrData:GetDataByID(attrType) local attrName = attrData.Name if showIcon then local attrIcon = attrData.Icon UTL.Attr.SetAttrIconByAttrIcon(attrComp.img_Attr, attrIcon) end local attrValue = attrData.IsPercentShow and UTL.Attr.FormatNumberToPercentage(attrNum, 0) or attrNum content = UIUtils.GetLocalizedTxt(Const_IDS[attrName]) .. UTL.Color.FormatTextByColor(ATTR_TXT_COLOR, withPlus and "+" .. attrValue or attrValue) if attrComp.txt_Attr_Before then content = content .. UTL.Color.FormatTextByColor(ATTR_TXT_COLOR, attrData.IsPercentShow and UTL.Attr.FormatNumberToPercentage(oldAttrNum, 0) or oldAttrNum) end end attrComp.scrolling_Lab:SetText(content) end --合并属性 function Attr_Utility.CombineAttr(oriAttrList, addAttrList) for i = 1, #addAttrList do local flag = false --同属性相加 for j = 1, #oriAttrList do if addAttrList[i].AttrType == oriAttrList[j].AttrType then oriAttrList[j].AttrNum = oriAttrList[j].AttrNum + addAttrList[i].AttrNum flag = true break end end --不同属性插入 if flag == false then --这里的attrTable防止外部修改,修改到源数据,新建个table local attr = { AttrType = addAttrList[i].AttrType, AttrNum = addAttrList[i].AttrNum } table.insert(oriAttrList, attr) end end end return Attr_Utility