This commit is contained in:
xiekaidong 2023-06-05 16:24:22 +08:00
commit e3420eeb8a
3 changed files with 87 additions and 40 deletions

View File

@ -634,6 +634,13 @@ function UIPrefabObject:setClickAnimation(enable)
end end
end end
function UIPrefabObject:stopClickAnimation()
local eventListener = self:getComponent(BF_UI_TOUCH_EVENT)
if eventListener then
eventListener:StopTouchAnimation()
end
end
function UIPrefabObject:setTouchEnable(enable) function UIPrefabObject:setTouchEnable(enable)
local maskableGraphic = self:getComponent(UI_MASKABLE_GRAPHIC) local maskableGraphic = self:getComponent(UI_MASKABLE_GRAPHIC)
if maskableGraphic then if maskableGraphic then

View File

@ -1,5 +1,7 @@
local MainCityConst = {} local MainCityConst = {}
MainCityConst.SIDE_BAR_MIN_COUNT = 3
MainCityConst.BOTTOM_PAGE = { MainCityConst.BOTTOM_PAGE = {
MAIN = 1, MAIN = 1,
HERO = 2, HERO = 2,

View File

@ -440,20 +440,26 @@ function MainCityUI:refreshLeftBtns()
table.insert(self.leftBarList, cell) table.insert(self.leftBarList, cell)
end end
end end
if #self.leftBarList <= 0 then local sideBarShowCount = #self.leftBarList
if sideBarShowCount <= 0 then
self.leftNode:setAnchoredPositionX(GConst.NOT_VISIBLE_POS) self.leftNode:setAnchoredPositionX(GConst.NOT_VISIBLE_POS)
return return
end end
self.leftNode:setAnchoredPositionX(0) self.leftNode:setAnchoredPositionX(0)
local y = -SIDE_BAR_BORDER_OFFSET - self.sideBarHeight/2 local y = -SIDE_BAR_BORDER_OFFSET - self.sideBarHeight/2
if isClose then -- 只显示一个 if isClose then -- 只显示3个
local first = self.leftBarList[1] local minCount = GConst.MainCityConst.SIDE_BAR_MIN_COUNT
first:setAnchoredPositionY(y) for i = 1, minCount do
first:refresh() local sideBarBtn = self.leftBarList[i]
first:setActive(true) if i <= sideBarShowCount then
first:setVisible(true) sideBarBtn:setAnchoredPositionY(y)
sideBarBtn:refresh()
sideBarBtn:setActive(true)
sideBarBtn:setVisible(true)
y = y - self.sideBarHeight - SIDE_BAR_INTERVAL y = y - self.sideBarHeight - SIDE_BAR_INTERVAL
for i = 2, #self.leftBarList do end
end
for i = minCount + 1, sideBarShowCount do
self.leftBarList[i]:refresh() self.leftBarList[i]:refresh()
self.leftBarList[i]:setActive(true) self.leftBarList[i]:setActive(true)
self.leftBarList[i]:setVisible(false) self.leftBarList[i]:setVisible(false)
@ -467,12 +473,19 @@ function MainCityUI:refreshLeftBtns()
y = y - self.sideBarHeight - SIDE_BAR_INTERVAL y = y - self.sideBarHeight - SIDE_BAR_INTERVAL
end end
end end
if sideBarShowCount <= GConst.MainCityConst.SIDE_BAR_MIN_COUNT then -- 小于3个不显示箭头
y = y + self.sideBarHeight / 2
self.leftSideBar:setSizeDeltaY(-y)
self.leftArrowBtn:stopClickAnimation()
self.leftArrowBtn:setVisible(false)
else
local arrowHeight = self.leftArrowBtn:getRectHeight() local arrowHeight = self.leftArrowBtn:getRectHeight()
y = y + self.sideBarHeight/2 - SIDE_BAR_ARROW_INTERVAL - arrowHeight y = y + self.sideBarHeight/2 - SIDE_BAR_ARROW_INTERVAL - arrowHeight
self.leftSideBar:setSizeDeltaY(-y) self.leftSideBar:setSizeDeltaY(-y)
self.leftArrowImg:setLocalScale(1, isClose and -1 or 1, 1) self.leftArrowImg:setLocalScale(1, isClose and -1 or 1, 1)
self.leftArrowBtn:setAnchoredPositionY(self.leftSideBar:fastGetAnchoredPositionY() + y + arrowHeight/2 + SIDE_BAR_BORDER_OFFSET) self.leftArrowBtn:setAnchoredPositionY(self.leftSideBar:fastGetAnchoredPositionY() + y + arrowHeight/2 + SIDE_BAR_BORDER_OFFSET)
end end
end
function MainCityUI:openOrCloseRightSideBar() function MainCityUI:openOrCloseRightSideBar()
ModuleManager.MaincityManager:changeMainCityRightSideBarOpenOrClose() ModuleManager.MaincityManager:changeMainCityRightSideBarOpenOrClose()
@ -506,6 +519,7 @@ function MainCityUI:refreshRightBtns()
table.insert(self.rightBarList, cell) table.insert(self.rightBarList, cell)
end end
end end
local sideBarShowCount = #self.rightBarList
if #self.rightBarList <= 0 then if #self.rightBarList <= 0 then
self.rightNode:setAnchoredPositionX(GConst.NOT_VISIBLE_POS) self.rightNode:setAnchoredPositionX(GConst.NOT_VISIBLE_POS)
return return
@ -513,13 +527,18 @@ function MainCityUI:refreshRightBtns()
self.rightNode:setAnchoredPositionX(0) self.rightNode:setAnchoredPositionX(0)
local y = -SIDE_BAR_BORDER_OFFSET - self.sideBarHeight/2 local y = -SIDE_BAR_BORDER_OFFSET - self.sideBarHeight/2
if isClose then -- 只显示一个 if isClose then -- 只显示一个
local first = self.rightBarList[1] local minCount = GConst.MainCityConst.SIDE_BAR_MIN_COUNT
first:setAnchoredPositionY(y) for i = 1, minCount do
first:refresh() local sideBarBtn = self.rightBarList[i]
first:setActive(true) if i <= sideBarShowCount then
first:setVisible(true) sideBarBtn:setAnchoredPositionY(y)
sideBarBtn:refresh()
sideBarBtn:setActive(true)
sideBarBtn:setVisible(true)
y = y - self.sideBarHeight - SIDE_BAR_INTERVAL y = y - self.sideBarHeight - SIDE_BAR_INTERVAL
for i = 2, #self.rightBarList do end
end
for i = minCount + 1, sideBarShowCount do
self.rightBarList[i]:refresh() self.rightBarList[i]:refresh()
self.rightBarList[i]:setActive(true) self.rightBarList[i]:setActive(true)
self.rightBarList[i]:setVisible(false) self.rightBarList[i]:setVisible(false)
@ -533,12 +552,19 @@ function MainCityUI:refreshRightBtns()
y = y - self.sideBarHeight - SIDE_BAR_INTERVAL y = y - self.sideBarHeight - SIDE_BAR_INTERVAL
end end
end end
if sideBarShowCount <= GConst.MainCityConst.SIDE_BAR_MIN_COUNT then
y = y + self.sideBarHeight / 2
self.rightSideBar:setSizeDeltaY(-y)
self.rightArrowBtn:stopClickAnimation()
self.rightArrowBtn:setVisible(false)
else
local arrowHeight = self.rightArrowBtn:getRectHeight() local arrowHeight = self.rightArrowBtn:getRectHeight()
y = y + self.sideBarHeight / 2 - SIDE_BAR_ARROW_INTERVAL - arrowHeight y = y + self.sideBarHeight / 2 - SIDE_BAR_ARROW_INTERVAL - arrowHeight
self.rightSideBar:setSizeDeltaY(-y) self.rightSideBar:setSizeDeltaY(-y)
self.rightArrowImg:setLocalScale(1, isClose and -1 or 1, 1) self.rightArrowImg:setLocalScale(1, isClose and -1 or 1, 1)
self.rightArrowBtn:setAnchoredPositionY(self.rightSideBar:fastGetAnchoredPositionY() + y + arrowHeight/2 + SIDE_BAR_BORDER_OFFSET) self.rightArrowBtn:setAnchoredPositionY(self.rightSideBar:fastGetAnchoredPositionY() + y + arrowHeight/2 + SIDE_BAR_BORDER_OFFSET)
end end
end
function MainCityUI:clearSideBarList(sideBarList) function MainCityUI:clearSideBarList(sideBarList)
local count = #sideBarList local count = #sideBarList
@ -712,15 +738,21 @@ end
function MainCityUI:updateSideBarStatus() function MainCityUI:updateSideBarStatus()
if self.leftBarList then if self.leftBarList then
local first = self.leftBarList[1] local minCount = GConst.MainCityConst.SIDE_BAR_MIN_COUNT
if first then for i = 1, minCount do
if first:getIsShowRedPoint() then local sideBarBtn = self.leftBarList[i]
first:showRedPoint() if sideBarBtn then
if sideBarBtn:getIsShowRedPoint() then
sideBarBtn:showRedPoint()
else else
first:hideRedPoint() sideBarBtn:hideRedPoint()
end end
end
end
local sideBarCount = #self.leftBarList
if sideBarCount > minCount then
local count = 0 local count = 0
for i = 2, #self.leftBarList do for i = minCount + 1, sideBarCount do
if self.leftBarList[i]:getIsShowRedPoint() then if self.leftBarList[i]:getIsShowRedPoint() then
self.leftBarList[i]:showRedPoint() self.leftBarList[i]:showRedPoint()
count = count + 1 count = count + 1
@ -738,15 +770,21 @@ function MainCityUI:updateSideBarStatus()
end end
end end
if self.rightBarList then if self.rightBarList then
local first = self.rightBarList[1] local minCount = GConst.MainCityConst.SIDE_BAR_MIN_COUNT
if first then for i = 1, minCount do
if first:getIsShowRedPoint() then local sideBarBtn = self.rightBarList[i]
first:showRedPoint() if sideBarBtn then
if sideBarBtn:getIsShowRedPoint() then
sideBarBtn:showRedPoint()
else else
first:hideRedPoint() sideBarBtn:hideRedPoint()
end end
end
end
local sideBarCount = #self.rightBarList
if sideBarCount > minCount then
local count = 0 local count = 0
for i = 2, #self.rightBarList do for i = minCount + 1, sideBarCount do
if self.rightBarList[i]:getIsShowRedPoint() then if self.rightBarList[i]:getIsShowRedPoint() then
self.rightBarList[i]:showRedPoint() self.rightBarList[i]:showRedPoint()
count = count + 1 count = count + 1