miduo_client/Assets/ManagedResources/~Lua/Modules/Player/HeadManager.lua

256 lines
8.0 KiB
Lua
Raw Normal View History

2021-04-20 13:58:00 +08:00
HeadManager = {}
2020-05-09 13:31:21 +08:00
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
2020-05-09 13:31:21 +08:00
-- 注册事件
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)
2021-04-25 15:27:44 +08:00
local configs = ConfigManager.GetAllConfigsDataByKey(ConfigName.PlayerRole, "Role", NameManager.roleSex)
local curMyHeadList = {}--只做条件判断 没什么用
2020-05-09 13:31:21 +08:00
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
2021-04-25 15:27:44 +08:00
end
else
table.insert(this._MyHeadList, head)
curMyHeadList[head.Id] = head.Id
end
2020-05-09 13:31:21 +08:00
end
end
end
end
return this._MyHeadList
end
-- 获取头像框
function HeadManager.GetHeadFrameList()
if #this._MyHeadFrameList == 0 then
2021-01-18 10:33:32 +08:00
--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
2021-01-18 10:33:32 +08:00
end
2020-05-09 13:31:21 +08:00
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
2021-01-15 21:06:48 +08:00
local playerHeadIcon = ConfigManager.GetConfig(ConfigName.PlayerHeadIcon)
this.headFrameData = {}
--获取后端传来的数据 加以修改
function HeadManager.SetHeadFrameAllData(data)
this.headFrameData = {}
if #data > 0 then
for i = 1, #data do
2021-07-01 16:33:40 +08:00
Log("头像框ID".. data[i].headFrameId.." 时间:"..data[i].validTime )
2021-01-15 21:06:48 +08:00
local single_data = {}
single_data.headFrameId = data[i].headFrameId
single_data.validTime = data[i].validTime
2021-01-18 10:33:32 +08:00
single_data.PlayerHeadIcon = ConfigManager.GetConfigDataByKey(ConfigName.PlayerHeadIcon,"Id",single_data.headFrameId)
2021-01-15 21:06:48 +08:00
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
2021-07-01 16:33:40 +08:00
Log("头像框ID".. headFrameId.." 时间:"..time )
2021-01-18 10:33:32 +08:00
single_data.PlayerHeadIcon = ConfigManager.GetConfigDataByKey(ConfigName.PlayerHeadIcon,"Id",single_data.headFrameId)
2021-01-15 21:06:48 +08:00
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
2021-01-18 15:07:23 +08:00
function HeadManager.SetCurFrameId(frame)
PlayerManager.frame= frame
end
2020-05-09 13:31:21 +08:00
2021-01-15 21:06:48 +08:00
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
2021-01-18 15:07:23 +08:00
HeadManager.SetCurFrameId(80000)
return PlayerManager.frame
2021-01-15 21:06:48 +08:00
end
-- 头像id转英雄id
function HeadManager.HeadIdToHeroId(headId)
if headId then
return this._HeadToHero[headId]
end
end
2020-06-23 18:36:24 +08:00
return HeadManager