local Item_Utility = {} local private = {} local ItemIconPath = ConstAssetPathConfig.ItemIconPath local HeroIconPath = ConstAssetPathConfig.HeadImgPath local NobilityIconPath = "%s.png" local FrameIconPath = ConstAssetPathConfig.FrameIconPath local AtlasAssetsPath = ConstAssetPathConfig.AtlasAssetsPath local NEWLINE_STR_FORMAT = "%s\n\n%s" Item_Utility.AN_JIN_QUALITY = 7 private.SymbolShow = { [1] = { BGImage = "zb_bq_hs", NameIDS = "IDS_RebelStrike_TagType" }, [2] = { BGImage = "zb_bq_hs", NameIDS = "IDS_DigTreasure_NewHint6" }, } private.AtlasPathCache = {} -- 防止相同道具数据反复刷新Item --货币图集图标 function Item_Utility.MoneyIcon(icon, itemId) local goodsItem = DataSheetManager.ItemData:GetDataByID(itemId) UTL.Item.SetAtlasSprite(icon,"UI_Common",goodsItem.Icon) end --道具图标 function Item_Utility.ItemSquareIcon(imgIcon, bgIcon, itemId) local goodsItem = DataSheetManager.ItemData:GetDataByID(itemId) local itemIcon = string.format(ItemIconPath, goodsItem.Icon) UIUtils.SetImageByAssetBundle(imgIcon, itemIcon) if bgIcon then UTL.Color.SetQualityImageByType(bgIcon, goodsItem.Color, UTL.Color.QualityType.Square) end end -- 道具库存 function Item_Utility.GetItemStockCount(itemID) if not itemID then return 0 end local itemData = DataSheetManager.ItemData:GetDataByID(itemID) if not itemData then return 0 end if (itemData.FirstType == LuaConst.ItemType.Materials and (itemData.SecondType == 5 or itemData.SecondType == 7 or itemData.SecondType == 25)) or itemData.FirstType == LuaConst.ItemType.Guild then -- 货币 return MDL.Currency.GetMoneyCount(itemID) elseif itemData.FirstType == LuaConst.ItemType.TeamExp and itemData.SecondType == 3 then return MDL.GoldenHeroMain.GetGoldHeroEnergyInfo(itemID) elseif itemData.FirstType == LuaConst.ItemType.Equip then return MDL.Equipment.GetEquipNumByItemId(itemID) elseif itemData.FirstType == LuaConst.ItemType.Gem then return MDL.GemCompose.GetGemCountByItemId(itemID) elseif itemData.FirstType == LuaConst.ItemType.SoulCrystal then return MDL.Treasure.GetSoulCrystalCountByItemId(itemID) elseif itemID == DataSheetManager.ConstData:GetDataByID("SiegeCityGoodsID").IntValue then return MDL.ChangAnSiege.GetGoods() elseif itemData.FirstType == LuaConst.ItemType.SlgGvEMaterial then return MDL.SlgGvE.GetMaterialNum(itemID) else return MDL.Bag.GetItemCount(itemID) end end --用于HUD和显示货币的地方 function Item_Utility.SetCurrencyImageIcon(imgIcon, itemID) local itemData = DataSheetManager.ItemData:GetDataByID(itemID) if MDL.Currency.IsMoneyTypeByItemID(itemID) then UTL.Item.SetAtlasSprite(imgIcon, "UI_Common", itemData.Icon) else UIUtils.SetImageByAssetBundle(imgIcon, string.format(ItemIconPath, itemData.Icon)) end end -- UIHeroHead模板英雄头像 function Item_Utility.SetHeroHeadTemplate(componentCollection, id, levelStr) if not componentCollection then return end -- 武将头像 if id and componentCollection.img_HeroHead then UIUtils.SetActive(componentCollection.img_HeroHead.gameObject, true) UIUtils.SetActive(componentCollection.img_Empty.gameObject, false) Item_Utility.SetHeroIconByHeroId(componentCollection.img_HeroHead, id) else UIUtils.SetActive(componentCollection.img_Empty.gameObject, true) UIUtils.SetActive(componentCollection.img_HeroHead.gameObject, false) end -- 武将等级txt if levelStr and componentCollection.txt_Level then UIUtils.SetActive(componentCollection.group_Level.gameObject, true) UIUtils.SetLabel(componentCollection.txt_Level, levelStr) else UIUtils.SetActive(componentCollection.group_Level.gameObject, false) end end function Item_Utility.ItemSquareIconByHeroId(heroId, imgIcon, bgIcon, nameText, isAwaken) local heroData = DataSheetManager.HeroNum:GetDataByID(heroId) local itemId if isAwaken then itemId = CTL.HeroAwaken.GetItemIconId(heroId) end if itemId == nil then itemId = heroData.HeroItem end local goodsItem = DataSheetManager.ItemData:GetDataByID(itemId) local itemIcon = string.format(HeroIconPath, goodsItem.Icon) UIUtils.SetImageByAssetBundle(imgIcon, itemIcon) if bgIcon then UTL.Color.SetQualityImageByType(bgIcon, goodsItem.Color, UTL.Color.QualityType.Square) end if nameText then UIUtils.SetLabelText(nameText, Const_IDS[heroData.NameIDS]) end end function Item_Utility.ItemSquareItemIconByHeroId(heroId, imgIcon, bgIcon, nameText, isAwaken) local heroData = DataSheetManager.HeroNum:GetDataByID(heroId) local itemId = heroData.HeroItem if isAwaken then itemId = CTL.HeroAwaken.GetItemIconId(heroId) end local goodsItem = DataSheetManager.ItemData:GetDataByID(itemId) local itemIcon = string.format(ItemIconPath, goodsItem.Icon) UIUtils.SetImageByAssetBundle(imgIcon, itemIcon) if bgIcon then UTL.Color.SetQualityImageByType(bgIcon, goodsItem.Color, UTL.Color.QualityType.Square) end if nameText then UIUtils.SetLabelText(nameText, Const_IDS[heroData.NameIDS]) end end function Item_Utility.ItemCircleIcon(imgIcon, bgIcon, itemId) local goodsItem = DataSheetManager.ItemData:GetDataByID(itemId) local itemIcon = string.format(ItemIconPath, goodsItem.Icon) UIUtils.SetImageByAssetBundle(imgIcon, itemIcon) UTL.Color.SetQualityImageByType(bgIcon, goodsItem.Color, UTL.Color.QualityType.Circle) end --道具图标不带背景 function Item_Utility.ItemIconWithoutBg(imgIcon, itemId) local goodsItem = DataSheetManager.ItemData:GetDataByID(itemId) local path if not goodsItem then logging.error(LTAG.ERROR, "ItemData表中没有ItemId为", itemId, "的数据,请策划检查!!!") end if goodsItem.FirstType == LuaConst.ItemType.HeroFragment then path = HeroIconPath elseif goodsItem.FirstType == LuaConst.ItemType.Frame then path = FrameIconPath else path = ItemIconPath end local itemIcon = string.format(path, goodsItem.Icon) UIUtils.SetImageByAssetBundle(imgIcon, itemIcon) end --纯道具图标(不包含立绘图)不带背景 function Item_Utility.OnlyItemIconWithoutBg(imgIcon, itemId) local goodsItem = DataSheetManager.ItemData:GetDataByID(itemId) local path if not goodsItem then logging.error(LTAG.ERROR, "ItemData表中没有ItemId为", itemId, "的数据,请策划检查!!!") end if goodsItem.FirstType == LuaConst.ItemType.Frame then path = FrameIconPath else path = ItemIconPath end local itemIcon = string.format(path, goodsItem.Icon) UIUtils.SetImageByAssetBundle(imgIcon, itemIcon) end function Item_Utility.SetItemIcon(imgIcon, itemId) local goodsItem = DataSheetManager.ItemData:GetDataByID(itemId) local itemIcon = string.format(ItemIconPath, goodsItem.Icon) UIUtils.SetImageByAssetBundle(imgIcon, itemIcon) end --道具图标不带背景 function Item_Utility.ItemRawIconWithoutBg(rawIcon, itemId) local goodsItem = DataSheetManager.ItemData:GetDataByID(itemId) local itemIcon = string.format(ItemIconPath, goodsItem.Icon) UIUtils.SetTextureByAssetBundle(rawIcon, itemIcon) end function Item_Utility.ItemIconByName(imgIcon, iconName) local itemIcon = string.format(ItemIconPath, iconName) UIUtils.SetImageByAssetBundle(imgIcon, itemIcon) end --设置武将整卡的信息,头像、背景 function Item_Utility.SetHeroHeadSquareIconAndBg(headImg, bgImg, id) local itemData = DataSheetManager.ItemData:GetDataByID(id) local heroIcon = string.format(HeroIconPath, itemData.Icon) UIUtils.SetImageByAssetBundle(headImg, heroIcon) UTL.Color.SetQualityImageByType(bgImg, itemData.Color, UTL.Color.QualityType.HeroSelectBg) end function Item_Utility.SetHeroHeadSquareIcon(headImg, id) local itemData = DataSheetManager.ItemData:GetDataByID(id) local heroIcon = string.format(HeroIconPath, itemData.Icon) UIUtils.SetImageByAssetBundle(headImg, heroIcon) end function Item_Utility.SetRawHeroIcon(rawImage, id) local itemData = DataSheetManager.ItemData:GetDataByID(id) local heroIcon = string.format(HeroIconPath,itemData.Icon) UIUtils.SetTextureByAssetBundle(rawImage, heroIcon) end function Item_Utility.SetHeroIconByHeroId(img, heroId, isAwaken) if heroId then if isAwaken then CTL.HeroAwaken.SetHeroIconByHeroId(img, heroId) else local heroData = DataSheetManager.HeroNum:GetDataByID(heroId) if not heroData and heroId then logging.error(LTAG.ERROR, "No Hero Data With Id:", heroId) return end local path = string.format(HeroIconPath, heroData.SquareHead) UIUtils.SetImageByAssetBundle(img, path) end else logging.error(LTAG.ERROR, "HYW : heroId nil Error @SetHeroIconByHeroId!") end end local HeroHalfCardImagePath = ConstAssetPathConfig.HeroPicPath function Item_Utility.SetHeroHalfCardImageByHeroId(cardImg, heroId, isAwaken) if isAwaken then CTL.HeroAwaken.SetHeroHalfCardImageByHeroId(cardImg, heroId) else local heroData = DataSheetManager.HeroNum:GetDataByID(heroId) if not heroData then logging.error(LTAG.ERROR, "No Hero Data With Id:", heroId) return end local path = string.format(HeroHalfCardImagePath, heroData.HalfCardImage) UIUtils.SetImageByAssetBundle(cardImg, path) end end function Item_Utility.SetItemCell(componentCollection, id, count, isFirstPassReward, tagType, playEffect) if not componentCollection then logging.error(LTAG.ERROR, "SetItemCell传入的componentCollection为空,请检查!!!", componentCollection, id) return end local itemData = DataSheetManager.ItemData:GetDataByID(id) if itemData == nil then logging.error(LTAG.ERROR, "道具ID:", id, "没有数据!!!请策划检查!!!") end UIUtils.SetActive(componentCollection.group_HorseSoul, itemData.FirstType == LuaConst.ItemType.HorseSoul) local itemIcon = "" if itemData.FirstType == LuaConst.ItemType.Frame then itemIcon = string.format(FrameIconPath, itemData.Icon) elseif itemData.FirstType == LuaConst.ItemType.HorseSoul then itemIcon = string.format(ItemIconPath, itemData.Icon) local soulData = DataSheetManager.HorseSoulData:GetDataByHorseSoulID(id) CTL.HorseSoul.SetPositionImage(componentCollection.img_Pos, soulData.HorseSoulPositionID) UIUtils.SetActive(componentCollection.group_Star.gameObject, itemData.Color >= LuaConst.QualityColor.Gold) if itemData.Color >= LuaConst.QualityColor.Gold then CTL.HorseSoul.SetStarLevel(componentCollection.group_Star, 0) end UIUtils.SetLabel(componentCollection.txt_Level, 1) else itemIcon = string.format(ItemIconPath, itemData.Icon) end UIUtils.SetImageByAssetBundle(componentCollection.img_Item, itemIcon) -- 考虑到从缓存池中拿出的有可能是置灰过的图片 所以每次设置去除置灰效果 UIUtils.SetGray(componentCollection.img_Item, false) --碎片图标显示 if itemData.ChipType > 0 then UIUtils.SetActive(componentCollection.group_Shard, true) else UIUtils.SetActive(componentCollection.group_Shard, false) end --道具底色 UTL.Color.SetQualityImageByType(componentCollection.sprite_Rank, itemData.Color, UTL.Color.QualityType.Square) Item_Utility.PlayItemEffect(componentCollection, id, playEffect) local isForgeFragmentItem = itemData.FirstType == LuaConst.ItemType.WeaponFragment and itemData.SecondType == LuaConst.ItemWeaponType.ForgeWeaponItem componentCollection.state_Forge:SetState(isForgeFragmentItem and 0 or 1) --道具数量 Item_Utility.SetItemCount(componentCollection, count) if isFirstPassReward then UIUtils.SetActive(componentCollection.group_FirstDone, true) else UIUtils.SetActive(componentCollection.group_FirstDone, false) end --右上角显示 if tagType and tagType > 0 then UIUtils.SetActive(componentCollection.group_txt_Elite, true) local info = private.SymbolShow[tagType] UTL.Item.SetAtlasSprite(componentCollection.img_Elite, "UI_Common", info.BGImage) UIUtils.SetLabelText(componentCollection.txt_Elite, Const_IDS[info.NameIDS]) else UIUtils.SetActive(componentCollection.group_txt_Elite, false) end --重置上阵、助阵、突破等级信息,有需要的话调用SetFormationAndBreakLv设置。否则对象池复用时会有状态残留 UIUtils.SetActive(componentCollection.group_Fomation, false) UIUtils.SetActive(componentCollection.group_txt_Break, false) end --对应类型需要显示上阵、助阵、突破等级信息。 --注意如果componentCollection是实例化出来的,其父节点体模板得挂UIComponentCollectionTemplate,避免初始化两份的问题 function Item_Utility.SetFormationAndBreakLv(componentCollection, id) local isShowMain, isShowAssist, breakLv = CTL.PayMall.GetItemUseState(id) --SetItemCell的时候已经重置过了,这里只写true的处理 if isShowMain or isShowAssist then UIUtils.SetActive(componentCollection.group_Fomation, true) if isShowMain then componentCollection.state_Fomation:SetState(0) componentCollection.img_Main:PlayUIEffect() else componentCollection.state_Fomation:SetState(1) componentCollection.img_Ass:PlayUIEffect() end end if breakLv and breakLv > 0 then UIUtils.SetActive(componentCollection.group_txt_Break, true) UIUtils.SetLabel(componentCollection.txt_Break, "+" .. breakLv) end end function Item_Utility.PlayItemEffect(componentCollection, id, playEffect) -- 彩金品质,使用通用节点,不再新增加 if componentCollection.effect_ItemExtra then componentCollection.effect_ItemExtra:StopUIEffect() if playEffect == nil or playEffect then UTL.Color.PlayQualityEffect(componentCollection.effect_ItemExtra, Item_Utility.GetEffectIdByItemId(id), UTL.Color.EffectType.Item) end end end function Item_Utility.SetItemCount(componentCollection, count) if count then UIUtils.SetActive(componentCollection.group_Count.gameObject, true) if type(count) == "number" then private.SetCount(componentCollection.lab_Count, count) UIUtils.SetTextAlignmentCenter(componentCollection.lab_Count, false) elseif type(count) == "string" and not string.isNilOrEmpty(count) then local index = string.find(count, 'IDS_') if index and index>0 then UIUtils.SetLabelText(componentCollection.lab_Count, Const_IDS[count]) else -- 当物品数量为字符串时,字符真实长度超过8个字符居中显示 if UTL.String.GetTextCharLengthWithoutRichTag(count) <= 8 then UIUtils.SetTextAlignmentCenter(componentCollection.lab_Count, false) else UIUtils.SetTextAlignmentCenter(componentCollection.lab_Count, true) end UIUtils.SetLabel(componentCollection.lab_Count, count) end else UIUtils.SetActive(componentCollection.group_Count.gameObject, false) end else UIUtils.SetActive(componentCollection.group_Count.gameObject, false) end end function Item_Utility.SetItemExpireTime(txt_Time, expireTime) txt_Time:SetDHMSStr( UIUtils.GetLocalizedTxt(Const_IDS["IDS_DirectGift_TimeHint_1"]), UIUtils.GetLocalizedTxt(Const_IDS["IDS_DirectGift_TimeHint_2"]), UIUtils.GetLocalizedTxt(Const_IDS["IDS_DirectGift_TimeHint_3"]), UIUtils.GetLocalizedTxt(Const_IDS["IDS_DirectGift_TimeHint_4"]) ) txt_Time:ResetAndBeginCustomTimer(false, expireTime, 0, 1) end function Item_Utility.GetEffectIdByItemId(id) local itemData = DataSheetManager.ItemData:GetDataByID(id) local eftID if itemData.FirstType == LuaConst.ItemType.HeroFragment then local heroNumCfg = DataSheetManager.HeroNum:GetDataByID(itemData.ThirdType) if heroNumCfg and heroNumCfg.EffectID > 0 then eftID = heroNumCfg.EffectID end elseif itemData.FirstType == LuaConst.ItemType.WeaponFragment and itemData.SecondType == LuaConst.ItemWeaponType.WeaponFragment then local magicWeaponCfg = DataSheetManager.MagicWeaponData:GetDataByMagicWeaponID(itemData.ThirdType) if magicWeaponCfg and magicWeaponCfg.EffectID > 0 then eftID = magicWeaponCfg.EffectID end elseif itemData.FirstType == LuaConst.ItemType.Treasure then local treasureId = MDL.Treasure.GetTreasureIdByItemId(id) local treasureData = DataSheetManager.TreasureData:GetDataByTreasureID(treasureId) if treasureData and treasureData.TreasureQualityEffect > 0 then eftID = treasureData.TreasureQualityEffect end elseif itemData.FirstType == LuaConst.ItemType.Appearance then if itemData.SecondType == MDL.Appearance.AppearanceType.Hero then if itemData.ThirdType > 0 then local heroAppearanceCfg = DataSheetManager.HeroAppearance:GetDataByID(itemData.ThirdType) if heroAppearanceCfg and heroAppearanceCfg.EffectID > 0 then eftID = heroAppearanceCfg.EffectID end end elseif itemData.SecondType == MDL.Appearance.AppearanceType.Weapon then if itemData.ThirdType > 0 then local weaponAppearanceCfg = DataSheetManager.WeaponAppearance:GetDataByID(itemData.ThirdType) if weaponAppearanceCfg and weaponAppearanceCfg.EffectID > 0 then eftID = weaponAppearanceCfg.EffectID end end elseif itemData.SecondType == MDL.Appearance.AppearanceType.Horse then if itemData.ThirdType > 0 then local horseAppearanceCfg = DataSheetManager.HorseAppearance:GetDataByID(itemData.ThirdType) if horseAppearanceCfg and horseAppearanceCfg.EffectID > 0 then eftID = horseAppearanceCfg.EffectID end end end elseif itemData.FirstType == LuaConst.ItemType.Stratagem then if itemData.SecondType == LuaConst.ItemStratagemType.Fragment then local stratagemDataCfg = DataSheetManager.StratagemData:GetDataByID(itemData.ThirdType) if stratagemDataCfg and stratagemDataCfg.StratagemColorEffect > 0 then eftID = stratagemDataCfg.StratagemColorEffect end end elseif itemData.FirstType == LuaConst.ItemType.Horse then local horseId = MDL.WarHorse.GetHorseIdByItemId(id) local horseData = DataSheetManager.HorseData:GetDataByHorseID(horseId) if horseData and horseData.HorseColorEffectID > 0 then eftID = horseData.HorseColorEffectID end elseif itemData.FirstType == LuaConst.ItemType.GodBeast then local godBeastData = MDL.GodBeast.GetGodBeastDataByItemId(id) if godBeastData and godBeastData.GodBeastColorEffect > 0 then eftID = godBeastData.GodBeastColorEffect end elseif itemData.FirstType == LuaConst.ItemType.Pet then if itemData.SecondType == LuaConst.ItemMaterialsType.BreakPill then for _, v in DataSheetManager.PetRelation:GetEnumerator() do if v.ItemID == id then eftID = CTL.Pet.ConstPetItemEffectID break end end elseif itemData.SecondType == LuaConst.ItemMaterialsType.JingHunStone then if itemData.ThirdType > 0 then local petDataCfg = DataSheetManager.PetData:GetDataByID_Stage(itemData.ThirdType, 0) if petDataCfg and petDataCfg.EffectID > 0 then eftID = petDataCfg.EffectID end end end end return eftID end --单个属性 function Item_Utility.GetAttrDict(Attr_Table) local attrDict = {} for k, v in pairs(Attr_Table) do local AttrCfgData = DataSheetManager.AttrData:GetDataByID(v.AttrType) attrDict[UIUtils.GetLocalizedTxt(Const_IDS[AttrCfgData.Name])] = v.AttrNum end return attrDict end --属性值差 function Item_Utility.GetCompareAttrDict(Attr_Table1, Attr_Table2) local attrDict1 = Item_Utility.GetAttrDict(Attr_Table1) local attrDict2 = Item_Utility.GetAttrDict(Attr_Table2) local attrDict = {} local hasData = false for k,v in pairs(attrDict1) do hasData = true if attrDict2[k] ~= nil then attrDict[k] = math.abs(v - attrDict2[k]) end end if hasData then return attrDict end return attrDict2 end function Item_Utility.IsItemWholeHero(itemId) --物品是否为武将整卡 local itemData = DataSheetManager.ItemData:GetDataByID(itemId) if itemData then if itemData.FirstType == LuaConst.ItemType.HeroFragment and itemData.SecondType == LuaConst.ItemHeroType.Hero then return itemData.BelongToHero end else logging.error(LTAG.ERROR, "未找到物品Id:",itemId) end return false end function Item_Utility.GetItemDrawCardColor(itemId) local itemData = DataSheetManager.ItemData:GetDataByID(itemId) if itemData then return itemData.DrawCardColor else logging.error(LTAG.ERROR, "未找到物品Id:",itemId) return 0 end end function private.SetCount(label, count) local num = UTL.String.GetCountStr(count) label.text = num end -- ItemData中道具字符串拼接 ---@param itemId number 配置表id ---@param id number 道具实例id ---@return table function Item_Utility.GetItemDataSpliceByType(itemId, id) local itemData = DataSheetManager.ItemData:GetDataByID(itemId) local itemDataName,itemDataDes = private.GetNameAndDes(itemData) local dataSplice = {} --势力战装备宝箱需要等级自适应显示概率 local desc = CTL.GuildWar.GetEquipBoxDesc(itemId) if desc then dataSplice.Name = itemDataName dataSplice.Des = desc return dataSplice end if itemData.FirstType == LuaConst.ItemType.Gem then dataSplice.Name = string.format(itemDataName, itemData.ThirdType) dataSplice.Des = string.format(itemDataDes, itemData.ThirdType) elseif itemData.FirstType == LuaConst.ItemType.Equip then local equipData = DataSheetManager.EquipData:GetDataByID(itemId) local expStr = UTL.Color.FormatQualityText(equipData.ResonanceExp, itemData.Color) dataSplice.Name = itemDataName dataSplice.Des = string.format(itemDataDes, expStr) elseif itemData.FirstType == LuaConst.ItemType.Portrait then dataSplice.Name = itemDataName local portraitData = MDL.Character.GetPortraitDataByItemId(itemId) if portraitData then local portraitName = UIUtils.GetLocalizedTxt(Const_IDS[portraitData.Name]) local duration = "" if portraitData.Duration == 0 then duration = UIUtils.GetLocalizedTxt(Const_IDS.IDS_HeadPortraitAndBox_GotForever) else duration = UTL.Time.FormatTimeForTitle(portraitData.Duration) end local getWay = CTL.Character.GetDescribeByPortraitId(portraitData.ID) dataSplice.Des = string.FormatByIdsId(Const_IDS.IDS_HeadPortraitAndBox_Des1, portraitName, duration, getWay) else dataSplice.Des = "" end elseif itemData.FirstType == LuaConst.ItemType.Frame then dataSplice.Name = itemDataName local frameData = MDL.Character.GetFrameDataByItemId(itemId) if frameData then local frameName = UIUtils.GetLocalizedTxt(Const_IDS[frameData.Name]) local duration = "" if frameData.Duration == 0 then duration = UIUtils.GetLocalizedTxt(Const_IDS.IDS_HeadPortraitAndBox_GotForever) else duration = UTL.Time.FormatTimeForTitle(frameData.Duration) end local getWay = UIUtils.GetLocalizedTxt(Const_IDS[frameData.Describe]) dataSplice.Des = string.FormatByIdsId(Const_IDS.IDS_HeadPortraitAndBox_Des2, frameName, duration, getWay) else dataSplice.Des = "" end elseif itemData.FirstType == LuaConst.ItemType.Title then dataSplice.Name = itemDataName local titleData = CTL.Title.GetTitleDataByItemId(itemId) if titleData then local titleName = UIUtils.GetLocalizedTxt(Const_IDS[titleData.Name]) local duration = "" if titleData.Time <= 0 then duration = UIUtils.GetLocalizedTxt(Const_IDS.IDS_HeadPortraitAndBox_GotForever) else duration = UTL.Time.GetShowTimeBySeconds(titleData.Time) end local getWay = string.format(UIUtils.GetLocalizedTxt(Const_IDS[titleData.Describe], titleData.parm1, titleData.parm2)) dataSplice.Des = string.FormatByIdsId(Const_IDS.IDS_WarZoneAuction_24, titleName, duration, getWay) else dataSplice.Des = "" end elseif itemData.FirstType == LuaConst.ItemType.Materials and itemData.SecondType == LuaConst.ItemType.HeroEffect then dataSplice.Name = itemDataName local _, lightEffectData = DataSheetManager.LightEffect:TryGetDataByID(itemId) if lightEffectData then local duration = "" if lightEffectData.Time > 0 then duration = "\n" .. string.FormatByIdsId(Const_IDS.IDS_LightEffect_Time_3, UTL.Time.GetShowTimeBySeconds(lightEffectData.Time)) else duration = "\n" .. string.FormatByIdsId(Const_IDS.IDS_LightEffect_Time_3, UIUtils.GetLocalizedTxt(Const_IDS.IDS_HeadPortraitAndBox_GotForever)) end local getWay = UIUtils.GetLocalizedTxt(Const_IDS[lightEffectData.Describe]) local des = itemDataDes if #lightEffectData.ActivationSkin > 0 then --按皮肤激活显示 dataSplice.Des = string.format(NEWLINE_STR_FORMAT, des .. duration, getWay) else --按道具激活显示 local attributeDes = private.GetAttrDes(lightEffectData.Attr_Table) dataSplice.Des = string.FormatByIdsId(Const_IDS.IDS_ItemDes_LightEffect,dataSplice.Name) .. duration .. attributeDes .. string.format(NEWLINE_STR_FORMAT, des, getWay) end else dataSplice.Des = "" end elseif itemData.FirstType == LuaConst.ItemType.Appearance then dataSplice.Name = itemDataName local addContent = "" local attributeList = {} local attributeDes = "" if itemData.SecondType == MDL.Appearance.AppearanceType.Hero then --武将时装 local appearanceId local heroName = "" for k,appearanceCfg in DataSheetManager.HeroAppearance:GetEnumerator() do if appearanceCfg.Activation == itemData.ID then appearanceId = appearanceCfg.ID local heroData = DataSheetManager.HeroData:GetDataByID(appearanceCfg.HeroID) if heroData then heroName = UIUtils.GetLocalizedTxt(Const_IDS[heroData.NameIDS]) end --典藏外观的属性特殊处理 local dyeAttr = CTL.DyeAppearance.GetSuitExtraAttr(appearanceId, true) if dyeAttr then for type, value in pairs(dyeAttr) do table.insert(attributeList, {AttrType = type, AttrNum = value}) end else attributeList = appearanceCfg.Attr_Table end break end end addContent = string.FormatByIdsId(Const_IDS.IDS_ItemDes_HeroAppearance, heroName, dataSplice.Name) attributeDes = private.GetAttrDes(attributeList) dataSplice.Des = addContent .. attributeDes .. itemDataDes elseif itemData.SecondType == MDL.Appearance.AppearanceType.Weapon then --神兵时装 local weaponName = "" for k,appearanceCfg in DataSheetManager.WeaponAppearance:GetEnumerator() do if appearanceCfg.Activation == itemData.ID then local heroData = DataSheetManager.HeroData:GetDataByID(appearanceCfg.HeroID) if heroData then weaponName = UIUtils.GetLocalizedTxt(Const_IDS[heroData.NameIDS]) end attributeList = appearanceCfg.Attr_Table break end end addContent = string.FormatByIdsId(Const_IDS.IDS_ItemDes_WeaponAppearance, weaponName, dataSplice.Name) attributeDes = private.GetAttrDes(attributeList) dataSplice.Des = addContent .. attributeDes .. itemDataDes elseif itemData.SecondType == MDL.Appearance.AppearanceType.Horse then dataSplice.Name = itemDataName local appearanceData = MDL.WarHorse.GetAppearanceDataByItemID(itemId) local duration if appearanceData.Duration > 0 then duration = UTL.Time.GetShowTimeBySeconds(appearanceData.Duration) else duration = UIUtils.GetLocalizedTxt(Const_IDS["IDS_HorseAppearance_GotForever"]) end dataSplice.Des = string.FormatByIdsId(Const_IDS["IDS_HorseAppearance_Des"], UIUtils.GetLocalizedTxt(Const_IDS[appearanceData.Name]), duration, -- 有效期 UIUtils.GetLocalizedTxt(Const_IDS[appearanceData.Describe]), -- 获取方式 UIUtils.GetLocalizedTxt(Const_IDS[appearanceData.AppearanceDes]) --皮肤简介 ) end elseif itemData.FirstType == LuaConst.ItemType.HeroSubstitute and itemData.SecondType == LuaConst.ItemHeroSubstituteType.RegretSubstitute then --武将置换反悔道具 dataSplice.Name = itemDataName local heroReSubstituteItemExtraData = MDL.Bag.GetHeroReSubstituteItemExtraDataById(id) local hero1Name, hero2Name if heroReSubstituteItemExtraData then hero1Name = CTL.HeroSelect.GetHeroQualityName(heroReSubstituteItemExtraData.hero1ID) hero2Name = CTL.HeroSelect.GetHeroQualityName(heroReSubstituteItemExtraData.hero2ID) end dataSplice.Des = string.FormatByIdsId(Const_IDS[itemData.Des], hero1Name, hero2Name) elseif itemData.FirstType == LuaConst.ItemType.HorseEquip then dataSplice.Name = itemDataName local cfg = DataSheetManager.HorseEquipData:GetDataByID(itemId) local expStr = UTL.Color.FormatQualityText(cfg.ResonanceExp, itemData.Color) dataSplice.Des = string.FormatByIdsId(Const_IDS[itemData.Des], expStr) elseif itemData.FirstType == LuaConst.ItemType.GiftBag and itemData.SecondType == LuaConst.ItemGiftBagType.RechargeGiftBag then dataSplice.Name = itemDataName local rechargeScore = MDL.Currency.GetTotalRechargeCredit() local rechargeScoreStr = UTL.Color.FormatGreenColor(rechargeScore) if itemData.LimitRequireRechargeScore > rechargeScore then rechargeScoreStr = UTL.Color.FormatRedColor(rechargeScore) end dataSplice.Des = string.FormatByIdsId(Const_IDS[itemData.Des], rechargeScoreStr, itemData.LimitRequireRechargeScore) else dataSplice.Name = itemDataName dataSplice.Des = itemDataDes end return dataSplice end --检查是否有配置IDSCombine,配置了就优先使用 function private.GetNameAndDes(itemData) local name local des local combineId = itemData.NameIDSCombine if combineId and combineId > 0 then name = UTL.String.FormatCombineTextByID(combineId) else name = UIUtils.GetLocalizedTxt(Const_IDS[itemData.Name]) end combineId = itemData.DesIDSCombine if combineId and combineId > 0 then des = UTL.String.FormatCombineTextByID(combineId) else des = UIUtils.GetLocalizedTxt(Const_IDS[itemData.Des]) end return name, des end function private.GetAttrDes(attributeList) local attributeNames = {} for _, attrInfo in ipairs(attributeList) do local AttrCfgData = DataSheetManager.AttrData:GetDataByID(attrInfo.AttrType) table.insert(attributeNames, UIUtils.GetLocalizedTxt(Const_IDS[AttrCfgData.Name])) end return string.FormatByIdsId(Const_IDS.IDS_Appearance_JiHuoShuXingZhi, attributeNames[1], attributeList[1].AttrNum, attributeNames[2], attributeList[2].AttrNum, attributeNames[3], attributeList[3].AttrNum) end --得到物品的品质名字 function Item_Utility.GetItemColorName(itemId) local itemCfgData = DataSheetManager.ItemData:GetDataByID(itemId) local itemNameAndDesc = Item_Utility.GetItemDataSpliceByType(itemId); return UTL.Color.FormatQualityText(itemNameAndDesc.Name, itemCfgData.Color); end function Item_Utility.GetItemName(itemId) local itemCfgData = DataSheetManager.ItemData:GetDataByID(itemId) local itemNameAndDesc = Item_Utility.GetItemDataSpliceByType(itemId); return itemNameAndDesc.Name end --对指定内容设置成道具的品质色 function Item_Utility.GetItemColorContent(itemId,content) local itemCfgData = DataSheetManager.ItemData:GetDataByID(itemId) return UTL.Color.FormatQualityText(content, itemCfgData.Color); end -- 商品图标和品质色底色 local imgPathTemplate = ConstAssetPathConfig.Path0 function Item_Utility.SetStoreGoodsQualityImg(itemId, itemIcon, nameBg, itemBg) local itemCfgData = DataSheetManager.ItemData:GetDataByID(itemId) local path if itemCfgData.FirstType == LuaConst.ItemType.HeroFragment then path = HeroIconPath elseif itemCfgData.FirstType == LuaConst.ItemType.Frame then path = FrameIconPath else path = ItemIconPath end UIUtils.SetImageByAssetBundle(itemIcon, string.format(path, itemCfgData.Icon)) UTL.Color.SetQualityImageByType(nameBg, itemCfgData.Color, UTL.Color.QualityType.StoreGoodsNameBase) UTL.Color.SetQualityImageByType(itemBg, itemCfgData.Color, UTL.Color.QualityType.StoreGoodsIconBase) end -- 图文混排 ---@param imgPath 战队等级(以"Dynamic/"开头) ---@param size 图片大小 ---@param param 图片后拼接字符串 --- 使用举例 this.text = aaaaggg function Item_Utility.GetImageAndText(imgPath, size, param) if size == nil then size = 1 end return string.format("%s", imgPath, size, param) end -- 等级转换成爵位显示 ---@param teamLevel 战队等级 ---@return nobilityIcon 爵位图标 ---@return nobilityLevel 爵位等级 --- 使用举例 this.text = aaaaggg ---size只能使用整数,不知后续是否有优化方案 function Item_Utility.GetNobilityByTeamLevel(teamLevel, size) if size == nil then size = 2 end if teamLevel <= DataSheetManager.Nobility:GetDataByRankID(1).TeamLevelMax then return teamLevel end for k,v in DataSheetManager.Nobility:GetEnumerator() do if v.TeamLevelMax == -1 or v.TeamLevelMax >= teamLevel then local level = teamLevel - DataSheetManager.Nobility:GetDataByRankID(k - 1).TeamLevelMax local imgPath= string.format("Localization/%s/%s",Localization.GetLanguage(),v.SmallIcon) return string.format("%s", imgPath, size, level) end end end --获取爵位等级,图片资源 function Item_Utility.SetNobilityIcon(teamLevel, imgIcon) if teamLevel <= DataSheetManager.Nobility:GetDataByRankID(1).TeamLevelMax then UIUtils.SetActive(imgIcon, false) return teamLevel end for k,v in DataSheetManager.Nobility:GetEnumerator() do if v.TeamLevelMax == -1 or v.TeamLevelMax >= teamLevel then local level = teamLevel - DataSheetManager.Nobility:GetDataByRankID(k - 1).TeamLevelMax UIUtils.SetLocalizationImage(imgIcon, string.format(NobilityIconPath, v.SmallIcon)) UIUtils.SetActive(imgIcon, true) return level end end end function Item_Utility.GetTypeNameByConstItemId(itemId) for _, v in MDL.OperationActivity.StoreGoodsData:GetEnumerator() do if v.MoneyID == itemId then local storeData = MDL.OperationActivity.StoreTypeData:GetDataByTabID(v.TabID) if storeData.TypeID == MDL.PayMall.ShopType.Store then return UIUtils.GetLocalizedTxt(Const_IDS.IDS_Store) else return UIUtils.GetLocalizedTxt(Const_IDS.IDS_Store_PayStore) end end end end --设置国际化图片的接口,以后扩展修改可以只改这一处接口即可 --localizationState UIStateSwitch 为空则表示不判断state --localizationImage Image --imgPath 路径,语种后面的 function Item_Utility.SetLocalizationImage(localizationState, localizationImage, imgPath) if not localizationState then UIUtils.SetLocalizationImage(localizationImage, imgPath) elseif localizationState.CurState == 0 then UIUtils.SetLocalizationImage(localizationImage, imgPath) end end function Item_Utility.SetAtlasSprite(comp, atlasname, spritename) local cacheTable = private.AtlasPathCache[atlasname] local spritePath if cacheTable then spritePath = cacheTable[spritename] if not spritePath then spritePath = string.format(AtlasAssetsPath, atlasname, spritename) cacheTable[spritename] = spritePath end else spritePath = string.format(AtlasAssetsPath, atlasname, spritename) private.AtlasPathCache[atlasname] = {} private.AtlasPathCache[atlasname][spritename] = spritePath end UIUtils.SetImageByAssetBundle(comp, spritePath) end function Item_Utility.GetDarkGoldenEffectDatas(eftID, propertyName) if not eftID or eftID<=0 then return nil end local __, effectData = DataSheetManager.QualityEffect:TryGetDataByID(eftID) if effectData then return effectData[propertyName], effectData[propertyName .. "Offset"] end return nil end return Item_Utility