c1_lua/lua/app/ui/common/cell/reward_cell.lua
2025-10-30 21:39:53 +08:00

234 lines
6.2 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

local RewardCell = class("RewardCell", BaseCell)
function RewardCell:init()
local uiMap = self:getUIMap()
self.frameAni = uiMap["reward_cell.frame_ani"]
self.itemCell = uiMap["reward_cell.item_cell"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.ITEM_CELL)
self.equipCell = uiMap["reward_cell.equip_cell"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.EQUIP_CELL)
self.imgSelect = uiMap["reward_cell.img_select"]
-- 概率标记
self.probNode = uiMap["reward_cell.prob"]
self.txProb = uiMap["reward_cell.prob.tx_prob"]
self.firstNode = uiMap["reward_cell.first_bg"]
self.txfirst = uiMap["reward_cell.first_bg.first_tx"]
self.rightUpIcon = uiMap["reward_cell.right_up_icon"]
self.rightUpIcon:setActive(false)
self:setShowSelect(false)
self:hideFrameAnimation()
self:setShowProbTag(false)
self:setShowFirstTag(false)
end
function RewardCell:refresh(reward, mask, check)
if reward.type == GConst.REWARD_TYPE.ITEM then
self.id = reward.item.id
self.num = reward.item.num
self.type = reward.type
self.itemCell:setActive(true)
self.equipCell:setActive(false)
self.itemCell:refreshByCfg(reward.item.id, reward.item.num or reward.item.count)
elseif reward.type == GConst.REWARD_TYPE.EQUIP then
self.id = reward.equip.cfg_id
self.type = reward.type
self.itemCell:setActive(false)
self.equipCell:setActive(true)
self.equipCell:refreshByCfg(self.id)
end
self:showMask(mask, check)
self:showCheck(check)
self:setShowProbTag(false)
self:setShowFirstTag(false)
self:setClickShowTips()
end
function RewardCell:refreshById(id, num)
self.id = id
self.num = num
self.type = GConst.REWARD_TYPE.ITEM
self.itemCell:setActive(true)
self.equipCell:setActive(false)
self.itemCell:refreshByCfg(self.id, self.num)
self:showMask(false, false)
self:showCheck(false)
self:setShowProbTag(false)
self:setShowFirstTag(false)
self:setClickShowTips()
end
function RewardCell:refreshByConfig(reward, mask, check)
self.id = reward.id
self.type = reward.type
self.num = reward.num
if reward.type == GConst.REWARD_TYPE_NUM.ITEM then
self.itemCell:setActive(true)
self.equipCell:setActive(false)
local num = reward.num or reward.count
self.itemCell:refreshByCfg(reward.id, num)
elseif reward.type == GConst.REWARD_TYPE_NUM.EQUIP then
self.itemCell:setActive(false)
self.equipCell:setActive(true)
self.equipCell:refreshByCfg(reward.id, reward.lv)
end
self:showMask(mask, check)
self:showCheck(check)
self:setShowProbTag(false)
self:setShowFirstTag(false)
self:setClickShowTips()
end
function RewardCell:refreshByEntity(entity)
local type = entity:getType()
if type == GConst.REWARD_TYPE.ITEM then
local id = entity:getId()
self:refreshByConfig({type = type, id = id, num = entity:getNum()})
end
end
function RewardCell:setShowSelect(show, scale)
self.imgSelect:setActive(show)
end
function RewardCell:setShowProbTag(show, prob)
if self.probNode == nil or self.txProb == nil then
return
end
self.probNode:setVisible(show)
self.txProb:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT_MESH_PRO).fontSize = 24 -- 临时处理大版本的时候再修改prefab
self.txProb:setText((prob or 0) .. "%")
end
function RewardCell:setShowFirstTag(show)
if self.firstNode == nil or self.txfirst == nil then
return
end
self.firstNode:setVisible(show)
self.txfirst:setText(I18N:getGlobalText(I18N.GlobalConst.FIRST_PASS))
end
-- 展示spine动画高亮框
function RewardCell:showFrameAnimation(scale)
self.frameAni:setActive(true)
self.frameAni:getComponent(GConst.TYPEOF_UNITY_CLASS.ANIMATOR).enabled = true
if self.frameAniType ~= GConst.REWARD_TYPE.ITEM then
-- CS.UnityEngine.Animator.StringToHash("frame_reward") 结果是997722489
self.frameAni:getComponent(GConst.TYPEOF_UNITY_CLASS.ANIMATOR):Play(997722489, -1, 0)
self.frameAniType = GConst.REWARD_TYPE.ITEM
end
end
function RewardCell:hideFrameAnimation()
self.frameAni:getComponent(GConst.TYPEOF_UNITY_CLASS.ANIMATOR).enabled = false
self.frameAni:setActive(false)
end
function RewardCell:showRightUpIcon(show, atlas, iconName)
self.rightUpIcon:setActive(show)
if not show then
return
end
self.rightUpIcon:setSprite(atlas, iconName)
end
function RewardCell:showMask(show, syncCheck)
self.itemCell:showMask(show)
self.equipCell:showMask(show)
self:showCheck(syncCheck)
end
function RewardCell:showCheck(show)
self.itemCell:showCheck(show)
self.equipCell:showCheck(show)
end
function RewardCell:showLock(show)
self.itemCell:showLock(show)
self.equipCell:showLock(show)
end
function RewardCell:hideRewardNum()
self.itemCell:setNum(GConst.EMPTY_STRING)
end
function RewardCell:showRewardNum(numStr)
if not numStr then
return
end
self.itemCell:setNum(numStr)
end
function RewardCell:setNumTxDouble()
if self.count then
local count = self.count * 2
if count > 100 then
self:showRewardNum(GFunc.num2Str(count))
else
self:showRewardNum(GFunc.intToString(count))
end
end
end
function RewardCell:setClickShowTips(showItemTip)
self.itemCell:addClickListener(function()
ModuleManager.TipsManager:showRewardTips(self.id, self.type, self.baseObject, nil, { num = self.num },
showItemTip)
end)
self.equipCell:addClickListener(function()
ModuleManager.TipsManager:showRewardTips(self.id, self.type, self.baseObject)
end)
end
function RewardCell:addClickListener(func)
self.itemCell:addClickListener(func)
self.equipCell:addClickListener(func)
end
function RewardCell:setParentUI(parent)
self.parentUI = parent
end
function RewardCell:removeClickListener()
self.itemCell:removeClickListener()
self.equipCell:removeClickListener()
end
function RewardCell:setVisible(visible)
self.baseObject:setActive(visible)
end
function RewardCell:setActive(active)
self.baseObject:setActive(active)
end
function RewardCell:setAnchoredPositionX(x)
self.baseObject:setAnchoredPositionX(x)
end
function RewardCell:getAnchoredPositionX()
return self.baseObject:getAnchoredPositionX()
end
function RewardCell:getAnchoredPositionY()
return self.baseObject:getAnchoredPositionY()
end
function RewardCell:setTouchEnable(enable)
self.baseObject:setTouchEnable(enable)
self.itemCell:setTouchEnable(enable)
self.equipCell:setTouchEnable(enable)
end
function RewardCell:setLocalScale(x, y, z)
self.baseObject:setLocalScale(x, y, z)
end
return RewardCell