优化排序

This commit is contained in:
xiekaidong 2023-04-23 12:07:42 +08:00
parent 26fab280b3
commit 153cf72fb2
6 changed files with 26 additions and 30 deletions

View File

@ -16,7 +16,7 @@ function HeroManager:upgradeHero(heroId, heroEntity)
end end
local fragmentCost = materials[1] or 0 local fragmentCost = materials[1] or 0
if not GFunc.checkCost(heroEntity:getFramentId(), fragmentCost, true) then if not GFunc.checkCost(heroEntity:getFragmentId(), fragmentCost, true) then
return return
end end

View File

@ -29,7 +29,7 @@ function HeroCell:refresh(heroEntity, isGray)
self.lvUpArrow:setVisible(canLvUp) self.lvUpArrow:setVisible(canLvUp)
self.fragmenImg:setVisible(not canLvUp) self.fragmenImg:setVisible(not canLvUp)
local materials = heroEntity:getLvUpMaterials() or {} local materials = heroEntity:getLvUpMaterials() or {}
local fragmentCount = DataManager.BagData.ItemData:getItemNumById(heroEntity:getFramentId()) local fragmentCount = DataManager.BagData.ItemData:getItemNumById(heroEntity:getFragmentId())
local needFragmentCount = materials[1] or 1 local needFragmentCount = materials[1] or 1
self.progressTx:setText(fragmentCount .. "/" .. needFragmentCount) self.progressTx:setText(fragmentCount .. "/" .. needFragmentCount)
self.progress:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER).value = fragmentCount / needFragmentCount self.progress:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER).value = fragmentCount / needFragmentCount

View File

@ -46,7 +46,7 @@ function HeroListCell:refresh(index, heroList, stageFormation, allHeroCount, act
local heroIndex = heroStartIndex local heroIndex = heroStartIndex
for i = 1, 4 do for i = 1, 4 do
if heroIndex <= activeCount then if heroIndex <= activeCount then
local heroId = heroList[heroIndex] local heroId = heroList[heroIndex].cfgId
local heroEntity = DataManager.HeroData:getHeroById(heroId) local heroEntity = DataManager.HeroData:getHeroById(heroId)
local matchType = heroEntity:getMatchType() local matchType = heroEntity:getMatchType()
self.heroCells[i]:setVisible(true) self.heroCells[i]:setVisible(true)
@ -61,7 +61,7 @@ function HeroListCell:refresh(index, heroList, stageFormation, allHeroCount, act
if heroStartIndex <= activeCount then if heroStartIndex <= activeCount then
self.heroCells[i]:setVisible(false) self.heroCells[i]:setVisible(false)
else else
local heroId = heroList[heroIndex] local heroId = heroList[heroIndex].cfgId
local heroEntity = DataManager.HeroData:getHeroById(heroId) local heroEntity = DataManager.HeroData:getHeroById(heroId)
self.heroCells[i]:setVisible(true) self.heroCells[i]:setVisible(true)
self.heroCells[i]:refresh(heroEntity, true) self.heroCells[i]:refresh(heroEntity, true)

View File

@ -17,7 +17,7 @@ function HeroComp:init()
self.heroList = {} self.heroList = {}
local heroCfg = ConfigManager:getConfig("hero") local heroCfg = ConfigManager:getConfig("hero")
for id, v in pairs(heroCfg) do for id, v in pairs(heroCfg) do
table.insert(self.heroList, id) table.insert(self.heroList, {cfgId = id, sort = id, elementType = v.position})
end end
self.heroNodeList = { self.heroNodeList = {
self.uiMap["hero_ui.formation.hero_1"], self.uiMap["hero_ui.formation.hero_1"],
@ -120,30 +120,26 @@ function HeroComp:sortHeroList()
local heroA local heroA
local heroB local heroB
local HeroData = DataManager.HeroData local HeroData = DataManager.HeroData
table.sort(self.heroList, function(a, b) for _, info in ipairs(self.heroList) do
heroA = HeroData:getHeroById(a) local heroEntity = HeroData:getHeroById(info.cfgId)
heroB = HeroData:getHeroById(b) local sort = info.cfgId -- id 预留6位
if heroA:isUnlock() == heroB:isUnlock() then sort = sort + (10 - info.elementType) * 1000000 -- 位置预留1位
if heroA:isActived() and heroB:isActived() then
if heroA:getLv() == heroB:getLv() then if heroEntity:isUnlock() then
if heroA:getQlt() == heroB:getQlt() then sort = sort + 30000000
return a > b elseif DataManager.BagData.ItemData:getItemNumById(heroEntity:getFragmentId()) > 0 then
else sort = sort + 20000000
return heroA:getQlt() > heroB:getQlt()
end
else
return heroA:getLv() > heroB:getLv()
end
elseif heroA:isActived() and not heroB:isActived() then
return true
elseif heroB:isActived() and not heroA:isActived() then
return false
else
return a > b
end
else else
return heroA:isUnlock() sort = sort + 10000000
end end
sort = sort + 100000000 * heroEntity:getQlt() -- 品质1位
sort = sort + 1000000000 * heroEntity:getLv() -- 预留3位
info.sort = sort
end
table.sort(self.heroList, function(a, b)
return a.sort > b.sort
end) end)
end end

View File

@ -41,7 +41,7 @@ function HeroDetailUI:_display()
uiMap["hero_detail_ui.bg.hero_element"]:setSprite(GConst.ATLAS_PATH.ICON_HERO, ModuleManager.HeroManager:getMatchTypeIcon(self.heroEntity:getMatchType())) uiMap["hero_detail_ui.bg.hero_element"]:setSprite(GConst.ATLAS_PATH.ICON_HERO, ModuleManager.HeroManager:getMatchTypeIcon(self.heroEntity:getMatchType()))
local materials = self.heroEntity:getLvUpMaterials() or {} local materials = self.heroEntity:getLvUpMaterials() or {}
local fragmentCount = DataManager.BagData.ItemData:getItemNumById(self.heroEntity:getFramentId()) local fragmentCount = DataManager.BagData.ItemData:getItemNumById(self.heroEntity:getFragmentId())
local needFragmentCount = materials[1] or 1 local needFragmentCount = materials[1] or 1
uiMap["hero_detail_ui.bg.fragment_num"]:setText(fragmentCount .. "/" .. needFragmentCount) uiMap["hero_detail_ui.bg.fragment_num"]:setText(fragmentCount .. "/" .. needFragmentCount)
uiMap["hero_detail_ui.bg.slider"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER).value = fragmentCount / needFragmentCount uiMap["hero_detail_ui.bg.slider"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER).value = fragmentCount / needFragmentCount

View File

@ -149,7 +149,7 @@ function HeroEntity:canLvUp()
end end
local fragmentCost = cost[1] or 0 local fragmentCost = cost[1] or 0
if not GFunc.checkCost(self:getFramentId(), fragmentCost, false) then if not GFunc.checkCost(self:getFragmentId(), fragmentCost, false) then
return false return false
end end
local goldCost = cost[2] or 0 local goldCost = cost[2] or 0
@ -205,7 +205,7 @@ function HeroEntity:getHurtSkill()
return self.config.hurt_skill return self.config.hurt_skill
end end
function HeroEntity:getFramentId() function HeroEntity:getFragmentId()
return self.config.item_id return self.config.item_id
end end