From e07eb6a9619131ea7c80f4ea50f5e5edd5adecef Mon Sep 17 00:00:00 2001 From: chenxi Date: Wed, 17 May 2023 11:14:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=98=E4=BB=A4=E5=AE=9A=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/app/ui/bounty/bounty_main_ui.lua | 96 +++++++++++++++---------- lua/app/userdata/bounty/bounty_data.lua | 26 +++++++ 2 files changed, 86 insertions(+), 36 deletions(-) diff --git a/lua/app/ui/bounty/bounty_main_ui.lua b/lua/app/ui/bounty/bounty_main_ui.lua index 67027007..e3e8f5c1 100644 --- a/lua/app/ui/bounty/bounty_main_ui.lua +++ b/lua/app/ui/bounty/bounty_main_ui.lua @@ -29,6 +29,9 @@ function BountyMainUI:onClose() self.autoRotateTween:Kill() end self:clearPreviewRewardAnimation() + if self.rewardsContentMoveTween then + self.rewardsContentMoveTween:Kill() + end end function BountyMainUI:onLoadRootComplete() @@ -120,7 +123,6 @@ function BountyMainUI:initRewards() self.scrollrectComp = self.scrollrect:addLuaComponent(GConst.TYPEOF_LUA_CLASS.SCROLL_RECT_BASE) self.scrollrectComp:clearCells() self.scrollrectComp:setTotalCount(0) - self.scrollrectComp:setFadeArgs(0, 0.3) self.scrollrectComp:addInitCallback(function() return "app/ui/bounty/cell/bounty_cell" end) @@ -136,16 +138,18 @@ function BountyMainUI:initRewards() self.refreshIndex = index local totalCount = self.scrollrectComp:getTotalCount() local isFinalCell = index == totalCount - if isFinalCell then - self.rewardCellIdx = index - self:hidePreviewReward() - else - if index > self.rewardCellIdx then + if not self.disablePreviewReward then + if isFinalCell then self.rewardCellIdx = index - self:showNextPreviewReward() - elseif index < self.rewardCellIdx - self.rewardCellNum then - self.rewardCellIdx = index + self.rewardCellNum - self:showNextPreviewReward() + self:hidePreviewReward() + else + if index > self.rewardCellIdx then + self.rewardCellIdx = index + self:showNextPreviewReward() + elseif index < self.rewardCellIdx - self.rewardCellNum then + self.rewardCellIdx = index + self.rewardCellNum + self:showNextPreviewReward() + end end end cell:refresh(index, isFinalCell) @@ -160,7 +164,7 @@ function BountyMainUI:initRewards() end self.repeatRewardRoot:getTransform():SetAsLastSibling() end) - self.cellHeight = 200 + self.cellHeight = self.uiMap["bounty_main_ui.mid_node.scrollrect.viewport.content.cell"]:getRectHeight() local scrollBottom = 106 local scrollTop = 464 local height = self.root:getRectHeight() @@ -264,10 +268,16 @@ function BountyMainUI:refreshRewards() end local maxLv = DataManager.BountyData:getMaxLevel() local lv = DataManager.BountyData:getLevel() - if self.scrollrectComp:getTotalCount() <= 0 then + if self.scrollrectComp:getTotalCount() <= 0 then -- 打开界面的时候定位到当前可领取的最低等级奖励,如果没有则定位到当前等级 self.scrollrectComp:refillCells(maxLv) + local level = DataManager.BountyData:getMinUnclaimedRewardIndex() + if level > 1 then + self:scrollToIndex(level) + end else + self.disablePreviewReward = true self.scrollrectComp:updateAllCell() + self.disablePreviewReward = false end if lv >= maxLv then self.line:setVisible(false) @@ -372,32 +382,46 @@ function BountyMainUI:clearPreviewRewardAnimation() end function BountyMainUI:scrollToIndex(targetIndex) - local maxLv = DataManager.BountyData:getMaxLevel() - local cellHeight = self.cellHeight - 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 + -- 未避免scrollrect没填充完毕,延迟一帧执行 + if self.rewardsContentSid then + self:unscheduleGlobal(self.rewardsContentSid) end - if targetIndex <= 6 then - self.scrollrectComp:moveToIndex(targetIndex) - else - self.scrollrectComp:moveToIndex(targetIndex - 6) - self.scrollSid = self:scheduleGlobal(function(inter) - posY = posY + 40*inter/0.015 - if posY >= targetPosY then - posY = targetPosY + self.rewardsContentSid = self:performWithDelayGlobal(function() + self.rewardsContentSid = nil + if self.rewardsContentMaxY == nil then + local maxLv = DataManager.BountyData:getMaxLevel() + self.rewardsContentMaxY = maxLv*self.cellHeight - self.scrollrectViewport:getRectHeight() + end + -- 最多移动6格,超过6格就先整体移动后再移动6格 + 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 + self.rewardsContent:setAnchoredPositionY(tartgetY) end - self.rewardsContent:setAnchoredPositionY(posY) - if posY >= targetPosY then - self:unscheduleGlobal(self.scrollSid) - self.scrollSid = nil - end - end, 0) - end + else + moveTime = (targetIndex - 1) * moveTimePerCell + end + 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, 0) end function BountyMainUI:updateTime() diff --git a/lua/app/userdata/bounty/bounty_data.lua b/lua/app/userdata/bounty/bounty_data.lua index 8fce3abe..b7db7ce6 100644 --- a/lua/app/userdata/bounty/bounty_data.lua +++ b/lua/app/userdata/bounty/bounty_data.lua @@ -178,6 +178,31 @@ function BountyData:getIfCanBuyLevel() return false 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() if not self:getIsOpen() then return false @@ -191,6 +216,7 @@ function BountyData:getIfCanClaimReward() return false end +-- 是否可以领取重复奖励 function BountyData:getIfCanClaimRepeatReward() local maxLevel = self:getMaxLevel() if maxLevel <= 0 then