local EquipCell = class("EquipCell", BaseCell)

function EquipCell:refresh(entity, showMask, showLv)
	local uiMap = self:getUIMap()
	local bg = uiMap["equip_cell.frame_bg"]
	local icon = uiMap["equip_cell.icon"]
	local partBg = uiMap["equip_cell.part_bg"]
	local mask = uiMap["equip_cell.mask"]
	local partIcon = uiMap["equip_cell.part_bg.icon"]
	local lvTx = uiMap["equip_cell.lv_tx"]

	bg:setSprite(entity:getFrameRes())
	icon:setSprite(entity:getIconRes())
	partBg:setSprite(entity:getPartBgRes())
	partIcon:setSprite(entity:getPartRes())
	lvTx:setText(I18N:getGlobalText(I18N.GlobalConst.LV_POINT, entity:getLv()))

	icon:setVisible(true)
	partBg:setVisible(true)
	mask:setVisible(showMask == true)
	lvTx:setVisible(showLv)
end

function EquipCell:refreshByCfg(id, showMask)
	local cfg = ConfigManager:getConfig("equip")[id]
	if not cfg then
		return
	end
	local uiMap = self:getUIMap()
	local bg = uiMap["equip_cell.frame_bg"]
	local icon = uiMap["equip_cell.icon"]
	local partBg = uiMap["equip_cell.part_bg"]
	local partIcon = uiMap["equip_cell.part_bg.icon"]
	local mask = uiMap["equip_cell.mask"]
	local lvTx = uiMap["equip_cell.lv_tx"]

	bg:setSprite(GConst.ATLAS_PATH.ICON_EQUIP, "frame_" .. cfg.qlt)
	icon:setSprite(GFunc.getEquipIconRes(id))
	partBg:setSprite(GConst.ATLAS_PATH.ICON_EQUIP, "type_" .. cfg.qlt)
	partIcon:setSprite(GConst.ATLAS_PATH.ICON_EQUIP, "e" .. cfg.part)

	icon:setVisible(true)
	partBg:setVisible(true)
	mask:setVisible(showMask == true)
	lvTx:setVisible(false)
end

function EquipCell:refreshByPart(part)
	local uiMap = self:getUIMap()
	local bg = uiMap["equip_cell.frame_bg"]
	local icon = uiMap["equip_cell.icon"]
	local partBg = uiMap["equip_cell.part_bg"]
	local mask = uiMap["equip_cell.mask"]
	local lvTx = uiMap["equip_cell.lv_tx"]

	bg:setSprite(GConst.ATLAS_PATH.ICON_EQUIP, "frame_empty")
	icon:setSprite(GConst.ATLAS_PATH.ICON_EQUIP, "empty_" .. part)

	icon:setVisible(true)
	partBg:setVisible(false)
	mask:setVisible(false)
	lvTx:setVisible(false)
end

function EquipCell:setTouchEnable(enable)
	self:getBaseObject():setTouchEnable(enable == true)
end

function EquipCell:addClickListener(func)
    self:getBaseObject():addClickListener(func)
end

function EquipCell:getAnchoredPositionX()
    return self:getBaseObject():getAnchoredPositionX()
end

function EquipCell:setVisible(visible, scale)
	self:getBaseObject():setVisible(visible, scale)
end

function EquipCell:setActive(active)
	self:getBaseObject():setActive(active)
end

function EquipCell:addRedPoint(posX, posY, scale)
	self:getBaseObject():addRedPoint(posX, posY, scale)
end

function EquipCell:removeRedPoint()
	self:getBaseObject():removeRedPoint()
end

return EquipCell
