local PlayerHeadCell = class("PlayerHeadCell", BaseCell)

function PlayerHeadCell:init()
	local uiMap = self.baseObject:genAllChildren()

    self.imgFrame = uiMap["player_head_cell.img_frame"]
    self.imgAvatar = uiMap["player_head_cell.img_avatar"]
end

-- (avatarId：头像id，frameId：头像框id)
function PlayerHeadCell:refresh(avatarId, frameId, showRp)
    if avatarId == nil or frameId == nil then
        -- 是玩家自己
        avatarId = DataManager.PlayerData:getUsingAvatarId()
        frameId = DataManager.PlayerData:getUsingFrameId()
    end

    -- 背景颜色
    local smallFrame = DataManager.PlayerData:getAvatarBg(avatarId)
    if smallFrame then
        self.baseObject:setSprite(GConst.ATLAS_PATH.ICON_HERO, smallFrame)
    end

    -- 头像
    local avatarName = DataManager.PlayerData:getAvatarIconId(avatarId)
    if avatarName then
        self.imgAvatar:setSprite(GConst.ATLAS_PATH.ICON_HERO, avatarName, function()
            self.imgAvatar:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_IMAGE):SetNativeSize()
        end)
    end

    -- 头像框
    local frameName = DataManager.PlayerData:getFrameIconId(frameId)
    if frameName then
        self.imgFrame:setSprite(GConst.ATLAS_PATH.ICON_AVATAR, frameName, function()
            self.imgFrame:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_IMAGE):SetNativeSize()
        end)
    end

    -- 红点
    if showRp and (DataManager.PlayerData:hasNewAvatar() or DataManager.PlayerData:hasNewFrame()) then
        self.baseObject:addRedPoint(50, 50, 0.7)
    else
        self.baseObject:removeRedPoint()
    end
end


return PlayerHeadCell