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

109 lines
3.3 KiB
Lua

local ExchangeCell = class("ExchangeCell", BaseCell)
function ExchangeCell:init()
local uiMap = self:getUIMap()
self.bg = uiMap["exchange_cell.bg"]
self.rewardCell = uiMap["exchange_cell.bg.reward_cell"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.REWARD_CELL)
self.icon = uiMap["exchange_cell.bg.icon"]
self.costTx = uiMap["exchange_cell.bg.cost_tx"]
self.descTx = uiMap["exchange_cell.bg.desc_tx"]
self.emptyTx = uiMap["exchange_cell.bg.empty_tx"]
self.tagNode = uiMap["exchange_cell.bg.tag"]
self.txOff = uiMap["exchange_cell.bg.tag.off_tx"]
self.txName = uiMap["exchange_cell.bg.tx_name"]
self.changeImg = uiMap["exchange_cell.bg.change_img"]
self.emptyTx:setText(I18N:getGlobalText(I18N.GlobalConst.GIFT_ROUTINE_DESC_10))
self.bg:addClickListener(function()
self:doExchange()
end)
end
function ExchangeCell:refresh(parentUI, dataKey, cfg)
self.parentUI = parentUI
self.data = DataManager[dataKey]
local id = cfg.id
self.id = id
self.cfg = cfg
self.reward = cfg.reward[1]
self.cost = cfg.cost[1]
local totalNum = cfg.limit
self.remainNum = totalNum - DataManager.ActivityData:getExchangeCount(self.id)
self.rewardCell:refreshByConfig(self.reward, self.remainNum <= 0, self.remainNum <= 0)
self.descTx:setText(I18N:getGlobalText(I18N.GlobalConst.GIFT_ROUTINE_DESC_8).. ":" .. self.remainNum .. "/" .. totalNum)
self.txName:setText(GFunc.getRewardName(self.reward))
if self.remainNum > 0 then
self.bg:setTouchEnable(true)
self.bg:setSprite(self.parentUI:getExchangeRes(true))
self.costTx:setText(self.cost.num)
self.icon:setSprite(GFunc.getIconRes(self.cost.id))
GFunc.centerImgAndTx(self.icon, self.costTx, 0)
self.emptyTx:setActive(false)
self.costTx:setActive(true)
self.icon:setActive(true)
else
self.bg:setTouchEnable(false)
self.bg:setSprite(self.parentUI:getExchangeRes())
self.emptyTx:setActive(true)
self.costTx:setActive(false)
self.icon:setActive(false)
end
if self.cfg.value then
self.tagNode:setActive(true)
self.txOff:setText(self.cfg.value .. "%")
else
self.tagNode:setActive(false)
end
self:refreshChange()
end
function ExchangeCell:refreshChange()
local group = self.cfg.group
if not group then
self.changeImg:setActive(false)
return
end
local list = self.data:getExchange2GroupList(group)
if #list <= 1 then
self.changeImg:setActive(false)
return
end
self.changeImg:setActive(true)
self.changeImg:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_IMAGE):SetNativeSize()
self.changeImg:addClickListener(function()
local idx = self.data:getExchange2GroupListSelIdx(group)
local rewards = {}
for i,v in ipairs(list) do
table.insert(rewards, v.reward[1])
end
GFunc.showRewardSelectUI(rewards, idx, function(index)
self.data:setExchange2GroupListSelIdx(group, index)
end, I18N:getGlobalText(I18N.GlobalConst.GET_REWARD_DESC))
end)
end
function ExchangeCell:doExchange()
if not self.reward then
return
end
if not GFunc.checkCost(self.cost.id, self.cost.num, true) then
EventManager:dispatchEvent(EventManager.CUSTOM_EVENT.CHANGE_ACTIVITY_PAGE, self.parentUI.ActConst.BOTTOM_PAGE.TURNTABLE)
return
end
GFunc.showBuyFastUI(self.reward, self.cost, self.remainNum, function(count)
self.parentUI:reqExchange(self.id, count)
end)
end
return ExchangeCell