From 123e453bd2f54bd4ddf45897a2ed680588f80fb6 Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Wed, 9 Dec 2020 00:49:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81=EF=BC=8Cla?= =?UTF-8?q?ng=E6=A8=A1=E5=9D=97=E5=8A=9F=E8=83=BD=E7=89=B9=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zframework/languages.lua | 32 ++++++++++++++++---------------- Zframework/widget.lua | 2 -- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/Zframework/languages.lua b/Zframework/languages.lua index 715c3110..158d0ff9 100644 --- a/Zframework/languages.lua +++ b/Zframework/languages.lua @@ -12,23 +12,30 @@ local tipMeta={__call=function(L)return L[math.random(#L)]end} local langList={} local publicText,publicWidgetText={},{} +local function lang_set(l) + text=langList[l] + WIDGET.setLang(text.WidgetText) + for _,s in next,drawableTextLoad do + drawableText[s]:set(text[s]) + end +end local LANG={} ---Must call before LANG.init +--Call these before call LANG.init() function LANG.setLangList(list)langList=list end function LANG.setPublicText(L)publicText=L end function LANG.setPublicWidgetText(L)publicWidgetText=L end -function LANG.init() +function LANG.init()--Attention, calling this will DESTORY ALL METHODS, only left LANG.set()! for i=1,#langList do local L=langList[i] - + --Set public text for key,list in next,publicText do L[key]=list end - + --Set public widget text for key,list in next,publicWidgetText do local WT=L.WidgetText @@ -37,31 +44,24 @@ function LANG.init() WT[key][k]=v end end - + --Fallback to other language, default zh if i>1 then langFallback(langList[L.fallback or 1],L) end - + --Metatable:__call for table:getTip if type(rawget(L,"getTip"))=="table"then setmetatable(L.getTip,tipMeta) end - + --set global name for all back button for _,v in next,L.WidgetText do v.back=L.back end end - LANG.init=nil -end - -function LANG.set(l) - text=langList[l] - WIDGET.setLang(text.WidgetText) - for _,s in next,drawableTextLoad do - drawableText[s]:set(text[s]) - end + LANG.init,LANG.setLangList,LANG.setPublicText,LANG.setPublicWidgetText=nil + LANG.set=lang_set end return LANG \ No newline at end of file diff --git a/Zframework/widget.lua b/Zframework/widget.lua index 69ee305c..f6bbb49e 100644 --- a/Zframework/widget.lua +++ b/Zframework/widget.lua @@ -3,12 +3,10 @@ local kb=love.keyboard local int,abs=math.floor,math.abs local max,min=math.max,math.min local sub,format=string.sub,string.format -local ins=table.insert local Timer=love.timer.getTime local setFont,mStr=setFont,mStr -local widgetList={} local WIDGET={} local widgetMetatable={ __tostring=function(self)