c1_lua/lua/app/ui/bounty/cell/bounty_reward_cell.lua
2023-05-15 21:32:13 +08:00

85 lines
3.2 KiB
Lua

local BountyRewardCell = class("BountyRewardCell", BaseCell)
function BountyRewardCell:init()
local uiMap = self:getUIMap()
self.uiMap = uiMap
self.rewardCell1 = uiMap["cell.bg.reward_cell_1"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.REWARD_CELL)
self.rewardCell2 = uiMap["cell.bg.reward_cell_2"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.REWARD_CELL)
self.maskImg = uiMap["cell.mask_img"]
self.rewardCell1:addClickListener(function()
if self.idx == nil then
return
end
local iCslaimed = DataManager.BountyData:getLevelState(self.idx)
local lv = DataManager.BountyData:getLevel()
if not iCslaimed and lv >= self.idx then
ModuleManager.BountyManager:claimReward(self.idx, false)
else
local bountyInfo = DataManager.BountyData:getSeasonInfoByLevel(self.idx)
ModuleManager.TipsManager:showRewardTips(bountyInfo.reward.id, bountyInfo.reward.type, self.rewardCell1:getBaseObject())
end
end)
self.rewardCell2:addClickListener(function()
if self.idx == nil then
return
end
local isBought = DataManager.BountyData:getBought()
local iCslaimed = DataManager.BountyData:getProLevelState(self.idx)
local lv = DataManager.BountyData:getLevel()
if isBought and not iCslaimed and lv >= self.idx then
ModuleManager.BountyManager:claimReward(self.idx, true)
else
local bountyInfo = DataManager.BountyData:getSeasonInfoByLevel(self.idx)
ModuleManager.TipsManager:showRewardTips(bountyInfo.reward_pro.id, bountyInfo.reward_pro.type, self.rewardCell2:getBaseObject())
end
end)
end
function BountyRewardCell:refresh(idx)
self.idx = idx
local bountyInfo = DataManager.BountyData:getSeasonInfoByLevel(idx)
local lv = DataManager.BountyData:getLevel()
local state = DataManager.BountyData:getLevelState(idx)
local proState = DataManager.BountyData:getProLevelState(idx)
local isBought = DataManager.BountyData:getBought()
self.rewardCell1:refreshByConfig(bountyInfo.reward, state, state)
self.rewardCell2:refreshByConfig(bountyInfo.reward_pro, proState, proState)
if lv >= idx then
self.maskImg:setVisible(false)
if state then -- 已经领过了
self.rewardCell1:hideFrameAnimation()
else
self.rewardCell1:showFrameAnimation(bountyInfo.reward)
end
if isBought and not proState then
self.rewardCell2:showFrameAnimation(bountyInfo.reward_pro.type)
else
self.rewardCell2:hideFrameAnimation()
end
else
self.maskImg:setVisible(true)
self.rewardCell1:hideFrameAnimation()
self.rewardCell2:hideFrameAnimation()
end
-- self.lockImg:setVisible(not isBought, 1.5)
-- self.rewardBg:setVisible(false)
-- self.bg:setSprite(GConst.ATLAS_PATH.UI_BOUNTY, "bounty_board_7")
-- if lv >= idx then
-- self.lvBg:setSprite(GConst.ATLAS_PATH.UI_BOUNTY, "bounty_board_5", function ()
-- self.lvBg:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_IMAGE):SetNativeSize()
-- end)
-- else
-- self.lvBg:setSprite(GConst.ATLAS_PATH.UI_BOUNTY, "bounty_board_6", function ()
-- self.lvBg:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_IMAGE):SetNativeSize()
-- end)
-- end
-- self.rewardCell1:setLocalScale(0.65, 0.65, 1)
-- self.rewardCell2:setLocalScale(0.65, 0.65, 1)
end
function BountyRewardCell:setVisible(visible)
self.baseObject:setVisible(visible)
end
return BountyRewardCell