c1_lua/lua/app/ui/activity/common/act_gift_ui.lua
2025-05-08 22:43:25 +08:00

146 lines
4.5 KiB
Lua

local ActGiftUI = class("ActGiftUI", BaseUI)
function ActGiftUI:isFullScreen()
return false
end
function ActGiftUI:showCommonBG()
return false
end
function ActGiftUI:getPrefabPath()
return self.prefabPath
end
function ActGiftUI:onPressBackspace()
self:closeUI()
end
function ActGiftUI:onClose()
end
function ActGiftUI:ctor(param)
self.actId = param.actId
self.prefabPath = param.prefabPath
self.giftIds = DataManager.ActGiftData:getTriggerGiftIdsByActId(self.actId)
self.curIndex = 1
end
function ActGiftUI:onLoadRootComplete()
local uiMap = self.root:genAllChildren()
self.txTitle = uiMap["act_gift_ui.content.tx_title"]
self.imgTime = uiMap["act_gift_ui.content.time_node.img_time"]
self.txTime = uiMap["act_gift_ui.content.time_node.tx_time"]
self.rewardCells = {}
for i = 1, 2 do
table.insert(self.rewardCells, uiMap["act_gift_ui.content.reward_node.reward_cell_" .. i]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.REWARD_CELL))
end
self.btnRight = uiMap["act_gift_ui.content.btn_right"]
self.btnLeft = uiMap["act_gift_ui.content.btn_left"]
self.btnBuy = uiMap["act_gift_ui.content.btn_buy"]
self.txBuy = uiMap["act_gift_ui.content.btn_buy.tx_buy"]
self.offNode = uiMap["act_gift_ui.content.off_node"]
self.txOff = uiMap["act_gift_ui.content.off_node.tx_off"]
self.btnClose = uiMap["act_gift_ui.btn_close"]
self.layout = uiMap["act_gift_ui.content.layout"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_HORIZONTAL_OR_VERTICAL_LAYOUT)
self.tags = {}
for i = 1, 10 do
table.insert(self.tags, uiMap["act_gift_ui.content.layout.tag_" .. i])
end
self.txTitle:setText(I18N:getGlobalText(I18N.GlobalConst.GIFT_DESC_1))
self:scheduleGlobal(function()
self:updateTime()
end, 1)
self:updateTime()
self.btnBuy:addClickListener(function()
ModuleManager.ActivityManager:onGiftBuy(self.giftIds[self.curIndex])
end)
self.btnLeft:addClickListener(function()
if self.curIndex <= 1 then
return
end
self:onChangeSelect(self.curIndex - 1)
end)
self.btnRight:addClickListener(function()
if self.curIndex >= #self.giftIds then
return
end
self:onChangeSelect(self.curIndex + 1)
end)
self.btnClose:addClickListener(function()
self:closeUI()
end)
self:bind(DataManager.PaymentData, "isDirty", function()
self:onGiftChange()
end)
self:addEventListener(EventManager.CUSTOM_EVENT.ACT_TRIGGER_GIFT, function()
self:onGiftChange()
end)
end
function ActGiftUI:updateTime()
local remainTime = DataManager.ActGiftData:getTriggerGiftEndTime(self.actId, self.giftIds[self.curIndex]) - Time:getServerTime()
if remainTime > 0 then
self.txTime:setText(I18N:getGlobalText(I18N.GlobalConst.TIME_END_DESC_1, Time:formatNumTimeStr(remainTime)))
else
self:onGiftChange()
end
end
function ActGiftUI:onGiftChange()
self.giftIds = DataManager.ActGiftData:getTriggerGiftIdsByActId(self.actId)
if self.giftIds and #self.giftIds > 0 then
self:onChangeSelect(1)
self:onRefresh()
else
self:closeUI()
end
end
function ActGiftUI:onChangeSelect(idx)
self.curIndex = idx
self:updateTime()
self:onRefresh()
end
function ActGiftUI:onRefresh()
local giftId = self.giftIds[self.curIndex]
local giftCfg = ConfigManager:getConfig("act_gift")[giftId]
local rewards = giftCfg.reward
for i, cell in ipairs(self.rewardCells) do
if rewards and rewards[i] then
cell:showCell()
cell:refreshByConfig(rewards[i])
else
cell:hideCell()
end
end
self.btnLeft:setActive(self.curIndex > 1)
self.btnRight:setActive(self.curIndex < #self.giftIds)
self.txBuy:setText(GFunc.getFormatPrice(giftCfg.recharge_id))
self.offNode:setActive(giftCfg.value ~= nil)
self.txOff:setText("-" .. giftCfg.value .. "%")
for i, tag in ipairs(self.tags) do
if self.giftIds[i] then
tag:setActive(true)
tag:setSprite(GConst.ATLAS_PATH.COMMON, self.curIndex == i and "common_point_2" or "common_point_3")
tag:addClickListener(function()
self:onChangeSelect(i)
end)
else
tag:setActive(false)
end
end
self.layout:RefreshLayout()
GFunc.centerImgAndTx(self.imgTime, self.txTime, 3)
end
return ActGiftUI