c1_lua/lua/app/ui/fund/level_fund_ui.lua
2023-05-25 17:05:55 +08:00

203 lines
6.9 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_GOLD,
GConst.ItemConst.ITEM_ID_GEM,
GConst.ItemConst.ITEM_ID_VIT,
},
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.fundLevel = DataManager.FundData:getFundLevel()
self:initLevelInfoList()
end
function LevelFundUI:initLevelInfoList()
self.levelInfoList = DataManager.FundData:getCurrLevelInfoList()
local playerLevel = DataManager.PlayerData:getLv()
local cfg = ConfigManager:getConfig("act_level_fund")
self.inactiveIndex = nil
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 + 1
end
end
function LevelFundUI:onClose()
if self.originTitleBgHeight then
self.uiMap["level_fund_ui.title_img.bg"]:setSizeDeltaY(self.originTitleBgHeight)
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()
self:bindData()
end
function LevelFundUI:initTitle()
self.titleTx = self.uiMap["level_fund_ui.title_img.title_tx"]
self.titleDialogBg = self.uiMap["level_fund_ui.title_img.bg"]
self.originTitleBgHeight = self.titleDialogBg:fastGetSizeDeltaY()
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)
self.payBtn1 = self.uiMap["level_fund_ui.title_bg_2.btn_1"]
self.payBtn1:addClickListener(function()
ModuleManager.FundManager:buyLevelFund(DataManager.FundData:getFundBaseId())
end)
self.payBtnTx1 = self.uiMap["level_fund_ui.title_bg_2.btn_1.text"]
self.payBtn2 = self.uiMap["level_fund_ui.title_bg_2.btn_2"]
self.payBtn2:setAnchoredPositionX(width/3)
self.payBtn2:addClickListener(function()
ModuleManager.FundManager:buyLevelFund(DataManager.FundData:getFundAdvanceId())
end)
self.payBtnTx2 = self.uiMap["level_fund_ui.title_bg_2.btn_2.text"]
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.horizontalLine = 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:bindData()
self:bind(DataManager.FundData, "dirty", function()
if self.fundLevel ~= DataManager.FundData:getFundLevel() then
self.fundLevel = DataManager.FundData:getFundLevel()
self:initLevelInfoList()
end
self:onRefresh()
end)
end
function LevelFundUI:onRefresh()
self:refreshTitle()
self:refreshPayBtns()
self:refreshRewards()
end
function LevelFundUI:refreshTitle()
local fundLevel = DataManager.FundData:getFundLevel()
if fundLevel == 1 then
self.uiMap["level_fund_ui.title_img"]:setTexture("assets/arts/textures/background/fund/fund_bg_1.png")
elseif fundLevel == 2 then
self.uiMap["level_fund_ui.title_img"]:setTexture("assets/arts/textures/background/fund/fund_bg_2.png")
end
self.titleTx:setText(I18N:getGlobalText(I18N.GlobalConst.LEVEL_FUND_DESC_1, fundLevel))
local height = self.titleTx:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT_MESH_PRO).preferredHeight + 58
if height < self.originTitleBgHeight then
height = self.originTitleBgHeight
end
self.titleDialogBg:setSizeDeltaY(height)
end
function LevelFundUI:refreshPayBtns()
if not DataManager.FundData:getIsBoughtBase() then
local rechargeId = DataManager.FundData:getCurrLevelBaseRechargeId()
self.payBtnTx1:setText(GFunc.getFormatPrice(rechargeId))
self.payBtn1:setTouchEnable(true)
else
self.payBtnTx1:setText(I18N:getGlobalText(I18N.GlobalConst.ALREADY_ACTIVE))
self.payBtn1:setTouchEnable(false)
end
if not DataManager.FundData:getIsBoughtAdvance() then
local rechargeId = DataManager.FundData:getCurrLevelAdvanceRechargeId()
self.payBtnTx2:setText(GFunc.getFormatPrice(rechargeId))
self.payBtn2:setTouchEnable(true)
else
self.payBtnTx2:setText(I18N:getGlobalText(I18N.GlobalConst.ALREADY_ACTIVE))
self.payBtn2:setTouchEnable(false)
end
end
function LevelFundUI:refreshRewards()
local count = #self.levelInfoList
if self.scrollRectComp:getTotalCount() <= 0 then
self.scrollRectComp:refillCells(count)
local minIndex = DataManager.FundData:getMinUnclaimedRewardIndex()
if minIndex > 1 then
self.scrollRectComp:moveToIndex(minIndex)
end
elseif self.scrollRectComp:getTotalCount() ~= count then -- 打开界面的时候定位到当前可领取的最低等级奖励,如果没有则定位到当前等级
self.scrollRectComp:clearCells()
self.scrollRectComp:refillCells(count)
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)
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)
self.horizontalLine:setAnchoredPositionY(-topRecoveryOffset - (self.inactiveIndex - 1)*cellWidth)
end
return LevelFundUI