116 lines
4.4 KiB
Lua
116 lines
4.4 KiB
Lua
local MailCell = class("MailCell", BaseCell)
|
|
|
|
local TITLE_ICON = {
|
|
[GConst.MailConst.MAIL_STATE.NOT_READ] = "mail_dec_1",
|
|
[GConst.MailConst.MAIL_STATE.READED] = "mail_dec_2",
|
|
[GConst.MailConst.MAIL_STATE.RECEIVED] = "mail_dec_2",
|
|
}
|
|
|
|
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"]
|
|
local isReadType = false
|
|
if entity:getMailType() == GConst.MailConst.MAIL_TYPE.CUSTOM then
|
|
normalNode:setActive(false)
|
|
adNode:setActive(false)
|
|
readNode:setActive(true)
|
|
isReadType = true
|
|
elseif entity:getMailType() == GConst.MailConst.MAIL_TYPE.AD then
|
|
normalNode:setActive(false)
|
|
adNode:setActive(true)
|
|
readNode:setActive(false)
|
|
elseif entity:getMailType() == GConst.MailConst.MAIL_TYPE.NORMAL then
|
|
normalNode:setActive(true)
|
|
adNode:setActive(false)
|
|
readNode:setActive(false)
|
|
elseif entity:getMailType() == GConst.MailConst.MAIL_TYPE.READ then
|
|
normalNode:setActive(false)
|
|
adNode:setActive(false)
|
|
readNode:setActive(true)
|
|
isReadType = 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()
|
|
self:claimMail(entity)
|
|
end)
|
|
uiMap["mail_cell.bg_ad.claim_btn"]:addClickListener(function()
|
|
self:claimMail(entity)
|
|
end)
|
|
uiMap["mail_cell.bg_read.claim_btn"]:addClickListener(function()
|
|
BIReport:postMailClick(entity:getId())
|
|
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, function()
|
|
titleIcon:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_IMAGE):SetNativeSize()
|
|
end)
|
|
self.icon = icon
|
|
end
|
|
uiMap["mail_cell.new"]:setActive(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:setActive(true)
|
|
self.rewardCell:setActive(false)
|
|
mask:setActive(showCheck)
|
|
else
|
|
rewardBg:setActive(false)
|
|
if entity:haveReward() then
|
|
self.rewardCell:setActive(true)
|
|
self.rewardCell:refreshByConfig(rewards[1], showCheck, showCheck)
|
|
else
|
|
self.rewardCell:setActive(false)
|
|
end
|
|
end
|
|
if isReadType then
|
|
if showCheck then
|
|
uiMap["mail_cell.bg_read"]:setImageGray(true)
|
|
uiMap["mail_cell.bg_read.claim_btn"]:setSprite(GConst.ATLAS_PATH.COMMON, "common_btn_grey_3")
|
|
elseif not entity:haveReward() and entity:isRead() then
|
|
uiMap["mail_cell.bg_read"]:setImageGray(true)
|
|
uiMap["mail_cell.bg_read.claim_btn"]:setSprite(GConst.ATLAS_PATH.COMMON, "common_btn_grey_3")
|
|
else
|
|
uiMap["mail_cell.bg_read"]:setImageGray(false)
|
|
uiMap["mail_cell.bg_read.claim_btn"]:setSprite(GConst.ATLAS_PATH.COMMON, "common_btn_green_3")
|
|
end
|
|
end
|
|
end
|
|
|
|
function MailCell:claimMail(entity)
|
|
if not entity:canClaim() then
|
|
return
|
|
end
|
|
|
|
if entity:getIsAdMail() then
|
|
SDKManager:showFullScreenAds(BIReport.ADS_CLICK_TYPE.MAIL, function()
|
|
ModuleManager.MailManager:claimMail({entity:getId()})
|
|
end)
|
|
elseif entity:getIsNormalMail() then
|
|
ModuleManager.MailManager:claimMail({entity:getId()})
|
|
end
|
|
end
|
|
|
|
return MailCell |