整理代码,lang模块功能特化
This commit is contained in:
@@ -12,23 +12,30 @@ local tipMeta={__call=function(L)return L[math.random(#L)]end}
|
|||||||
|
|
||||||
local langList={}
|
local langList={}
|
||||||
local publicText,publicWidgetText={},{}
|
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={}
|
local LANG={}
|
||||||
|
|
||||||
--Must call before LANG.init
|
--Call these before call LANG.init()
|
||||||
function LANG.setLangList(list)langList=list end
|
function LANG.setLangList(list)langList=list end
|
||||||
function LANG.setPublicText(L)publicText=L end
|
function LANG.setPublicText(L)publicText=L end
|
||||||
function LANG.setPublicWidgetText(L)publicWidgetText=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
|
for i=1,#langList do
|
||||||
local L=langList[i]
|
local L=langList[i]
|
||||||
|
|
||||||
--Set public text
|
--Set public text
|
||||||
for key,list in next,publicText do
|
for key,list in next,publicText do
|
||||||
L[key]=list
|
L[key]=list
|
||||||
end
|
end
|
||||||
|
|
||||||
--Set public widget text
|
--Set public widget text
|
||||||
for key,list in next,publicWidgetText do
|
for key,list in next,publicWidgetText do
|
||||||
local WT=L.WidgetText
|
local WT=L.WidgetText
|
||||||
@@ -37,31 +44,24 @@ function LANG.init()
|
|||||||
WT[key][k]=v
|
WT[key][k]=v
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--Fallback to other language, default zh
|
--Fallback to other language, default zh
|
||||||
if i>1 then
|
if i>1 then
|
||||||
langFallback(langList[L.fallback or 1],L)
|
langFallback(langList[L.fallback or 1],L)
|
||||||
end
|
end
|
||||||
|
|
||||||
--Metatable:__call for table:getTip
|
--Metatable:__call for table:getTip
|
||||||
if type(rawget(L,"getTip"))=="table"then
|
if type(rawget(L,"getTip"))=="table"then
|
||||||
setmetatable(L.getTip,tipMeta)
|
setmetatable(L.getTip,tipMeta)
|
||||||
end
|
end
|
||||||
|
|
||||||
--set global name for all back button
|
--set global name for all back button
|
||||||
for _,v in next,L.WidgetText do
|
for _,v in next,L.WidgetText do
|
||||||
v.back=L.back
|
v.back=L.back
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
LANG.init=nil
|
LANG.init,LANG.setLangList,LANG.setPublicText,LANG.setPublicWidgetText=nil
|
||||||
end
|
LANG.set=lang_set
|
||||||
|
|
||||||
function LANG.set(l)
|
|
||||||
text=langList[l]
|
|
||||||
WIDGET.setLang(text.WidgetText)
|
|
||||||
for _,s in next,drawableTextLoad do
|
|
||||||
drawableText[s]:set(text[s])
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return LANG
|
return LANG
|
||||||
@@ -3,12 +3,10 @@ local kb=love.keyboard
|
|||||||
local int,abs=math.floor,math.abs
|
local int,abs=math.floor,math.abs
|
||||||
local max,min=math.max,math.min
|
local max,min=math.max,math.min
|
||||||
local sub,format=string.sub,string.format
|
local sub,format=string.sub,string.format
|
||||||
local ins=table.insert
|
|
||||||
|
|
||||||
local Timer=love.timer.getTime
|
local Timer=love.timer.getTime
|
||||||
local setFont,mStr=setFont,mStr
|
local setFont,mStr=setFont,mStr
|
||||||
|
|
||||||
local widgetList={}
|
|
||||||
local WIDGET={}
|
local WIDGET={}
|
||||||
local widgetMetatable={
|
local widgetMetatable={
|
||||||
__tostring=function(self)
|
__tostring=function(self)
|
||||||
|
|||||||
Reference in New Issue
Block a user