local BountyMainUI = class("BountyMainUI", BaseUI) function BountyMainUI:getPrefabPath() return "assets/prefabs/ui/bounty/bounty_main_ui.prefab" end function BountyMainUI:ctor() self.maxCellIdx = 0 self.maxCellNum = 0 -- 默认预览第10档奖励 self.previewRewardIndex = 10 end function BountyMainUI:onLoadRootComplete() local uiMap = self.root:genAllChildren() self.uiMap = uiMap local closeBtn = uiMap["bounty_main_ui.bottom_node.clost_btn"] closeBtn:addClickListener(function() self:closeUI() end) self:initPayBtn() self:initPreviewReward() self:initRewards() self:bindData() self:scheduleGlobal(function() self:updateTime() end, 1) self:updateTime() end function BountyMainUI:initPayBtn() self.payBtn = self.uiMap["bounty_main_ui.top_node.buy_btn"] self.payBtnTx = self.uiMap["bounty_main_ui.top_node.buy_btn.tx"] self.payBtn:addClickListener(function() ModuleManager.BountyManager:showBountyBuyUI() end) end function BountyMainUI:initPreviewReward() self.previewReward = self.uiMap["bounty_main_ui.mid_node.preview"] self.previewRewardCellComp = self.uiMap["bounty_main_ui.mid_node.preview.bg.reward_cell"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.REWARD_CELL) self.uiMap["bounty_main_ui.mid_node.preview.bg"]:addClickListener(function() if not self.inPreviewRewardAction then self:scrollToIndex(self.previewRewardIndex) end end) end function BountyMainUI:initRewards() self.line = self.uiMap["bounty_main_ui.mid_node.scrollrect.viewport.content.line"] self.buyLevelBtn = self.uiMap["bounty_main_ui.mid_node.scrollrect.viewport.content.line.btn"] self.buyLevelBtn:addClickListener(function() ModuleManager.BountyManager:buyBountyLevel() end) self.scrollrect = self.uiMap["bounty_main_ui.mid_node.scrollrect"] self.rewardsContent = self.uiMap["bounty_main_ui.mid_node.scrollrect.viewport.content"] 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_reward_cell" end) self.scrollrectComp:addRefreshCallback(function(index, cell) if index > self.maxCellIdx then self.maxCellIdx = index self:showLevelNextCell() elseif index < self.maxCellIdx - self.maxCellNum then self.maxCellIdx = index + self.maxCellNum self:showLevelNextCell() end local lv = DataManager.BountyData:getLevel() if index > lv - 1 or index < lv + 1 then self.line:getTransform():SetAsLastSibling() end cell:refresh(index) end) self.cellHeight = self.scrollrectComp:getCellHeight() local scrollBottom = 114 local scrollTop = 416 local height = self.root:getRectHeight() height = height - scrollTop - scrollBottom self.maxCellNum = math.ceil(height/self.cellHeight) self.scrollrect:setOffsetMin(-scrollTop, scrollBottom) self.scrollrect:setSizeDeltaX(1280) self.scrollrect:setAnchoredPosition(0, -scrollTop) end function BountyMainUI:bindData() self:bind(DataManager.BountyData, "dirty", function() self:onRefresh() end) end function BountyMainUI:onRefresh() self:refreshPayBtn() self:refreshPreviewReward(self.previewRewardIndex) self:refreshRewards() end function BountyMainUI:refreshPayBtn() if DataManager.BountyData:getBought() then self.payBtn:setTouchEnable(false) self.payBtnTx:setText("临时文本:已激活") else self.payBtn:setTouchEnable(true) self.payBtnTx:setText("临时文本:激活黄金通行证") end end function BountyMainUI:refreshPreviewReward(idx) local info = DataManager.BountyData:getSeasonInfoByLevel(idx) if info == nil then return end self.previewRewardCellComp:refreshByConfig(info.reward_pro) end function BountyMainUI:refreshRewards() local maxLv = DataManager.BountyData:getMaxLevel() local lv = DataManager.BountyData:getLevel() if self.scrollrectComp:getTotalCount() <= 0 then self.scrollrectComp:refillCells(maxLv) else self.scrollrectComp:updateAllCell() end if lv >= maxLv then self.line:setVisible(false) else self.line:setVisible(true) local posY = (maxLv - lv)*self.cellHeight self.line:setAnchoredPosition(640, posY + 5) end end function BountyMainUI:showLevelNextCell() -- local minIdx = self.maxCellIdx -- local showMyCell = -1 -- for i = minIdx, minIdx + 10 do -- local cfg = DataManager.BountyData:getSeasonCfgByLevel(i) -- if cfg and cfg.reward_type and cfg.reward_type == 1 then -- showMyCell = i -- break -- end -- end -- if self.previewRewardIndex == showMyCell then -- return -- end -- self.previewRewardIndex = showMyCell -- if showMyCell <= 0 then -- self.rewardMyCellComp3:setVisible(false) -- self.rewardMyCell3:setAnchoredPositionY(0) -- else -- self.rewardMyCellComp3:setVisible(true) -- self:showMyCellAction() -- end end function BountyMainUI:showMyCellAction() -- self.inPreviewRewardAction = true -- if self.rewardMyCell3.aniSeq then -- self.rewardMyCell3.aniSeq:Kill() -- end -- local time = 0.3 -- local maxY = 134 -- local posY = self.rewardMyCell3:getAnchoredPositionY() -- local aniSeq = self.rewardMyCell3:createBindTweenSequence() -- if posY > 0 then -- aniSeq:Append(self.rewardMyCell3:getTransform():DOAnchorPosY(0, time/maxY*posY):SetEase(CS.DG.Tweening.Ease.InCubic)) -- end -- aniSeq:AppendCallback(function() -- if self.previewRewardIndex > 0 then -- self.rewardMyCellComp3:refresh(self.previewRewardIndex) -- end -- end) -- aniSeq:Append(self.rewardMyCell3:getTransform():DOAnchorPosY(maxY, time):SetEase(CS.DG.Tweening.Ease.InCubic)) -- aniSeq:AppendCallback(function() -- self.inPreviewRewardAction = false -- end) -- self.rewardMyCell3.aniSeq = aniSeq 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 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 end self.rewardsContent:setAnchoredPositionY(posY) if posY >= targetPosY then self:unscheduleGlobal(self.scrollSid) self.scrollSid = nil end end, 0) end end function BountyMainUI:updateTime() end return BountyMainUI