319 lines
11 KiB
Lua
319 lines
11 KiB
Lua
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:onClose()
|
|
self:clearAdaptScrollrect()
|
|
end
|
|
|
|
function BountyMainUI:onLoadRootComplete()
|
|
local uiMap = self.root:genAllChildren()
|
|
self.uiMap = uiMap
|
|
local closeBtn = uiMap["bounty_main_ui.bottom_node.close_btn"]
|
|
closeBtn:addClickListener(function()
|
|
self:closeUI()
|
|
end)
|
|
|
|
self:initTime()
|
|
self:initLevel()
|
|
self:initPayBtn()
|
|
self:initPreviewReward()
|
|
self:initRewards()
|
|
|
|
self:bindData()
|
|
self:scheduleGlobal(function()
|
|
self:updateTime()
|
|
end, 1)
|
|
self:updateTime()
|
|
end
|
|
|
|
function BountyMainUI:initTime()
|
|
self.timeIcon = self.uiMap["bounty_main_ui.top_node.time_icon"]
|
|
self.timeTx = self.uiMap["bounty_main_ui.top_node.time_tx"]
|
|
self.timeTx:setText(GConst.EMPTY_STRING)
|
|
self.adjustTimeUI = false
|
|
end
|
|
|
|
function BountyMainUI:initLevel()
|
|
self.levelSlider = self.uiMap["bounty_main_ui.top_node.progress_bg.slider"]
|
|
self.levelItemImg = self.uiMap["bounty_main_ui.top_node.progress_bg.item_img"]
|
|
self.levelSliderTx = self.uiMap["bounty_main_ui.top_node.progress_bg.slider_tx"]
|
|
self.lvTx = self.uiMap["bounty_main_ui.top_node.progress_bg.lv_img.lv_tx"]
|
|
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.adjustRewardsTitleUI = false
|
|
local rewardsLeftTitle = self.uiMap["bounty_main_ui.top_node.left"]
|
|
rewardsLeftTitle:setAnchoredPositionX(-GConst.UI_SCREEN_WIDTH/4)
|
|
self.rewardsLeftTitleIcon = self.uiMap["bounty_main_ui.top_node.left.icon"]
|
|
self.rewardsLeftTitleTx = self.uiMap["bounty_main_ui.top_node.left.text"]
|
|
local rewardsRightTitle = self.uiMap["bounty_main_ui.top_node.right"]
|
|
rewardsRightTitle:setAnchoredPositionX(GConst.UI_SCREEN_WIDTH/4)
|
|
self.rewardsRightTitleIcon = self.uiMap["bounty_main_ui.top_node.right.icon"]
|
|
self.rewardsRightTitleTx = self.uiMap["bounty_main_ui.top_node.right.text"]
|
|
|
|
self.line = self.uiMap["bounty_main_ui.mid_node.scrollrect.viewport.content.line"]
|
|
local buyLevelItemIcon = self.uiMap["bounty_main_ui.mid_node.scrollrect.viewport.content.line.btn.item"]
|
|
local buyLevelItemTx = self.uiMap["bounty_main_ui.mid_node.scrollrect.viewport.content.line.btn.tx"]
|
|
local cost = DataManager.BountyData:getBuyBountyLevelCost()
|
|
local costId = GFunc.getRewardId(cost)
|
|
local info = ConfigManager:getConfig("item")[costId]
|
|
if info then
|
|
buyLevelItemIcon:setSprite(GConst.ATLAS_PATH.ICON_ITEM, info.icon)
|
|
end
|
|
local costNum = GFunc.getRewardNum(cost)
|
|
buyLevelItemTx:setText(tostring(costNum))
|
|
GFunc.centerImgAndTx(buyLevelItemIcon, buyLevelItemTx)
|
|
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.scrollrectViewport = self.uiMap["bounty_main_ui.mid_node.scrollrect.viewport"]
|
|
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_cell"
|
|
end)
|
|
self.scrollrectComp:addRefreshCallback(function(index, cell)
|
|
-- TODO 有时候顺序还是不对
|
|
if self.refreshIndex then
|
|
if index > self.refreshIndex then
|
|
cell:getBaseObject():getTransform():SetAsLastSibling()
|
|
elseif index < self.refreshIndex then
|
|
cell:getBaseObject():getTransform():SetAsFirstSibling()
|
|
end
|
|
end
|
|
self.refreshIndex = index
|
|
|
|
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, index == self.scrollrectComp:getTotalCount())
|
|
end)
|
|
self.cellHeight = 200
|
|
local scrollBottom = 106
|
|
local scrollTop = 464
|
|
local height = self.root:getRectHeight()
|
|
height = height - scrollTop - scrollBottom
|
|
self.maxCellNum = math.ceil(height/self.cellHeight)
|
|
self:adaptScrollrect()
|
|
end
|
|
|
|
function BountyMainUI:adaptScrollrect()
|
|
if not self.rectDefaultSize then
|
|
self.rectDefaultSize = self.scrollrect:getSizeDelta()
|
|
end
|
|
if not self.viewDefaultSize then
|
|
self.viewDefaultSize = self.scrollrectViewport:getSizeDelta()
|
|
end
|
|
local addH = GFunc.calculateFitSizeY()
|
|
self.scrollrect:setSizeDelta(self.rectDefaultSize.x, self.rectDefaultSize.y + addH)
|
|
self.scrollrectViewport:setSizeDelta(self.viewDefaultSize.x, self.viewDefaultSize.y + addH)
|
|
end
|
|
|
|
function BountyMainUI:clearAdaptScrollrect()
|
|
if not self.rectDefaultSize then
|
|
return
|
|
end
|
|
self.scrollrect:setSizeDelta(self.rectDefaultSize.x, self.rectDefaultSize.y)
|
|
self.scrollrectViewport:setSizeDelta(self.viewDefaultSize.x, self.viewDefaultSize.y)
|
|
end
|
|
|
|
function BountyMainUI:bindData()
|
|
self:bind(DataManager.BountyData, "dirty", function()
|
|
self:onRefresh()
|
|
end)
|
|
end
|
|
|
|
function BountyMainUI:onRefresh()
|
|
self:refreshLv()
|
|
self:refreshPayBtn()
|
|
self:refreshPreviewReward(self.previewRewardIndex)
|
|
self:refreshRewards()
|
|
end
|
|
|
|
function BountyMainUI:refreshLv()
|
|
local exp = DataManager.BountyData:getExp()
|
|
local lvUpExp = DataManager.BountyData:getLvUpExp()
|
|
local level = DataManager.BountyData:getLevel()
|
|
self.levelSliderTx:setText(exp .. "/" .. lvUpExp)
|
|
self.levelSlider:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER).value = exp / lvUpExp
|
|
self.lvTx:setText(tostring(level))
|
|
local expItemIcon = DataManager.BountyData:getExpItemIcon()
|
|
self.levelItemImg:setSprite(GConst.ATLAS_PATH.ICON_ITEM, expItemIcon)
|
|
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()
|
|
self.rewardsLeftTitleTx:setText("临时文本:免费通行证")
|
|
self.rewardsRightTitleTx:setText("临时文本:黄金通行证")
|
|
if not self.adjustRewardsTitleUI then
|
|
self.adjustRewardsTitleUI = true
|
|
GFunc.centerImgAndTx(self.rewardsLeftTitleIcon, self.rewardsLeftTitleTx)
|
|
GFunc.centerImgAndTx(self.rewardsRightTitleIcon, self.rewardsRightTitleTx)
|
|
end
|
|
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 = -lv*self.cellHeight
|
|
self.line:setAnchoredPositionY(posY)
|
|
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()
|
|
local remainTime = DataManager.BountyData:getRemainTime()
|
|
if remainTime < 0 then
|
|
UIManager:closeUnderUI(self)
|
|
return self:closeUI()
|
|
end
|
|
self.timeTx:setText(GFunc.getTimeStr(remainTime))
|
|
if not self.adjustTimeUI then
|
|
self.adjustTimeUI = true
|
|
GFunc.centerImgAndTx(self.timeIcon, self.timeTx)
|
|
end
|
|
end
|
|
|
|
return BountyMainUI |