c1_lua/lua/app/ui/common/cell/item_cell.lua
2023-06-02 21:03:34 +08:00

71 lines
1.8 KiB
Lua

local ItemCell = class("ItemCell", BaseCell)
function ItemCell:init()
local uiMap = self:getUIMap()
self.icon = uiMap["item_cell.icon"]
self.num = uiMap["item_cell.num"]
self.bg = uiMap["item_cell.bg"]
self.mask = uiMap["item_cell.mask"]
self.check = uiMap["item_cell.check"]
self.fragment =uiMap["item_cell.fragment"]
end
function ItemCell:refresh(entity)
self:_refresh(entity:getId(), entity:getCount())
end
function ItemCell:refreshByCfg(id, count)
self:_refresh(id, count)
end
function ItemCell:_refresh(itemId, count)
local cfg = ConfigManager:getConfig("item")[itemId]
self.bg:setSprite(GConst.ATLAS_PATH.ICON_ITEM, GConst.FRAME_QLT[cfg.qlt])
self.num:setText(GFunc.num2Str(count))
if cfg.type == GConst.ItemConst.ITEM_TYPE.HERO_FRAGMENT then
local heroInfo = ConfigManager:getConfig("hero")[cfg.parameter]
if heroInfo then
self.icon:setSprite(GConst.ATLAS_PATH.ICON_HERO, heroInfo.icon)
else
self.icon:setSprite(GConst.ATLAS_PATH.COMMON, "common_alpha")
end
self.fragment:setVisible(true)
else
self.icon:setSprite(GConst.ATLAS_PATH.ICON_ITEM, cfg.icon)
self.fragment:setVisible(false)
end
self.mask:setVisible(false)
self.check:setVisible(false)
end
function ItemCell:setTouchEnable(enable)
self:getBaseObject():setTouchEnable(enable == true)
end
function ItemCell:addClickListener(func)
self:getBaseObject():addClickListener(func)
end
function ItemCell:showMask(showMask)
local uiMap = self:getUIMap()
local mask = uiMap["item_cell.mask"]
mask:setVisible(showMask == true)
end
function ItemCell:showCheck(showCheck)
local uiMap = self:getUIMap()
local check = uiMap["item_cell.check"]
check:setVisible(showCheck == true)
end
function ItemCell:showLock(showLock)
end
function ItemCell:setNum(numStr)
local uiMap = self:getUIMap()
local num = uiMap["item_cell.num"]
num:setText(numStr)
end
return ItemCell