战令定位

This commit is contained in:
chenxi 2023-05-17 11:14:07 +08:00
parent 4a162302ff
commit e07eb6a961
2 changed files with 86 additions and 36 deletions

View File

@ -29,6 +29,9 @@ function BountyMainUI:onClose()
self.autoRotateTween:Kill() self.autoRotateTween:Kill()
end end
self:clearPreviewRewardAnimation() self:clearPreviewRewardAnimation()
if self.rewardsContentMoveTween then
self.rewardsContentMoveTween:Kill()
end
end end
function BountyMainUI:onLoadRootComplete() function BountyMainUI:onLoadRootComplete()
@ -120,7 +123,6 @@ function BountyMainUI:initRewards()
self.scrollrectComp = self.scrollrect:addLuaComponent(GConst.TYPEOF_LUA_CLASS.SCROLL_RECT_BASE) self.scrollrectComp = self.scrollrect:addLuaComponent(GConst.TYPEOF_LUA_CLASS.SCROLL_RECT_BASE)
self.scrollrectComp:clearCells() self.scrollrectComp:clearCells()
self.scrollrectComp:setTotalCount(0) self.scrollrectComp:setTotalCount(0)
self.scrollrectComp:setFadeArgs(0, 0.3)
self.scrollrectComp:addInitCallback(function() self.scrollrectComp:addInitCallback(function()
return "app/ui/bounty/cell/bounty_cell" return "app/ui/bounty/cell/bounty_cell"
end) end)
@ -136,6 +138,7 @@ function BountyMainUI:initRewards()
self.refreshIndex = index self.refreshIndex = index
local totalCount = self.scrollrectComp:getTotalCount() local totalCount = self.scrollrectComp:getTotalCount()
local isFinalCell = index == totalCount local isFinalCell = index == totalCount
if not self.disablePreviewReward then
if isFinalCell then if isFinalCell then
self.rewardCellIdx = index self.rewardCellIdx = index
self:hidePreviewReward() self:hidePreviewReward()
@ -148,6 +151,7 @@ function BountyMainUI:initRewards()
self:showNextPreviewReward() self:showNextPreviewReward()
end end
end end
end
cell:refresh(index, isFinalCell) cell:refresh(index, isFinalCell)
local lv = DataManager.BountyData:getLevel() local lv = DataManager.BountyData:getLevel()
if index > lv - 1 or index < lv + 1 then if index > lv - 1 or index < lv + 1 then
@ -160,7 +164,7 @@ function BountyMainUI:initRewards()
end end
self.repeatRewardRoot:getTransform():SetAsLastSibling() self.repeatRewardRoot:getTransform():SetAsLastSibling()
end) end)
self.cellHeight = 200 self.cellHeight = self.uiMap["bounty_main_ui.mid_node.scrollrect.viewport.content.cell"]:getRectHeight()
local scrollBottom = 106 local scrollBottom = 106
local scrollTop = 464 local scrollTop = 464
local height = self.root:getRectHeight() local height = self.root:getRectHeight()
@ -264,10 +268,16 @@ function BountyMainUI:refreshRewards()
end end
local maxLv = DataManager.BountyData:getMaxLevel() local maxLv = DataManager.BountyData:getMaxLevel()
local lv = DataManager.BountyData:getLevel() local lv = DataManager.BountyData:getLevel()
if self.scrollrectComp:getTotalCount() <= 0 then if self.scrollrectComp:getTotalCount() <= 0 then -- 打开界面的时候定位到当前可领取的最低等级奖励,如果没有则定位到当前等级
self.scrollrectComp:refillCells(maxLv) self.scrollrectComp:refillCells(maxLv)
local level = DataManager.BountyData:getMinUnclaimedRewardIndex()
if level > 1 then
self:scrollToIndex(level)
end
else else
self.disablePreviewReward = true
self.scrollrectComp:updateAllCell() self.scrollrectComp:updateAllCell()
self.disablePreviewReward = false
end end
if lv >= maxLv then if lv >= maxLv then
self.line:setVisible(false) self.line:setVisible(false)
@ -372,33 +382,47 @@ function BountyMainUI:clearPreviewRewardAnimation()
end end
function BountyMainUI:scrollToIndex(targetIndex) function BountyMainUI:scrollToIndex(targetIndex)
-- 未避免scrollrect没填充完毕延迟一帧执行
if self.rewardsContentSid then
self:unscheduleGlobal(self.rewardsContentSid)
end
self.rewardsContentSid = self:performWithDelayGlobal(function()
self.rewardsContentSid = nil
if self.rewardsContentMaxY == nil then
local maxLv = DataManager.BountyData:getMaxLevel() local maxLv = DataManager.BountyData:getMaxLevel()
local cellHeight = self.cellHeight self.rewardsContentMaxY = maxLv*self.cellHeight - self.scrollrectViewport:getRectHeight()
local cellListHeight = self.scrollView:getTransform().rect.height
local posY = cellHeight*(targetIndex - 6)
local targetPosY = cellHeight*(targetIndex - 1)
targetPosY = math.min(targetPosY, maxLv*cellHeight - cellListHeight)
if self.scrollSid then
self:unscheduleGlobal(self.scrollSid)
self.scrollSid = nil
end end
if targetIndex <= 6 then -- 最多移动6格,超过6格就先整体移动后再移动6格
self.scrollrectComp:moveToIndex(targetIndex) local moveTimePerCell = 0.05
local moveCount = 6
local moveTime = moveCount * moveTimePerCell
if targetIndex > 7 then
local tartgetY = (targetIndex - 7)*self.cellHeight
if tartgetY > self.rewardsContentMaxY then
self.rewardsContent:setAnchoredPositionY(self.rewardsContentMaxY)
return
else else
self.scrollrectComp:moveToIndex(targetIndex - 6) self.rewardsContent:setAnchoredPositionY(tartgetY)
self.scrollSid = self:scheduleGlobal(function(inter)
posY = posY + 40*inter/0.015
if posY >= targetPosY then
posY = targetPosY
end end
self.rewardsContent:setAnchoredPositionY(posY) else
if posY >= targetPosY then moveTime = (targetIndex - 1) * moveTimePerCell
self:unscheduleGlobal(self.scrollSid) end
self.scrollSid = nil local y = (targetIndex - 1) * self.cellHeight
if y > self.rewardsContentMaxY then
y = self.rewardsContentMaxY
end
if self.rewardsContentMoveTween == nil then
self.rewardsContentMoveTween = self.rewardsContent:getTransform():DOAnchorPosY(y, moveTime)
self.rewardsContentMoveTween:SetAutoKill(false)
else
local CacheVector2 = BF.CacheVector2
CacheVector2.x = 0
CacheVector2.y = y
self.rewardsContentMoveTween:ChangeEndValue(CacheVector2, moveTime, true)
self.rewardsContentMoveTween:Restart()
end end
end, 0) end, 0)
end end
end
function BountyMainUI:updateTime() function BountyMainUI:updateTime()
local remainTime = self.endTime - Time:getServerTime() local remainTime = self.endTime - Time:getServerTime()

View File

@ -178,6 +178,31 @@ function BountyData:getIfCanBuyLevel()
return false return false
end end
-- 未领取的最小奖励的index
function BountyData:getMinUnclaimedRewardIndex()
local level = self.level
local maxLevel = self:getMaxLevel()
if level > maxLevel then
level = maxLevel
end
if self.claimedCount < self.level then
for i = 1, level do
if not self.claimed[i] then
return i
end
end
end
if self.bought and self.proClaimedCount < self:getMaxLevel() then
for i = 1, level do
if not self.proClaimed[i] then
return i
end
end
end
return level
end
-- 是否有未领取的奖励
function BountyData:getIfCanClaimReward() function BountyData:getIfCanClaimReward()
if not self:getIsOpen() then if not self:getIsOpen() then
return false return false
@ -191,6 +216,7 @@ function BountyData:getIfCanClaimReward()
return false return false
end end
-- 是否可以领取重复奖励
function BountyData:getIfCanClaimRepeatReward() function BountyData:getIfCanClaimRepeatReward()
local maxLevel = self:getMaxLevel() local maxLevel = self:getMaxLevel()
if maxLevel <= 0 then if maxLevel <= 0 then