主城资源栏

This commit is contained in:
chenxi 2023-05-12 11:54:45 +08:00
parent 7005bd8c0f
commit 2a8dd6bbca

View File

@ -272,6 +272,26 @@ function MainCityUI:initLeftRightBtns()
if self.sideBarCellMap == nil then if self.sideBarCellMap == nil then
self.sideBarCellMap = {} self.sideBarCellMap = {}
end end
self:recycleSideBarCells(self.leftSideBar)
self:recycleSideBarCells(self.rightSideBar)
end
function MainCityUI:recycleSideBarCells(list)
local childList = list:getChildList()
if childList and #childList > 0 then
local count = #childList
for i = count, 1, -1 do
local child = childList[i]
local name = child:getName()
if name and name ~= "" then
child:setVisible(false)
self.sideBarCellMap[name] = child:getLuaComponent(name)
else
child:destroy()
table.remove(childList, i)
end
end
end
end end
function MainCityUI:addSideBarCellComp(cellClassPath) function MainCityUI:addSideBarCellComp(cellClassPath)
@ -280,6 +300,7 @@ function MainCityUI:addSideBarCellComp(cellClassPath)
prefabObject:initWithPrefab(GConst.EMPTY_STRING, prefab) prefabObject:initWithPrefab(GConst.EMPTY_STRING, prefab)
prefabObject:initPrefabHelper() prefabObject:initPrefabHelper()
prefabObject:genAllChildren() prefabObject:genAllChildren()
prefabObject:setName(cellClassPath)
return prefabObject:addLuaComponent(cellClassPath) return prefabObject:addLuaComponent(cellClassPath)
end end
@ -377,6 +398,7 @@ function MainCityUI:refreshRightBtns()
else else
for k, v in ipairs(self.rightBarList) do for k, v in ipairs(self.rightBarList) do
v:setAnchoredPositionY(y) v:setAnchoredPositionY(y)
v:setVisible(true)
v:refresh() v:refresh()
y = y - self.sideBarHeight - 2 y = y - self.sideBarHeight - 2
end end