diff --git a/Assets/ManagedResources/~Lua/Common/functions.lua b/Assets/ManagedResources/~Lua/Common/functions.lua index 3f2796e72a..673a28cdb3 100644 --- a/Assets/ManagedResources/~Lua/Common/functions.lua +++ b/Assets/ManagedResources/~Lua/Common/functions.lua @@ -1635,6 +1635,37 @@ function LengthString(inputstr) end return width end + +--获取中文一段话的所有单个文字 +function GetSingleWordInString(inputstr) + if not inputstr or inputstr == "" then + return + end + local lenInByte = #inputstr + local width = 0 + local i = 1 + local outputstr={} + while (i<=lenInByte) + do + local curByte = string.byte(inputstr, i) + local byteCount = 1; + if curByte>0 and curByte<=127 then + byteCount = 1 --1字节字符 + elseif curByte>=192 and curByte<223 then + byteCount = 2 --双字节字符 + elseif curByte>=224 and curByte<239 then + byteCount = 3 --汉字 + elseif curByte>=240 and curByte<=247 then + byteCount = 4 --4字节字符 + end + local char = string.sub(inputstr, i, i+byteCount-1) + outputstr[width+1] = char + i = i + byteCount -- 重置下一字节的索引 + width = width + 1 + end + return outputstr +end + --都截取长度 function SubString(inputstr,num) local num = num and num or 0 diff --git a/Assets/ManagedResources/~Lua/Modules/Popup/CreateNamePopup.lua b/Assets/ManagedResources/~Lua/Modules/Popup/CreateNamePopup.lua index 91cf2651cf..a6d547c330 100644 --- a/Assets/ManagedResources/~Lua/Modules/Popup/CreateNamePopup.lua +++ b/Assets/ManagedResources/~Lua/Modules/Popup/CreateNamePopup.lua @@ -229,6 +229,14 @@ end -- 随机名称显示 function CreateNamePopup.OnRefreshName(randomName) + if GetCurLanguage() ~= 0 then + local str = GetSingleWordInString(randomName) + if LengthOfTable(str) == 3 then + randomName = GetLanguageStrById(str[1])..GetLanguageStrById(str[2]..str[3]) + elseif LengthOfTable(str) == 4 then + randomName = GetLanguageStrById(str[1]..str[2])..GetLanguageStrById(str[3]..str[4]) + end + end this.textName.text = randomName or "" this.textNameNew.text = randomName or "" end