From 8dadc2d54bcff3ebbc56cb71b7b44e9d34efe05c Mon Sep 17 00:00:00 2001 From: ZhangBiao Date: Fri, 5 Mar 2021 14:32:29 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=9C=AC=E5=9C=B0=E5=8C=96=E3=80=91?= =?UTF-8?q?=E9=9A=8F=E6=9C=BA=E5=90=8D=E5=AD=97=E6=9C=AC=E5=9C=B0=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../~Lua/Common/functions.lua | 31 +++++++++++++++++++ .../~Lua/Modules/Popup/CreateNamePopup.lua | 8 +++++ 2 files changed, 39 insertions(+) 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