376 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			Lua
		
	
			
		
		
	
	
			376 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			Lua
		
	
require("Base/BasePanel")
 | 
						|
local HeadChangePopup = Inherit(BasePanel)
 | 
						|
local this = HeadChangePopup
 | 
						|
-- 获取头像框数据, 并排序
 | 
						|
local _HeadFrameList = {}
 | 
						|
local _HeadList = {}
 | 
						|
 | 
						|
-- 头像对象管理
 | 
						|
local _PlayerHeadList = {}
 | 
						|
 | 
						|
-- Tab管理器
 | 
						|
local TabBox = require("Modules/Common/TabBox")
 | 
						|
local _TabFontColor = { default = Color.New(168 / 255, 168 / 255, 167 / 255, 1),
 | 
						|
                        lock = Color.New(168 / 255, 168 / 255, 167 / 255, 1),
 | 
						|
                        select = Color.New(250 / 255, 227 / 255, 175 / 255, 1) }
 | 
						|
local _TabData = {
 | 
						|
    [1] = { default = "r_hero_xuanze_002", lock = "r_hero_xuanze_002", select = "r_hero_xuanze_001", name = Language[11847] , rpType = RedPointType.HeadChange_Head},
 | 
						|
    [2] = { default = "r_hero_xuanze_002", lock = "r_hero_xuanze_002", select = "r_hero_xuanze_001", name = Language[11848] , rpType = RedPointType.HeadChange_Frame}}
 | 
						|
 | 
						|
 | 
						|
local SELECT_TYPE = {
 | 
						|
    HEAD = 1,
 | 
						|
    FRAME = 2,
 | 
						|
}
 | 
						|
 | 
						|
--初始化组件(用于子类重写)
 | 
						|
function HeadChangePopup:InitComponent()
 | 
						|
    this.spLoader = SpriteLoader.New()
 | 
						|
    -- 获取节点
 | 
						|
    this.btnBack = Util.GetGameObject(this.transform, "btnBack")
 | 
						|
    this.title = Util.GetGameObject(this.transform, "Title"):GetComponent("Text")
 | 
						|
    this.content = Util.GetGameObject(this.transform, "content"):GetComponent("Text")
 | 
						|
    this.btnConfirm = Util.GetGameObject(this.transform, "confirm")
 | 
						|
    this.scrollpos = Util.GetGameObject(this.transform, "scrollpos")
 | 
						|
    this.headFrameItem = Util.GetGameObject(this.transform, "scrollpos/item")
 | 
						|
    this.select = Util.GetGameObject(this.transform, "scrollpos/select")
 | 
						|
    this.using = Util.GetGameObject(this.transform, "scrollpos/using")
 | 
						|
 | 
						|
    local height = this.scrollpos.transform.rect.height
 | 
						|
    local width = this.scrollpos.transform.rect.width
 | 
						|
    this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, this.scrollpos.transform,
 | 
						|
            this.headFrameItem, nil, Vector2.New(width, height), 1, 4, Vector2.New(25,40))
 | 
						|
    this.ScrollView.gameObject:GetComponent("RectTransform").anchoredPosition = Vector2.New(0, 0)
 | 
						|
    this.ScrollView.gameObject:GetComponent("RectTransform").anchorMin = Vector2.New(0.5, 0.5)
 | 
						|
    this.ScrollView.gameObject:GetComponent("RectTransform").anchorMax = Vector2.New(0.5, 0.5)
 | 
						|
    this.ScrollView.gameObject:GetComponent("RectTransform").pivot = Vector2.New(0.5, 0.5)
 | 
						|
    this.ScrollView.moveTween.MomentumAmount = 1
 | 
						|
    this.ScrollView.moveTween.Strength = 2
 | 
						|
 | 
						|
    this.tabbox = Util.GetGameObject(this.transform, "top")
 | 
						|
 | 
						|
end
 | 
						|
 | 
						|
--绑定事件(用于子类重写)
 | 
						|
function HeadChangePopup:BindEvent()
 | 
						|
 | 
						|
    -- 初始化Tab管理器
 | 
						|
    this.TabCtrl = TabBox.New()
 | 
						|
    this.TabCtrl:SetTabAdapter(this.TabAdapter)
 | 
						|
    this.TabCtrl:SetTabIsLockCheck(this.TabIsLockCheck)
 | 
						|
    this.TabCtrl:SetChangeTabCallBack(this.OnTabChange)
 | 
						|
    this.TabCtrl:Init(this.tabbox, _TabData)
 | 
						|
 | 
						|
    -- 绑定红点
 | 
						|
    local tabList = this.TabCtrl:GetTabList()
 | 
						|
    for index = 1, #tabList do
 | 
						|
        local tab = tabList[index]
 | 
						|
        local redpot = Util.GetGameObject(tab, "redpot")
 | 
						|
        if _TabData[index].rpType then
 | 
						|
            BindRedPointObject(_TabData[index].rpType, redpot)
 | 
						|
        else
 | 
						|
            redpot:SetActive(false)
 | 
						|
        end
 | 
						|
    end
 | 
						|
 | 
						|
    --
 | 
						|
    Util.AddClick(this.btnBack, function()
 | 
						|
        PlaySoundWithoutClick(SoundConfig.Sound_UICancel)
 | 
						|
        -- 清除当前打开的类型界面全部红点
 | 
						|
        if this.CurSelectType then
 | 
						|
            if this.CurSelectType == SELECT_TYPE.FRAME then
 | 
						|
                HeadManager.RemoveAllNewHead(ItemType.HeadFrame)
 | 
						|
            elseif this.CurSelectType == SELECT_TYPE.HEAD then
 | 
						|
                HeadManager.RemoveAllNewHead(ItemType.Head)
 | 
						|
            end
 | 
						|
        end
 | 
						|
        this:ClosePanel()
 | 
						|
    end)
 | 
						|
 | 
						|
    -- 确认点击确认按钮
 | 
						|
    Util.AddClick(this.btnConfirm, function()
 | 
						|
        -- 请求更换头像框
 | 
						|
        if this.CurSelectType == SELECT_TYPE.FRAME then
 | 
						|
            local frameId = _HeadFrameList[this.CurSelectIndex].Id
 | 
						|
            local num = HeadManager.headFrameData[frameId]
 | 
						|
            if not num then
 | 
						|
                PopupTipPanel.ShowTip(Language[11849])
 | 
						|
                return
 | 
						|
            end
 | 
						|
            NetManager.RequestChangeModifyDecoration(0, frameId, function ()
 | 
						|
                PopupTipPanel.ShowTip(Language[11850])
 | 
						|
                HeadManager.SetCurFrameId(frameId) 
 | 
						|
                Game.GlobalEvent:DispatchEvent(GameEvent.Player.OnHeadFrameChange)
 | 
						|
                this.RefreshCurShow(false,false)
 | 
						|
            end)
 | 
						|
        elseif this.CurSelectType == SELECT_TYPE.HEAD then
 | 
						|
            local headId = _HeadList[this.CurSelectIndex].Id
 | 
						|
            local num = BagManager.GetItemCountById(headId)
 | 
						|
            if num <= 0 then
 | 
						|
                PopupTipPanel.ShowTip(Language[11851])
 | 
						|
                return
 | 
						|
            end
 | 
						|
            NetManager.RequestChangeModifyDecoration(1, headId, function ()
 | 
						|
                PopupTipPanel.ShowTip(Language[11850])
 | 
						|
                PlayerManager.head = headId
 | 
						|
                Game.GlobalEvent:DispatchEvent(GameEvent.Player.OnHeadChange)
 | 
						|
                this.RefreshCurShow(false,false)
 | 
						|
            end)
 | 
						|
        end
 | 
						|
    end)
 | 
						|
 | 
						|
end
 | 
						|
 | 
						|
--添加事件监听(用于子类重写)
 | 
						|
function HeadChangePopup:AddListener()
 | 
						|
 | 
						|
end
 | 
						|
 | 
						|
--移除事件监听(用于子类重写)
 | 
						|
function HeadChangePopup:RemoveListener()
 | 
						|
end
 | 
						|
 | 
						|
--界面打开时调用(用于子类重写)
 | 
						|
function HeadChangePopup:OnOpen(...)
 | 
						|
    _HeadList = HeadManager.GetHeadList()
 | 
						|
    _HeadFrameList = HeadManager.GetHeadFrameList()
 | 
						|
 | 
						|
    if this.TabCtrl then
 | 
						|
        this.TabCtrl:ChangeTab(1)
 | 
						|
    end
 | 
						|
end
 | 
						|
 | 
						|
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
 | 
						|
function HeadChangePopup:OnShow()
 | 
						|
end
 | 
						|
 | 
						|
--
 | 
						|
function HeadChangePopup:OnSortingOrderChange()
 | 
						|
    for _, playerHead in pairs(_PlayerHeadList) do
 | 
						|
        playerHead:SetLayer(self.sortingOrder)
 | 
						|
    end
 | 
						|
end
 | 
						|
 | 
						|
-- tab节点显示自定义
 | 
						|
function this.TabAdapter(tab, index, status)
 | 
						|
    local tabLab = Util.GetGameObject(tab, "Text")
 | 
						|
    Util.GetGameObject(tab,"Img"):GetComponent("Image").sprite = this.spLoader:LoadSprite(_TabData[index][status])
 | 
						|
    tabLab:GetComponent("Text").text = _TabData[index].name
 | 
						|
    tabLab:GetComponent("Text").color = _TabFontColor[status]
 | 
						|
end
 | 
						|
-- tab可用性检测
 | 
						|
function this.TabIsLockCheck(index)
 | 
						|
    --if index == SELECT_TYPE.HEAD then
 | 
						|
    --    return true, "功能尚未开启"
 | 
						|
    --end
 | 
						|
    return false
 | 
						|
end
 | 
						|
-- tab改变回调事件
 | 
						|
function this.OnTabChange(index, lastIndex)
 | 
						|
    -- 切换页签时清除上一个页签的所有红点数据
 | 
						|
    if lastIndex and index ~= lastIndex then
 | 
						|
        if lastIndex == SELECT_TYPE.FRAME then
 | 
						|
            HeadManager.RemoveAllNewHead(ItemType.HeadFrame)
 | 
						|
        elseif lastIndex == SELECT_TYPE.HEAD then
 | 
						|
            HeadManager.RemoveAllNewHead(ItemType.Head)
 | 
						|
        end
 | 
						|
    end
 | 
						|
 | 
						|
    -- 构建数据
 | 
						|
    local datalist = {}
 | 
						|
    local curId = nil
 | 
						|
    if index == SELECT_TYPE.FRAME then
 | 
						|
        datalist = _HeadFrameList
 | 
						|
        --print(#datalist.."     77777")
 | 
						|
        curId = HeadManager.GetCurFrameId()
 | 
						|
        this.title.text = Language[11852]
 | 
						|
    elseif index == SELECT_TYPE.HEAD then
 | 
						|
        datalist = _HeadList
 | 
						|
        curId = PlayerManager.head
 | 
						|
        --print(#datalist.."     88888")
 | 
						|
        this.title.text = Language[11853]
 | 
						|
    end
 | 
						|
    -- 排序
 | 
						|
    table.sort(datalist, function(a, b)
 | 
						|
        -- 使用中的头像在最前面
 | 
						|
        if curId == a.Id then return true end
 | 
						|
        if curId == b.Id then return false end
 | 
						|
        -- 拥有的头像往前放
 | 
						|
        local anum = BagManager.GetItemCountById(a.Id)
 | 
						|
        local bnum = BagManager.GetItemCountById(b.Id)
 | 
						|
        if anum > 0 and bnum <= 0 then return true end
 | 
						|
        if anum <= 0 and bnum > 0 then return false end
 | 
						|
        -- 按id排序
 | 
						|
        return a.Id < b.Id
 | 
						|
    end)
 | 
						|
    --
 | 
						|
    this.CurSelectType = index
 | 
						|
    this.CurSelectIndex = 1
 | 
						|
    this.ScrollView:SetData(datalist, function(index, go)
 | 
						|
        this.HeadFrameItemAdapter(go, datalist[index], index)
 | 
						|
    end,not true,not true)
 | 
						|
    -- this.ScrollView:SetIndex(1)
 | 
						|
end
 | 
						|
 | 
						|
--
 | 
						|
function this.RefreshCurShow(isTop,isAni)
 | 
						|
    local datalist = {}
 | 
						|
    if this.CurSelectType == SELECT_TYPE.FRAME then
 | 
						|
        datalist = _HeadFrameList
 | 
						|
    elseif this.CurSelectType == SELECT_TYPE.HEAD then
 | 
						|
        datalist = _HeadList
 | 
						|
    end
 | 
						|
    this.ScrollView:SetData(datalist, function(index, go)
 | 
						|
        this.HeadFrameItemAdapter(go, datalist[index], index)
 | 
						|
    end,not isTop,not isAni)
 | 
						|
end
 | 
						|
 | 
						|
--
 | 
						|
function this.HeadFrameItemAdapter(item, data, index)
 | 
						|
    local imgRoot = Util.GetGameObject(item, "Img")
 | 
						|
    local name = Util.GetGameObject(item, "name")
 | 
						|
    local redpot = Util.GetGameObject(item, "redpot")
 | 
						|
 | 
						|
    if not _PlayerHeadList[item] then
 | 
						|
        _PlayerHeadList[item] = SubUIManager.Open(SubUIConfig.PlayerHeadView, imgRoot.transform)
 | 
						|
    end
 | 
						|
    _PlayerHeadList[item]:Reset()
 | 
						|
 | 
						|
    if this.CurSelectType == SELECT_TYPE.FRAME then
 | 
						|
        local frameId = data.Id
 | 
						|
        name:GetComponent("Text").text = GetLanguageStrById(data.Name)
 | 
						|
        _PlayerHeadList[item]:SetFrame(frameId)
 | 
						|
        _PlayerHeadList[item]:SetHead(PlayerManager.head)
 | 
						|
        _PlayerHeadList[item]:SetLayer(this.sortingOrder)
 | 
						|
        _PlayerHeadList[item]:SetEffectScale(1.1)
 | 
						|
        if frameId == HeadManager.GetCurFrameId() then
 | 
						|
            this:SetUsing(_PlayerHeadList[item].gameObject)
 | 
						|
        else
 | 
						|
            this:RecycleUsing(_PlayerHeadList[item].gameObject)
 | 
						|
        end
 | 
						|
 | 
						|
        local num = HeadManager.headFrameData[frameId]
 | 
						|
        
 | 
						|
        _PlayerHeadList[item]:SetGray( not num)
 | 
						|
 | 
						|
        redpot:SetActive(num and HeadManager.IsNewHead(frameId))
 | 
						|
 | 
						|
        Util.AddOnceClick(item, function()
 | 
						|
            this.SelectItem(index, item)
 | 
						|
        end)
 | 
						|
    elseif this.CurSelectType == SELECT_TYPE.HEAD then
 | 
						|
        local headId = data.Id
 | 
						|
        name:GetComponent("Text").text = GetLanguageStrById(data.Name)
 | 
						|
        _PlayerHeadList[item]:SetHead(headId)
 | 
						|
        _PlayerHeadList[item]:SetFrame(HeadManager.GetCurFrameId())
 | 
						|
        _PlayerHeadList[item]:SetLayer(this.sortingOrder)
 | 
						|
        _PlayerHeadList[item]:SetEffectScale(1.1)
 | 
						|
        if headId == PlayerManager.head then
 | 
						|
            this:SetUsing(_PlayerHeadList[item].gameObject)
 | 
						|
        else
 | 
						|
            this:RecycleUsing(_PlayerHeadList[item].gameObject)
 | 
						|
        end
 | 
						|
 | 
						|
        local num = BagManager.GetItemCountById(headId)
 | 
						|
        --print(num.."     !!!!!!")
 | 
						|
        _PlayerHeadList[item]:SetGray(num <= 0)
 | 
						|
 | 
						|
        redpot:SetActive(num > 0 and HeadManager.IsNewHead(headId))
 | 
						|
 | 
						|
        Util.AddOnceClick(item, function()
 | 
						|
            this.SelectItem(index, item)
 | 
						|
        end)
 | 
						|
    end
 | 
						|
 | 
						|
    -- 判断选中框的显示
 | 
						|
    if this.CurSelectIndex == index then
 | 
						|
        this.SelectItem(index, item)
 | 
						|
    else
 | 
						|
        local select = Util.GetGameObject(item, "selectroot/select")
 | 
						|
        if select then select:SetActive(false) end
 | 
						|
    end
 | 
						|
end
 | 
						|
 | 
						|
--
 | 
						|
function this.SelectItem(index, item)
 | 
						|
    -- 保存选中的index
 | 
						|
    this.CurSelectIndex = index
 | 
						|
 | 
						|
    -- 显示选中图标
 | 
						|
    this.select:SetActive(true)
 | 
						|
    this.select.transform:SetParent(Util.GetGameObject(item, "selectroot").transform)
 | 
						|
    this.select.transform.localPosition = Vector3.zero
 | 
						|
 | 
						|
 | 
						|
    -- 设置content显示
 | 
						|
    local data = nil
 | 
						|
    local HeadData = nil
 | 
						|
    if this.CurSelectType == SELECT_TYPE.FRAME then
 | 
						|
        data = _HeadFrameList[index]
 | 
						|
        --print(data.Id)
 | 
						|
        HeadData = HeadManager.GetSingleFrame(data.Id)
 | 
						|
    elseif this.CurSelectType == SELECT_TYPE.HEAD then
 | 
						|
        data = _HeadList[index]
 | 
						|
    end
 | 
						|
   
 | 
						|
    if not data then return end
 | 
						|
    if data.Id >=80000 and HeadData and HeadData.validTime - GetTimeStamp() > 0 then
 | 
						|
        -- body
 | 
						|
        this.content.text = GetLanguageStrById(data.ItemDescribe)  ..Language[12173]..TimeStampToDateStr2(HeadData.validTime)
 | 
						|
    else
 | 
						|
        this.content.text = GetLanguageStrById(data.ItemDescribe)
 | 
						|
    end
 | 
						|
     --..",到期时间:"..HeadData.validTime
 | 
						|
 | 
						|
    -- 红点
 | 
						|
    if HeadManager.IsNewHead(data.Id) then
 | 
						|
        HeadManager.SetNotNewHeadAnyMore(data.Id)
 | 
						|
        Util.GetGameObject(item, "redpot"):SetActive(false)
 | 
						|
    end
 | 
						|
end
 | 
						|
 | 
						|
 | 
						|
-- 设置使用中的状态
 | 
						|
function HeadChangePopup:SetUsing(node)
 | 
						|
    local head = Util.GetGameObject(node, "icon")
 | 
						|
    this.using.transform:SetParent(head.transform)
 | 
						|
    this.using.transform.localPosition = Vector3.zero
 | 
						|
    this.using:SetActive(true)
 | 
						|
end
 | 
						|
function HeadChangePopup:RecycleUsing(node)
 | 
						|
    -- 如果node中包含using就回收
 | 
						|
    if node then
 | 
						|
        local using = Util.GetGameObject(node, "icon/using")
 | 
						|
        if not using then return end
 | 
						|
    end
 | 
						|
    this.using.transform:SetParent(this.scrollpos.transform)
 | 
						|
    this.using:SetActive(false)
 | 
						|
end
 | 
						|
 | 
						|
 | 
						|
--界面关闭时调用(用于子类重写)
 | 
						|
function HeadChangePopup:OnClose()
 | 
						|
end
 | 
						|
 | 
						|
--界面销毁时调用(用于子类重写)
 | 
						|
function HeadChangePopup:OnDestroy()
 | 
						|
    this.spLoader:Destroy()
 | 
						|
    this:RecycleUsing()
 | 
						|
    for _, playerHead in pairs(_PlayerHeadList) do
 | 
						|
        playerHead:Recycle()
 | 
						|
    end
 | 
						|
    _PlayerHeadList = {}
 | 
						|
 | 
						|
    this.ScrollView = nil
 | 
						|
 | 
						|
    -- 清除红点绑定
 | 
						|
    for _, v in ipairs(_TabData) do
 | 
						|
        if v.rpType then
 | 
						|
            ClearRedPointObject(v.rpType)
 | 
						|
        end
 | 
						|
    end
 | 
						|
end
 | 
						|
 | 
						|
return HeadChangePopup
 | 
						|
 |