c1_lua/lua/app/ui/privilege/monthly_card_ui.lua
2025-10-08 16:02:30 +08:00

227 lines
9.8 KiB
Lua

local MonthlyCardUI = class("MonthlyCardUI", BaseUI)
local IMG_BANNER = {
[GConst.MonthlyCardConst.CARD_TYPE.CARD_1] = "monthlycard_banner_2",
[GConst.MonthlyCardConst.CARD_TYPE.CARD_2] = "monthlycard_banner_1",
}
local IMG_TITLE = {
[GConst.MonthlyCardConst.CARD_TYPE.CARD_1] = "monthlycard_tattle_2",
[GConst.MonthlyCardConst.CARD_TYPE.CARD_2] = "monthlycard_tattle_1",
}
local TX_TITLE = {
[GConst.MonthlyCardConst.CARD_TYPE.CARD_1] = "MONTHLY_CARD_2",
[GConst.MonthlyCardConst.CARD_TYPE.CARD_2] = "MONTHLY_CARD_3",
}
local IMG_OFF = {
[GConst.MonthlyCardConst.CARD_TYPE.CARD_1] = "monthlycard_bg_4",
[GConst.MonthlyCardConst.CARD_TYPE.CARD_2] = "monthlycard_bg_3",
}
local IMG_SHOW = {
[GConst.MonthlyCardConst.CARD_TYPE.CARD_1] = {"monthlycard_dec_2" , "monthlycard_dec_3"},
[GConst.MonthlyCardConst.CARD_TYPE.CARD_2] = {"monthlycard_dec_4"},
}
local TX_SHOW = {
[GConst.MonthlyCardConst.CARD_TYPE.CARD_1] = {"MONTHLY_CARD_20" , "MONTHLY_CARD_DESC_1_1"},
[GConst.MonthlyCardConst.CARD_TYPE.CARD_2] = {"MONTHLY_CARD_2"},
}
function MonthlyCardUI:isFullScreen()
return false
end
function MonthlyCardUI:showCommonBG()
return false
end
function MonthlyCardUI:getPrefabPath()
return "assets/prefabs/ui/privilege/monthly_card_ui.prefab"
end
function MonthlyCardUI:onPressBackspace()
self:closeUI()
end
function MonthlyCardUI:onClose()
if self.callback then
self.callback()
end
end
function MonthlyCardUI:ctor(param)
self.cardType = param.cardType
self.callback = param.callback
self.showToday = param.showToday
end
function MonthlyCardUI:onLoadRootComplete()
local uiMap = self.root:genAllChildren()
self.banner = uiMap["monthly_card_ui.banner"]
self.card1Node = uiMap["monthly_card_ui.banner.card_1"]
self.txDesc1 = uiMap["monthly_card_ui.banner.card_1.tx_desc"]
self.txTips1 = uiMap["monthly_card_ui.banner.card_1.tx_tips"]
self.card2Node = uiMap["monthly_card_ui.banner.card_2"]
self.txDesc2 = uiMap["monthly_card_ui.banner.card_2.tx_desc"]
self.txTips2 = uiMap["monthly_card_ui.banner.card_2.tx_tips"]
self.titleNode = uiMap["monthly_card_ui.content.title"]
self.txTitle = uiMap["monthly_card_ui.content.title.tx_title"]
self.discountNode = uiMap["monthly_card_ui.content.discount"]
self.txDiscount = uiMap["monthly_card_ui.content.discount.tx_discount"]
self.imgShows = {}
self.txShows = {}
for i = 1, 2 do
table.insert(self.imgShows, uiMap['monthly_card_ui.content.show.img_show_' .. i])
table.insert(self.txShows, uiMap['monthly_card_ui.content.show.img_show_' .. i .. '.tx_show'])
end
self.listPrivilege = uiMap["monthly_card_ui.content.list_privilege"]
self.content = uiMap["monthly_card_ui.content.list_privilege.content"]
self.privilegeNodes = {}
self.txPrivilegeDescs = {}
for i = 1, 5 do
table.insert(self.privilegeNodes, uiMap['monthly_card_ui.content.list_privilege.content.privilege_' .. i])
table.insert(self.txPrivilegeDescs, uiMap['monthly_card_ui.content.list_privilege.content.privilege_' .. i .. '.tx_desc'])
end
self.txImmediate = uiMap["monthly_card_ui.content.immediate.tx_immediate"]
self.immediateRewardCell = uiMap["monthly_card_ui.content.immediate.reward_cell_immediate"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.REWARD_CELL)
self.txDaily = uiMap["monthly_card_ui.content.daily.tx_daily"]
self.dailyRewardCells = {}
for i = 1, 2 do
table.insert(self.dailyRewardCells, uiMap['monthly_card_ui.content.daily.reward_cell_daily_' .. i]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.REWARD_CELL))
end
self.btnBuy = uiMap["monthly_card_ui.content.btn_buy"]
self.txBuy = uiMap["monthly_card_ui.content.btn_buy.tx_buy"]
self.btnClose = uiMap["monthly_card_ui.btn_close"]
-- 今日不再展示
self.todayNode = uiMap["monthly_card_ui.content.today"]
self.todatCheck = uiMap["monthly_card_ui.content.today.check"]
self.todaySelect = uiMap["monthly_card_ui.content.today.check.select"]
self.txToday = uiMap["monthly_card_ui.content.today.text"]
self.txDaily:setText(I18N:getGlobalText(I18N.GlobalConst.MONTHLY_CARD_7))
self.txImmediate:setText(I18N:getGlobalText(I18N.GlobalConst.MONTHLY_CARD_4))
self.txDesc1:setText(I18N:getGlobalText(I18N.GlobalConst.MONTHLY_CARD_20) .. "\n " .. I18N:getGlobalText(I18N.GlobalConst.MONTHLY_CARD_DESC_1_1))
self.txDesc2:setText(I18N:getGlobalText(I18N.GlobalConst.MONTHLY_CARD_21))
self.txTips1:setText(I18N:getGlobalText(I18N.GlobalConst.MONTHLY_CARD_22))
self.txTips2:setText(I18N:getGlobalText(I18N.GlobalConst.MONTHLY_CARD_22))
self.btnClose:addClickListener(function()
self:closeUI()
end)
self.btnBuy:addClickListener(function()
ModuleManager.MonthlyCardManager:buyMonthlyCard(self.cardType)
self:closeUI()
end)
self.todatCheck:addClickListener(function()
if ModuleManager.BattleManager.battleController and ModuleManager.BattleManager.battleController.battleData then
ModuleManager.BattleManager.battleController.battleData:setNotPopMonthlyCard(not LocalData:getMonthlyTodayNotShow())
end
LocalData:setMonthlyTodayNotShow(not LocalData:getMonthlyTodayNotShow())
self:onRefresh()
end)
end
function MonthlyCardUI:onRefresh()
self.banner:setSprite(GConst.ATLAS_PATH.UI_MONTHLY_CARD, IMG_BANNER[self.cardType])
self.card1Node:setActive(self.cardType == GConst.MonthlyCardConst.CARD_TYPE.CARD_1)
self.card2Node:setActive(self.cardType == GConst.MonthlyCardConst.CARD_TYPE.CARD_2)
self.titleNode:setSprite(GConst.ATLAS_PATH.UI_MONTHLY_CARD, IMG_TITLE[self.cardType])
self.discountNode:setSprite(GConst.ATLAS_PATH.UI_MONTHLY_CARD, IMG_OFF[self.cardType])
for i = 1, 2 do
if IMG_SHOW[self.cardType][i] then
self.imgShows[i]:setActive(true)
self.imgShows[i]:setSprite(GConst.ATLAS_PATH.UI_MONTHLY_CARD, IMG_SHOW[self.cardType][i], function()
self.imgShows[i]:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_IMAGE):SetNativeSize()
end)
self.txShows[i]:setText(I18N:getGlobalText(I18N.GlobalConst[TX_SHOW[self.cardType][i]]))
else
self.imgShows[i]:setActive(false)
end
end
self.txTitle:setText(I18N:getGlobalText(I18N.GlobalConst[TX_TITLE[self.cardType]]))
local actGiftCfg = DataManager.MonthlyCardData:getActGiftConfig(self.cardType)
self.txBuy:setText(GFunc.getFormatPrice(actGiftCfg.recharge_id))
self.txDiscount:setText(I18N:getGlobalText(I18N.GlobalConst.ACT_MAGIC_DESC_9, actGiftCfg.value))
if self.cardType == GConst.MonthlyCardConst.CARD_TYPE.CARD_1 then
local totalHeight = 0
for i, node in ipairs(self.privilegeNodes) do
local key = I18N.GlobalConst["MONTHLY_CARD_DESC_1_" .. i]
if key then
local str = I18N:getGlobalText(key)
if str and str ~= "" then
node:setActive(true)
self.txPrivilegeDescs[i]:setText(str)
local curHeight = self.txPrivilegeDescs[i]:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT_MESH_PRO).preferredHeight
curHeight = curHeight + 10
totalHeight = totalHeight + curHeight
self.txPrivilegeDescs[i]:setSizeDeltaY(curHeight)
node:setSizeDeltaY(curHeight)
else
node:setActive(false)
end
else
node:setActive(false)
end
end
self.content:setSizeDeltaY(totalHeight)
else
local totalHeight = 0
for i, node in ipairs(self.privilegeNodes) do
local key = I18N.GlobalConst["MONTHLY_CARD_DESC_2_" .. i]
if key then
local str = I18N:getGlobalText(key)
if str and str ~= "" then
node:setActive(true)
self.txPrivilegeDescs[i]:setText(str)
local curHeight = self.txPrivilegeDescs[i]:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT_MESH_PRO).preferredHeight
curHeight = curHeight + 10
totalHeight = totalHeight + curHeight
self.txPrivilegeDescs[i]:setSizeDeltaY(curHeight)
node:setSizeDeltaY(curHeight)
else
node:setActive(false)
end
else
node:setActive(false)
end
end
self.content:setSizeDeltaY(totalHeight)
end
-- 每日奖励
local isActive = DataManager.MonthlyCardData:getIsCardActive(self.cardType)
local canGetDailyReward = DataManager.MonthlyCardData:checkCanGetDailyReward(self.cardType)
local dailyRewards = DataManager.MonthlyCardData:getCardDailyRewards(self.cardType)
for i, cell in ipairs(self.dailyRewardCells) do
if dailyRewards[i] then
cell:getBaseObject():setActive(true)
cell:refreshByConfig(dailyRewards[i], isActive and not canGetDailyReward, isActive and not canGetDailyReward)
if canGetDailyReward then
cell:showFrameAnimation()
cell:addClickListener(function()
ModuleManager.MonthlyCardManager:getDailyReward()
end)
else
cell:hideFrameAnimation()
cell:setClickShowTips()
end
else
cell:getBaseObject():setActive(false)
end
end
-- 购买立得
local immediateReward = DataManager.MonthlyCardData:getCardBuyReward()[1]
self.immediateRewardCell:refreshByConfig(immediateReward)
self.todayNode:setActive(self.showToday)
self.todaySelect:setActive(LocalData:getMonthlyTodayNotShow())
self.txToday:setText(I18N:getGlobalText(I18N.GlobalConst.CONFIRM_IGNORE))
GFunc.centerImgAndTx(self.todatCheck, self.txToday, 5)
end
return MonthlyCardUI