miduo_client/Assets/ManagedResources/~Lua/Modules/Popup/NameManager.lua

101 lines
3.1 KiB
Lua

local RandomName = ConfigManager.GetConfig(ConfigName.RandomName)
local this = {
roleName = "",
roleSex = ROLE_SEX.BOY
}
local function readonly(t,k,v)
Log(string.format("field \"%s\" is read-only", tostring(k)))
end
local function indexer(t,k)
if not this[k] then
Log(string.format("field \"%s\" not found", tostring(k)))
end
return this[k]
end
function this.Initialize()
end
function this.LateUpdate()
end
function this.SetRoleName(name)
this.roleName = name
end
function this.SetRoleSex(sex)
local str = sex == ROLE_SEX.BOY and Language[11490] or Language[11491]
Log(str)
this.roleSex = sex
end
function this.GetLocalRandomName()
local random1 = math.random(1, RandomName.__count)
local random2 = math.random(1, RandomName.__count)
return GetLanguageStrById(RandomName[random1].Sur_name) .. GetLanguageStrById(RandomName[random2].Name)
end
--得到任意名字数据
function this.GetRandomNameData()
NetManager.GetRandomNameRequest(function(randomName, preName, postName)
if IsLanguagePack then
preName = GetLanguageStrById(preName)
postName = GetLanguageStrById(postName)
if GetCurLanguage() == 1 then
randomName = postName .. preName
elseif GetCurLanguage() == 2 then
randomName = string.gsub(postName, " ", "") -- 使用单独名字去掉中间空格
else
randomName = preName .. postName
end
Game.GlobalEvent:DispatchEvent(GameEvent.Player.OnNameChange, randomName)
else
if randomName ~= "" then
Game.GlobalEvent:DispatchEvent(GameEvent.Player.OnNameChange, randomName)
end
end
end)
end
-- 字符正确性检测
function this.CheckStringRight(str)
if string.find(str, "|") then
return false
end
return true
end
--更改玩家姓名
function this.ChangeUserName(type, name, teamPosId, sex, callBack)
if not this.CheckStringRight(name) then
PopupTipPanel.ShowTip("名称含有敏感字符")
return
end
NetManager.ChangeUserNameRequest(type, name, teamPosId, sex, function()
-- 保存一下老名字,用于上报事件
local oldName = this.roleName
--
this.roleSex = sex
this.roleName = name
PlayerManager.nickName = name
-- 打点静态数据修改
ThinkingAnalyticsManager.SetSuperProperties({
role_name = PlayerManager.nickName,
})
-- 上报改名事件
SubmitExtraData({ type = SDKSubMitType.TYPE_CHANGE_NAME, oldName = oldName })
-- 创建角色时保存一下头像数据
if type == 1 then
local config = ConfigManager.GetConfigDataByKey(ConfigName.PlayerRole, "Role", sex)
PlayerManager.head = config.RolePic
end
Game.GlobalEvent:DispatchEvent(GameEvent.Player.OnChangeName)
if callBack then callBack() end
end)
end
NameManager = {}
setmetatable(NameManager, { __index = indexer, __newindex = readonly })
return NameManager