c1_lua/lua/app/ui/activity/activity_hero_comp.lua
2023-08-11 11:52:12 +08:00

52 lines
2.2 KiB
Lua

local ActivityHeroComp = class("ActivityHeroComp", LuaComponent)
function ActivityHeroComp:init()
local uiMap = self:getUIMap()
self.spineBanner = uiMap["hero_panel.spine_banner"]
self.txTitle = uiMap["hero_panel.tx_title"]
self.popRewardCell1 = uiMap["hero_panel.rewards.pop_reward_cell_1"]
self.popRewardCell2 = uiMap["hero_panel.rewards.pop_reward_cell_2"]
self.popRewardCell3 = uiMap["hero_panel.rewards.pop_reward_cell_3"]
self.txTime = uiMap["hero_panel.tx_time"]
self.btnBuy = uiMap["hero_panel.btn_buy"]
self.txBuy = uiMap["hero_panel.btn_buy.tx_buy"]
self.rewardCells = {}
for i = 1, 3 do
table.insert(self.rewardCells, uiMap["hero_panel.rewards.pop_reward_cell_" .. i]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.POP_REWARD_CELL))
end
self.btnBuy:addClickListener(function()
PayManager:purchasePackage(GConst.ActivityConst.HERO_GIFT_ID_1, PayManager.PURCHARSE_TYPE.ACT_GIFT)
end)
LocalData:recordTodayActSummerWatchedHero()
end
function ActivityHeroComp:refresh()
self.spineBanner:playAnimComplete("born", false, true, function()
self.spineBanner:playAnim("idle", true, true)
end)
self.txTitle:setText(I18N:getGlobalText(I18N.GlobalConst.ACT_DESC_8))
local gift = DataManager.ShopData:getActGiftConfig()[GConst.ActivityConst.HERO_GIFT_ID_1]
self.txTime:setText(I18N:getGlobalText(I18N.GlobalConst.SHOP_DESC_18, tostring(gift.limit)))
self.txBuy:setText(GFunc.getFormatPrice(gift.recharge_id))
for index, cell in ipairs(self.rewardCells) do
if gift.reward[index] then
cell:setVisible(true)
cell:refresh(gift.reward[index].id, gift.reward[index].num, true)
else
cell:setVisible(false)
end
end
if DataManager.ShopData:getGiftRemainBuyNum(GConst.ActivityConst.HERO_GIFT_ID_1) > 0 then
self.btnBuy:setTouchEnable(true)
self.btnBuy:setSprite(GConst.ATLAS_PATH.COMMON, "common_btn_green_2")
self.txBuy:setText(GFunc.getFormatPrice(gift.recharge_id))
else
self.btnBuy:setTouchEnable(false)
self.btnBuy:setSprite(GConst.ATLAS_PATH.COMMON, "common_btn_grey_2")
self.txBuy:setText(I18N:getGlobalText(I18N.GlobalConst.SHOP_DESC_20))
end
end
return ActivityHeroComp