91 lines
3.5 KiB
Lua
91 lines
3.5 KiB
Lua
local MailCell = class("MailCell", BaseCell)
|
|
|
|
local TITLE_ICON = {
|
|
[GConst.MailConst.MAIL_STATE.NOT_READ] = "mail_dec_2",
|
|
[GConst.MailConst.MAIL_STATE.READED] = "mail_dec_3",
|
|
[GConst.MailConst.MAIL_STATE.RECEIVED] = "mail_dec_3",
|
|
}
|
|
|
|
local AD_TITLE_ICON = "mail_dec_1"
|
|
|
|
function MailCell:refresh(entity)
|
|
if not entity then
|
|
return
|
|
end
|
|
|
|
local uiMap = self:getUIMap()
|
|
local normalNode = uiMap["mail_cell.bg_normal"]
|
|
local adNode = uiMap["mail_cell.bg_ad"]
|
|
local readNode = uiMap["mail_cell.bg_read"]
|
|
if entity:getMailType() == GConst.MailConst.MAIL_TYPE.CUSTOM then
|
|
normalNode:setVisible(false)
|
|
adNode:setVisible(false)
|
|
readNode:setVisible(true)
|
|
elseif entity:getMailType() == GConst.MailConst.MAIL_TYPE.AD then
|
|
normalNode:setVisible(false)
|
|
adNode:setVisible(true)
|
|
readNode:setVisible(false)
|
|
elseif entity:getMailType() == GConst.MailConst.MAIL_TYPE.NORMAL then
|
|
normalNode:setVisible(true)
|
|
adNode:setVisible(false)
|
|
readNode:setVisible(false)
|
|
elseif entity:getMailType() == GConst.MailConst.MAIL_TYPE.READ then
|
|
normalNode:setVisible(false)
|
|
adNode:setVisible(false)
|
|
readNode:setVisible(true)
|
|
end
|
|
GFunc.setAdsSprite(uiMap["mail_cell.bg_ad.claim_btn.ad"])
|
|
uiMap["mail_cell.bg_normal.claim_btn.tx"]:setText(I18N:getGlobalText(I18N.GlobalConst.BTN_CLAIM))
|
|
uiMap["mail_cell.bg_read.claim_btn.tx"]:setText(I18N:getGlobalText(I18N.GlobalConst.BTN_READ))
|
|
uiMap["mail_cell.bg_normal.claim_btn"]:addClickListener(function()
|
|
if entity:canClaim() then
|
|
ModuleManager.MailManager:claimMail({entity:getId()})
|
|
end
|
|
end)
|
|
uiMap["mail_cell.bg_ad.claim_btn"]:addClickListener(function()
|
|
if entity:canClaim() then
|
|
SDKManager:showFullScreenAds(BIReport.ADS_CLICK_TYPE.MAIL, function()
|
|
ModuleManager.MailManager:claimMail({entity:getId()})
|
|
end)
|
|
end
|
|
end)
|
|
uiMap["mail_cell.bg_read.claim_btn"]:addClickListener(function()
|
|
ModuleManager.MailManager:readMail(entity:getId())
|
|
end)
|
|
|
|
local titleIcon = uiMap["mail_cell.title_icon"]
|
|
local icon = TITLE_ICON[entity:getState()] or TITLE_ICON[GConst.MailConst.MAIL_STATE.NOT_READ]
|
|
|
|
if entity:notRead() and entity:getMailType() == GConst.MailConst.MAIL_TYPE.AD then
|
|
icon = AD_TITLE_ICON
|
|
end
|
|
if self.icon ~= icon then
|
|
titleIcon:setSprite(GConst.ATLAS_PATH.UI_MAIL, icon)
|
|
self.icon = icon
|
|
end
|
|
uiMap["mail_cell.new"]:setVisible(entity:showNew())
|
|
uiMap["mail_cell.desc"]:setText(entity:getMailName())
|
|
uiMap["mail_cell.time"]:setText(entity:getRemainCdStr())
|
|
local rewardBg = uiMap["mail_cell.reward_bg"]
|
|
local mask = uiMap["mail_cell.reward_bg.mask"]
|
|
if not self.rewardCell then
|
|
self.rewardCell = CellManager:addCellComp(uiMap["mail_cell.reward_cell"], GConst.TYPEOF_LUA_CLASS.REWARD_CELL)
|
|
end
|
|
local rewards = entity:getRewards()
|
|
local showCheck = entity:isReceived()
|
|
if rewards[2] then
|
|
rewardBg:setVisible(true)
|
|
self.rewardCell:getBaseObject():setVisible(false)
|
|
mask:setVisible(showCheck)
|
|
else
|
|
rewardBg:setVisible(false)
|
|
if entity:haveReward() then
|
|
self.rewardCell:getBaseObject():setVisible(true, 0.7)
|
|
self.rewardCell:refreshByConfig(rewards[1], showCheck, showCheck)
|
|
else
|
|
self.rewardCell:getBaseObject():setVisible(false)
|
|
end
|
|
end
|
|
end
|
|
|
|
return MailCell |