c1_lua/lua/app/ui/fund/level_fund_ui.lua
2023-05-24 19:19:34 +08:00

149 lines
5.1 KiB
Lua

local LevelFundUI = class("LevelFundUI", BaseUI)
function LevelFundUI:isFullScreen()
return true
end
function LevelFundUI:getCurrencyParams()
if self.currencyParams == nil then
self.currencyParams = {
itemIds = {
GConst.ItemConst.ITEM_ID_VIT,
GConst.ItemConst.ITEM_ID_GOLD,
GConst.ItemConst.ITEM_ID_GEM
},
showType = GConst.CURRENCY_TYPE.HORIZONTAL
}
end
return self.currencyParams
end
function LevelFundUI:getPrefabPath()
return "assets/prefabs/ui/fund/level_fund_ui.prefab"
end
function LevelFundUI:ctor()
self.levelInfoList = DataManager.FundData:getCurrLevelInfoList()
local playerLevel = DataManager.PlayerData:getLv()
local cfg = ConfigManager:getConfig("act_level_fund")
for k, v in ipairs(self.levelInfoList) do
if cfg[v] then
if playerLevel < cfg[v].level then
self.inactiveIndex = k
break
end
end
end
if self.inactiveIndex == nil then
self.inactiveIndex = #self.levelInfoList
end
end
function LevelFundUI:onLoadRootComplete()
self.uiMap = self.root:genAllChildren()
self.uiMap["level_fund_ui.down.close_btn"]:addClickListener(function()
self:closeUI()
end)
self:initTitle()
self:initPayBtns()
self:initRewards()
end
function LevelFundUI:initTitle()
self.uiMap["level_fund_ui.title_img.title_tx"]:setText("临时文本:购买成长基金后,可通过提升等级获得钻石,多档基金可同时购买")
end
function LevelFundUI:initPayBtns()
local width = GConst.UI_SCREEN_WIDTH
local freeTx = self.uiMap["level_fund_ui.title_bg_2.free_tx"]
freeTx:setText(I18N:getGlobalText(I18N.GlobalConst.STR_FREE))
freeTx:setAnchoredPositionX(-width/3)
local payBtn1 = self.uiMap["level_fund_ui.title_bg_2.btn_1"]
payBtn1:addClickListener(function()
end)
if not DataManager.FundData:getIsBoughtBase() then
local rechargeId = DataManager.FundData:getCurrLevelBaseRechargeId()
self.uiMap["level_fund_ui.title_bg_2.btn_1.text"]:setText(GFunc.getFormatPrice(rechargeId))
else
self.uiMap["level_fund_ui.title_bg_2.btn_1.text"]:setText(I18N:getGlobalText(I18N.GlobalConst.ALREADY_ACTIVE))
end
local payBtn2 = self.uiMap["level_fund_ui.title_bg_2.btn_2"]
payBtn2:setAnchoredPositionX(width/3)
payBtn2:addClickListener(function()
end)
if not DataManager.FundData:getIsBoughtAdvance() then
local rechargeId = DataManager.FundData:getCurrLevelAdvanceRechargeId()
self.uiMap["level_fund_ui.title_bg_2.btn_2.text"]:setText(GFunc.getFormatPrice(rechargeId))
else
self.uiMap["level_fund_ui.title_bg_2.btn_2.text"]:setText(I18N:getGlobalText(I18N.GlobalConst.ALREADY_ACTIVE))
end
end
function LevelFundUI:initRewards()
self.scrollRect = self.uiMap["level_fund_ui.scrollrect"]
self.scrollRectComp = self.scrollRect:addLuaComponent(GConst.TYPEOF_LUA_CLASS.SCROLL_RECT_BASE)
self.scrollRectComp:addInitCallback(function()
return "app/ui/fund/cell/level_fund_cell"
end)
self.scrollRectComp:addRefreshCallback(function(index, cell)
cell:refresh(self.levelInfoList[index])
end)
self.scrollRectComp:clearCells()
self.scrollRectComp:setTotalCount(0)
self.progressBg = self.uiMap["level_fund_ui.scrollrect.viewport.content.progress_bg"]
self.progressComp = self.uiMap["level_fund_ui.scrollrect.viewport.content.progress_bg.progress"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER)
self.grayImg = self.uiMap["level_fund_ui.scrollrect.viewport.content.gray_img"]
self.lineImg = self.uiMap["level_fund_ui.scrollrect.viewport.content.line_img"]
self.verticalLine1 = self.uiMap["level_fund_ui.scrollrect.viewport.content.vertical_line_1"]
self.verticalLine2 = self.uiMap["level_fund_ui.scrollrect.viewport.content.vertical_line_2"]
end
function LevelFundUI:onRefresh()
self:refreshRewards()
end
function LevelFundUI:refreshRewards()
local count = #self.levelInfoList
if self.scrollRectComp:getTotalCount() ~= count then -- 打开界面的时候定位到当前可领取的最低等级奖励,如果没有则定位到当前等级
self.scrollRectComp:clearCells()
self.scrollRectComp:refillCells(count)
-- local level = DataManager.BountyData:getMinUnclaimedRewardIndex()
-- if level > 1 then
-- self:scrollToIndex(level)
-- end
else
self.scrollRectComp:updateAllCell()
end
local topRecoveryOffset = self.scrollRectComp:getTopRecoveryOffset()
local contentWidth = self.scrollRect:getRectWidth()
local cellWidth = self.scrollRectComp:getCellHeight()
self.progressBg:setAnchoredPosition(contentWidth/3, -topRecoveryOffset - cellWidth/2)
self.progressBg:setSizeDeltaX(cellWidth*(count - 1))
local percent = (self.inactiveIndex - 2) / (count - 1)
if percent < 0 then
percent = 0
end
self.progressComp.value = percent
self.grayImg:setAnchoredPositionY(-topRecoveryOffset - (self.inactiveIndex - 1)*cellWidth)
self.grayImg:setSizeDeltaY(cellWidth*count + GConst.UI_SCREEN_HEIGHT)
self.lineImg:setAnchoredPositionY(-topRecoveryOffset - (self.inactiveIndex - 1)*cellWidth)
local lineHeight = topRecoveryOffset + cellWidth*count + GConst.UI_SCREEN_HEIGHT*2
self.verticalLine1:setAnchoredPositionX(contentWidth/3)
self.verticalLine1:setSizeDeltaY(lineHeight)
self.verticalLine2:setAnchoredPositionX(contentWidth*2/3)
self.verticalLine2:setSizeDeltaY(lineHeight)
end
return LevelFundUI