256 lines
8.0 KiB
Lua
256 lines
8.0 KiB
Lua
HeadManager = {}
|
||
local this = HeadManager
|
||
|
||
this._NewHeadList = {}
|
||
|
||
local _HeadConfig = {
|
||
[ItemType.HeadFrame] = {prefKey = "PlayerNewFrame", rpType = RedPointType.HeadChange_Frame},
|
||
[ItemType.Head] = {prefKey = "PlayerNewHead", rpType = RedPointType.HeadChange_Head},
|
||
}
|
||
|
||
function HeadManager.Initialize()
|
||
|
||
this._MyHeadList = {}
|
||
this._MyHeadFrameList = {}
|
||
|
||
-- 初始化头像和英雄的对应关系
|
||
this._HeadToHero = {}
|
||
local Heros = ConfigManager.TryGetAllConfigsDataByKey(ConfigName.ItemConfig, "ItemType", ItemType.Hero)
|
||
for _, data in ipairs(Heros) do
|
||
if data.ExtraReward and data.ExtraReward[2] then
|
||
local headId = data.ExtraReward[2][1]
|
||
this._HeadToHero[headId] = data.Id
|
||
end
|
||
end
|
||
|
||
-- 注册事件
|
||
Game.GlobalEvent:AddEvent(GameEvent.Bag.GetNewItem, this.OnNewItem)
|
||
end
|
||
|
||
|
||
function HeadManager.InitData()
|
||
this._NewHeadList = {}
|
||
-- 本地数据初始化
|
||
for type, config in pairs(_HeadConfig) do
|
||
local dataStr = PlayerPrefs.GetString(config.prefKey..PlayerManager.uid)
|
||
if dataStr == "" then
|
||
this._NewHeadList[type] = {}
|
||
else
|
||
this._NewHeadList[type] = string.split(dataStr, "|")
|
||
end
|
||
end
|
||
end
|
||
|
||
-- 获取新物品
|
||
function this.OnNewItem(itemId)
|
||
local itemInfo = ConfigManager.GetConfigData(ConfigName.ItemConfig, itemId)
|
||
local type = itemInfo.ItemType
|
||
|
||
-- 判断是否是头像相关的类型
|
||
local config = _HeadConfig[type]
|
||
if not config then return end
|
||
|
||
if not this._NewHeadList then
|
||
this._NewHeadList = {}
|
||
end
|
||
if not this._NewHeadList[type] then
|
||
this._NewHeadList[type] = {}
|
||
end
|
||
-- 保存数据
|
||
table.insert(this._NewHeadList[type], itemId)
|
||
-- 检测红点
|
||
if config.rpType then
|
||
CheckRedPointStatus(config.rpType)
|
||
end
|
||
-- 本地保存数据
|
||
local str = table.concat(this._NewHeadList[type], "|")
|
||
PlayerPrefs.SetString(config.prefKey..PlayerManager.uid, str)
|
||
end
|
||
|
||
-- 获取头像
|
||
function HeadManager.GetHeadList()
|
||
if #this._MyHeadList == 0 then
|
||
local AllHeadList = ConfigManager.GetAllConfigsDataByKey(ConfigName.ItemConfig, "ItemType", ItemType.Head)
|
||
local configs = ConfigManager.GetAllConfigsDataByKey(ConfigName.PlayerRole, "Role", NameManager.roleSex)
|
||
local curMyHeadList = {}--只做条件判断 没什么用
|
||
for _, head in ipairs(AllHeadList) do
|
||
if head.Ifopen == 1 then
|
||
-- 判断神将是否进入版本
|
||
local heroId = this.HeadIdToHeroId(head.Id)
|
||
if not heroId or HeroManager.InVersion(heroId) then
|
||
if head.Name == Language[11393] then
|
||
for i = 1, #configs do
|
||
if configs[i].RolePic == head.Id and not curMyHeadList[head.Id] then
|
||
table.insert(this._MyHeadList, head)
|
||
curMyHeadList[head.Id] = head.Id
|
||
end
|
||
end
|
||
else
|
||
table.insert(this._MyHeadList, head)
|
||
curMyHeadList[head.Id] = head.Id
|
||
end
|
||
end
|
||
end
|
||
end
|
||
end
|
||
return this._MyHeadList
|
||
end
|
||
|
||
-- 获取头像框
|
||
function HeadManager.GetHeadFrameList()
|
||
if #this._MyHeadFrameList == 0 then
|
||
--this._MyHeadFrameList = ConfigManager.GetConfig(ConfigName.PlayerHeadIcon) --ConfigManager.GetAllConfigsDataByDoubleKey(ConfigName.ItemConfig, "ItemType", ItemType.HeadFrame, "Ifopen", 1)
|
||
for key, value in ConfigPairs(ConfigManager.GetConfig(ConfigName.PlayerHeadIcon)) do
|
||
if value.Type == 2 then
|
||
table.insert(this._MyHeadFrameList,value)
|
||
end
|
||
end
|
||
end
|
||
return this._MyHeadFrameList
|
||
end
|
||
|
||
-- 判断是否是新头像
|
||
function HeadManager.IsNewHead(id)
|
||
-- 无数据
|
||
if not this._NewHeadList then
|
||
return false
|
||
end
|
||
-- 无类型数据
|
||
local itemInfo = ConfigManager.GetConfigData(ConfigName.ItemConfig, id)
|
||
if not this._NewHeadList[itemInfo.ItemType] then
|
||
return false
|
||
end
|
||
-- 遍历查找
|
||
for _, newFrameId in ipairs(this._NewHeadList[itemInfo.ItemType]) do
|
||
if tonumber(newFrameId) == id then
|
||
return true
|
||
end
|
||
end
|
||
return false
|
||
end
|
||
|
||
-- 设置已经不是新头像了
|
||
function HeadManager.SetNotNewHeadAnyMore(id)
|
||
if not this._NewHeadList then
|
||
return
|
||
end
|
||
local itemInfo = ConfigManager.GetConfigData(ConfigName.ItemConfig, id)
|
||
local type = itemInfo.ItemType
|
||
if not this._NewHeadList[type] then
|
||
return
|
||
end
|
||
|
||
local index = nil
|
||
for i, newId in ipairs(this._NewHeadList[type]) do
|
||
if tonumber(newId) == id then
|
||
index = i
|
||
break
|
||
end
|
||
end
|
||
if not index then return end
|
||
|
||
table.remove(this._NewHeadList[type], index)
|
||
-- 检测红点
|
||
local config = _HeadConfig[type]
|
||
if config and config.rpType then
|
||
CheckRedPointStatus(config.rpType)
|
||
end
|
||
-- 本地保存数据
|
||
local str = table.concat(this._NewHeadList[type], "|")
|
||
PlayerPrefs.SetString(config.prefKey..PlayerManager.uid, str)
|
||
end
|
||
|
||
-- 删除所有新头像数据,清空所有红点
|
||
function HeadManager.RemoveAllNewHead(type)
|
||
if not this._NewHeadList[type] then
|
||
return
|
||
end
|
||
if #this._NewHeadList[type] == 0 then
|
||
return
|
||
end
|
||
this._NewHeadList[type] = {}
|
||
-- 检测红点
|
||
local config = _HeadConfig[type]
|
||
if config and config.rpType then
|
||
CheckRedPointStatus(config.rpType)
|
||
end
|
||
-- 本地保存数据
|
||
local str = table.concat(this._NewHeadList[type], "|")
|
||
PlayerPrefs.SetString(config.prefKey..PlayerManager.uid, str)
|
||
end
|
||
|
||
|
||
-- 头像框红点判断
|
||
function HeadManager.CheckHeadRedPot(rpType)
|
||
local list = nil
|
||
if rpType == RedPointType.HeadChange_Frame then
|
||
list = this._NewHeadList[ItemType.HeadFrame]
|
||
elseif rpType == RedPointType.HeadChange_Head then
|
||
list = this._NewHeadList[ItemType.Head]
|
||
end
|
||
if list and #list > 0 then
|
||
return true
|
||
end
|
||
return false
|
||
end
|
||
|
||
local playerHeadIcon = ConfigManager.GetConfig(ConfigName.PlayerHeadIcon)
|
||
this.headFrameData = {}
|
||
--获取后端传来的数据 加以修改
|
||
function HeadManager.SetHeadFrameAllData(data)
|
||
this.headFrameData = {}
|
||
if #data > 0 then
|
||
for i = 1, #data do
|
||
Log("头像框ID:".. data[i].headFrameId.." 时间:"..data[i].validTime )
|
||
local single_data = {}
|
||
single_data.headFrameId = data[i].headFrameId
|
||
single_data.validTime = data[i].validTime
|
||
single_data.PlayerHeadIcon = ConfigManager.GetConfigDataByKey(ConfigName.PlayerHeadIcon,"Id",single_data.headFrameId)
|
||
this.headFrameData[single_data.headFrameId] = single_data
|
||
end
|
||
-- body
|
||
end
|
||
end
|
||
|
||
function HeadManager.SetSineleHeadFrameAllData(headFrameId,time)
|
||
local single_data = {}
|
||
single_data.headFrameId = headFrameId
|
||
single_data.validTime = time
|
||
Log("头像框ID:".. headFrameId.." 时间:"..time )
|
||
single_data.PlayerHeadIcon = ConfigManager.GetConfigDataByKey(ConfigName.PlayerHeadIcon,"Id",single_data.headFrameId)
|
||
this.headFrameData[single_data.headFrameId] = single_data
|
||
end
|
||
|
||
function HeadManager.GetSingleFrame(Did)
|
||
if this.headFrameData[Did] then
|
||
-- body
|
||
return this.headFrameData[Did]
|
||
else
|
||
return nil
|
||
end
|
||
end
|
||
function HeadManager.SetCurFrameId(frame)
|
||
PlayerManager.frame= frame
|
||
end
|
||
|
||
function HeadManager.GetCurFrameId()
|
||
local freameData = this.headFrameData[PlayerManager.frame]
|
||
if freameData then
|
||
if (freameData.validTime > 0 and freameData.validTime > GetTimeStamp()) or freameData.validTime <= 0 then
|
||
return PlayerManager.frame
|
||
else
|
||
this.headFrameData[PlayerManager.frame] = nil
|
||
end
|
||
end
|
||
HeadManager.SetCurFrameId(80000)
|
||
return PlayerManager.frame
|
||
end
|
||
|
||
-- 头像id转英雄id
|
||
function HeadManager.HeadIdToHeroId(headId)
|
||
if headId then
|
||
return this._HeadToHero[headId]
|
||
end
|
||
end
|
||
|
||
return HeadManager |