c1_lua/lua/app/ui/collection/cell/collection_reward_cell.lua
2023-07-17 11:16:51 +08:00

59 lines
2.4 KiB
Lua

local CollectionRewardCell = class("CollectionRewardCell", BaseCell)
function CollectionRewardCell:init()
local uiMap = self:getUIMap()
self.imgProg = uiMap["collection_reward_cell.progress.img_prog"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER)
self.txValue = uiMap["collection_reward_cell.progress.tx_value"]
self.txDesc = uiMap["collection_reward_cell.reward_info.tx_desc"]
self.maskReward = uiMap["collection_reward_cell.reward_info.mask"]
self.tagProg = uiMap["collection_reward_cell.cur_prog"]
self.imgTag = uiMap["collection_reward_cell.cur_prog.img_icon"]
self.txTag = uiMap["collection_reward_cell.cur_prog.tx_value"]
self.rewards = {}
for i = 1, 4 do
table.insert(self.rewards, uiMap["collect_reward_cell.reward_info.rewards.reward_cell_" .. i]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.REWARD_CELL))
end
end
function CollectionRewardCell:refresh(collectionType, id)
local curPoint = DataManager.CollectionData:getCurCollectPoint(collectionType)
local rewardList = DataManager.CollectionData:getRewardList(collectionType)[id]
self.txValue:setText(rewardList.point)
self.txTag:setText(curPoint)
local prog = DataManager.CollectionData:getRewardTargetProgress(collectionType, id)
if DataManager.CollectionData:getCurTargetId(collectionType) == id then
self.imgProg.value = prog
self.tagProg:setVisible(true)
-- 高度超框处理
local rootHeight = self.baseObject:fastGetSizeDeltaY()
local posY = rootHeight * prog
if id == 1 or id == #DataManager.CollectionData:getRewardList(collectionType) then
local tagHeight = self.tagProg:fastGetSizeDeltaY()
if posY < tagHeight / 2 then
posY = tagHeight / 2
end
end
self.tagProg:setAnchoredPositionY(posY)
else
self.imgProg.value = prog
self.tagProg:setVisible(false)
end
if DataManager.CollectionData:isRewardReceived(collectionType, id) then
self.maskReward:setVisible(false)
self.txDesc:setText(I18N:getGlobalText(I18N.GlobalConst.COLLECTION_DESC_5))
else
self.maskReward:setVisible(true)
self.txDesc:setText(I18N:getGlobalText(I18N.GlobalConst.COLLECTION_DESC_6))
end
for idx, reward in pairs(self.rewards) do
reward:refreshByConfig(rewardList.reward[idx])
end
GFunc.centerImgAndTx(self.imgTag, self.txTag, 5)
end
return CollectionRewardCell