c1_lua/lua/app/ui/bounty/cell/bounty_reward_cell.lua
2023-05-26 18:47:31 +08:00

103 lines
2.9 KiB
Lua

local BountyRewardCell = class("BountyRewardCell", BaseCell)
function BountyRewardCell:init()
local uiMap = self:getUIMap()
self.bg = uiMap["bounty_reward_cell.bg"]
self.icon = uiMap["bounty_reward_cell.icon"]
self.numTx = uiMap["bounty_reward_cell.num"]
self.check = uiMap["bounty_reward_cell.check"]
self.fragment = uiMap["bounty_reward_cell.fragment"]
self.light = uiMap["bounty_reward_cell.light"]
self.lock = uiMap["bounty_reward_cell.lock"]
self.matchImg = uiMap["bounty_reward_cell.match_img"]
self.sImg = uiMap["bounty_reward_cell.s"]
self:hideLight()
self.baseObject:addClickListener(function()
if self.clickCallback then
self.clickCallback()
elseif self.rewardId ~= nil then
ModuleManager.TipsManager:showRewardTips(self.rewardId, self.rewardType, self.baseObject)
end
end)
end
function BountyRewardCell:refresh(reward, isPro, isLock, showCheck)
self:showCheck(showCheck)
if isPro then
self.bg:setSprite(GConst.ATLAS_PATH.BOUNTY, "bounty_board_2")
else
self.bg:setSprite(GConst.ATLAS_PATH.BOUNTY, "bounty_board_1")
end
if isLock then
self.lock:setVisible(true)
else
self.lock:setVisible(false)
end
if reward.type == GConst.REWARD_TYPE.ITEM then
self:_refreshItem(reward)
self.rewardId = reward.id
self.rewardType = reward.type
else
self.rewardId = nil
end
end
function BountyRewardCell:_refreshItem(item)
local info = ConfigManager:getConfig("item")[item.id]
if info == nil then
return
end
self.numTx:setText(item.count or item.num)
if info.type == GConst.ItemConst.ITEM_TYPE.HERO_FRAGMENT then
local heroInfo = ConfigManager:getConfig("hero")[info.parameter]
if heroInfo then
self.icon:setLocalScale(0.86, 0.86, 0.86)
self.icon:setSprite(GConst.ATLAS_PATH.ICON_HERO, heroInfo.icon)
self.matchImg:setSprite(GConst.ATLAS_PATH.ICON_HERO, GConst.HeroConst.MATCH_ICON_NAME[heroInfo.position])
self.matchImg:setVisible(true)
self.sImg:setVisible(heroInfo.qlt >= 4)
else
self.icon:setSprite(GConst.ATLAS_PATH.COMMON, "common_alpha")
self.matchImg:setVisible(false)
self.sImg:setVisible(false)
end
self.fragment:setVisible(true)
else
self.icon:setLocalScale(1, 1, 1)
self.icon:setSprite(GConst.ATLAS_PATH.ICON_ITEM, info.icon)
self.fragment:setVisible(false)
self.matchImg:setVisible(false)
self.sImg:setVisible(false)
end
end
function BountyRewardCell:showCheck(show)
self.check:setVisible(show == true)
end
function BountyRewardCell:setVisible(visible)
self.baseObject:setActive(visible)
end
function BountyRewardCell:setAnchoredPositionX(x)
self.baseObject:setAnchoredPositionX(x)
end
function BountyRewardCell:setTouchEnable(enable)
self.baseObject:setTouchEnable(enable)
end
function BountyRewardCell:addClickListener(callback)
self.clickCallback = callback
end
function BountyRewardCell:showLight()
self.light:setVisible(true)
end
function BountyRewardCell:hideLight()
self.light:setVisible(false)
end
return BountyRewardCell