语言/控件系统升级,移除LANG.setPublicText

This commit is contained in:
MrZ626
2021-01-13 02:10:41 +08:00
parent ecd8354d8f
commit 1a212fb64b
8 changed files with 83 additions and 128 deletions

View File

@@ -1,10 +1,10 @@
local langList,publicText,publicWidgetText={},{},{}
local lang = require "parts.scenes.lang"
local langList,publicText={},{}
local LANG={}
--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()--Attention, calling this will destory all initializing methods, create a LANG.set()!
local function langFallback(T0,T)
@@ -27,15 +27,6 @@ function LANG.init()--Attention, calling this will destory all initializing meth
L[key]=list
end
--Set public widget text
for key,list in next,publicWidgetText do
local WT=L.WidgetText
if not WT[key]then WT[key]={}end
for k,v in next,list do
WT[key][k]=v
end
end
--Fallback to other language, default zh
if i>1 then
langFallback(langList[L.fallback or 1],L)
@@ -52,7 +43,7 @@ function LANG.init()--Attention, calling this will destory all initializing meth
end
end
LANG.init,LANG.setLangList,LANG.setPublicText,LANG.setPublicWidgetText=nil
LANG.init,LANG.setLangList,LANG.setPublicText=nil
function LANG.set(l)
text=langList[l]
@@ -63,6 +54,14 @@ function LANG.init()--Attention, calling this will destory all initializing meth
end
end
end
function LANG.addScene(name)
for i=1,#langList do
if langList[i].WidgetText and not langList[i].WidgetText[name]then
langList[i].WidgetText[name]={back=langList[i].back}
end
end
end
end
return LANG

View File

@@ -837,10 +837,8 @@ function WIDGET.set(list)
end
function WIDGET.setLang(widgetText)
for S,L in next,SCN.scenes do
if widgetText[S]then
for _,W in next,L.widgetList do
W.text=W.fText or widgetText[S][W.name]
end
for _,W in next,L.widgetList do
W.text=W.fText or widgetText[S][W.name]
end
end
end

View File

@@ -216,7 +216,6 @@ LANG.setLangList{
--1. Add language file to LANG folder;
--2. Require it;
--3. Add a button in parts/scenes/setting_lang.lua;
--4. Set button name at LANG.setPublicWidgetText.lang beneath.
}
LANG.setPublicText{
block={
@@ -227,48 +226,6 @@ LANG.setPublicText{
"I3","C","I2","O1"
},
}
LANG.setPublicWidgetText{
calculator={
_1="1",_2="2",_3="3",
_4="4",_5="5",_6="6",
_7="7",_8="8",_9="9",
_0="0",["."]=".",e="e",
["+"]="+",["-"]="-",["*"]="*",["/"]="/",
["<"]="<",["="]="=",
play="-->",
},
setting_skin={
prev="",next="",
prev1="",next1="",
prev2="",next2="",
prev3="",next3="",
prev4="",next4="",
prev5="",next5="",
prev6="",next6="",
prev7="",next7="",
},
custom_field={
b0="",b1="",b2="",b3="",b4="",b5="",b6="",b7="",
b8="",b9="",b10="",b11="",b12="",b13="",b14="",b15="",b16="",
b17="[ ]",b18="N",b19="B",b20="_",b21="_",b22="_",b23="_",b24="_",
},
lang={
zh="中文",
zh2="全中文",
en="English",
fr="Français",
sp="Español",
pt="Português",
symbol="?????",
yygq="就这?",
},
staff={},
history={
prev="",
next="",
},
mg_cubefield={},
}
LANG.init()
--Load shader files from SOURCE ONLY
@@ -299,6 +256,7 @@ for _,v in next,fs.getDirectoryItems("parts/scenes")do
if fs.getRealDirectory("parts/scenes/"..v)~=SAVEDIR then
local sceneName=v:sub(1,-5)
SCN.add(sceneName,require("parts/scenes/"..sceneName))
LANG.addScene(sceneName)
else
LOG.print("Dangerous file : %SAVE%/parts/scenes/"..v)
end

View File

@@ -128,25 +128,25 @@ function scene.draw()
end
scene.widgetList={
WIDGET.newKey{name="_1",x=150,y=300,w=90, font=50,code=pressKey"1"},
WIDGET.newKey{name="_2",x=250,y=300,w=90, font=50,code=pressKey"2"},
WIDGET.newKey{name="_3",x=350,y=300,w=90, font=50,code=pressKey"3"},
WIDGET.newKey{name="_4",x=150,y=400,w=90, font=50,code=pressKey"4"},
WIDGET.newKey{name="_5",x=250,y=400,w=90, font=50,code=pressKey"5"},
WIDGET.newKey{name="_6",x=350,y=400,w=90, font=50,code=pressKey"6"},
WIDGET.newKey{name="_7",x=150,y=500,w=90, font=50,code=pressKey"7"},
WIDGET.newKey{name="_8",x=250,y=500,w=90, font=50,code=pressKey"8"},
WIDGET.newKey{name="_9",x=350,y=500,w=90, font=50,code=pressKey"9"},
WIDGET.newKey{name="_0",x=150,y=600,w=90, font=50,code=pressKey"0"},
WIDGET.newKey{name=".", x=250,y=600,w=90,color="lPurple",font=50,code=pressKey"."},
WIDGET.newKey{name="e", x=350,y=600,w=90,color="lPurple",font=50,code=pressKey"e"},
WIDGET.newKey{name="+", x=450,y=300,w=90,color="lBlue", font=50,code=pressKey"+"},
WIDGET.newKey{name="-", x=450,y=400,w=90,color="lBlue", font=50,code=pressKey"-"},
WIDGET.newKey{name="*", x=450,y=500,w=90,color="lBlue", font=50,code=pressKey"*"},
WIDGET.newKey{name="/", x=450,y=600,w=90,color="lBlue", font=50,code=pressKey"/"},
WIDGET.newKey{name="<", x=550,y=300,w=90,color="lRed", font=50,code=pressKey"backspace"},
WIDGET.newKey{name="=", x=550,y=400,w=90,color="lYellow",font=50,code=pressKey"return"},
WIDGET.newButton{name="play",x=640,y=600,w=180,h=90,color="lGreen",font=40,code=pressKey"space",hide=function()return not pass end},
WIDGET.newKey{name="_1",x=150,y=300,w=90,fText="1",font=50,code=pressKey"1"},
WIDGET.newKey{name="_2",x=250,y=300,w=90,fText="2",font=50,code=pressKey"2"},
WIDGET.newKey{name="_3",x=350,y=300,w=90,fText="3",font=50,code=pressKey"3"},
WIDGET.newKey{name="_4",x=150,y=400,w=90,fText="4",font=50,code=pressKey"4"},
WIDGET.newKey{name="_5",x=250,y=400,w=90,fText="5",font=50,code=pressKey"5"},
WIDGET.newKey{name="_6",x=350,y=400,w=90,fText="6",font=50,code=pressKey"6"},
WIDGET.newKey{name="_7",x=150,y=500,w=90,fText="7",font=50,code=pressKey"7"},
WIDGET.newKey{name="_8",x=250,y=500,w=90,fText="8",font=50,code=pressKey"8"},
WIDGET.newKey{name="_9",x=350,y=500,w=90,fText="9",font=50,code=pressKey"9"},
WIDGET.newKey{name="_0",x=150,y=600,w=90,fText="0",font=50,code=pressKey"0"},
WIDGET.newKey{name=".", x=250,y=600,w=90,fText=".",color="lPurple", font=50,code=pressKey"."},
WIDGET.newKey{name="e", x=350,y=600,w=90,fText="e",color="lPurple", font=50,code=pressKey"e"},
WIDGET.newKey{name="+", x=450,y=300,w=90,fText="+",color="lBlue", font=50,code=pressKey"+"},
WIDGET.newKey{name="-", x=450,y=400,w=90,fText="-",color="lBlue", font=50,code=pressKey"-"},
WIDGET.newKey{name="*", x=450,y=500,w=90,fText="*",color="lBlue", font=50,code=pressKey"*"},
WIDGET.newKey{name="/", x=450,y=600,w=90,fText="/",color="lBlue", font=50,code=pressKey"/"},
WIDGET.newKey{name="<", x=550,y=300,w=90,fText="<",color="lRed", font=50,code=pressKey"backspace"},
WIDGET.newKey{name="=", x=550,y=400,w=90,fText="=",color="lYellow",font=50,code=pressKey"return"},
WIDGET.newButton{name="play",x=640,y=600,w=180,h=90,fText="-->",color="lGreen",font=40,code=pressKey"space",hide=function()return not pass end},
}
return scene

View File

@@ -247,32 +247,32 @@ scene.widgetList={
WIDGET.newText{name="title", x=1020,y=5,font=70,align="R"},
WIDGET.newText{name="subTitle", x=1030,y=50,font=35,align="L",color="grey"},
WIDGET.newButton{name="b1", x=580, y=130,w=75,color=COLOR.red, code=setPen(1)},--B1
WIDGET.newButton{name="b2", x=660, y=130,w=75,color=COLOR.fire, code=setPen(2)},--B2
WIDGET.newButton{name="b3", x=740, y=130,w=75,color=COLOR.orange, code=setPen(3)},--B3
WIDGET.newButton{name="b4", x=820, y=130,w=75,color=COLOR.yellow, code=setPen(4)},--B4
WIDGET.newButton{name="b5", x=900, y=130,w=75,color=COLOR.lame, code=setPen(5)},--B5
WIDGET.newButton{name="b6", x=980, y=130,w=75,color=COLOR.grass, code=setPen(6)},--B6
WIDGET.newButton{name="b7", x=1060, y=130,w=75,color=COLOR.green, code=setPen(7)},--B7
WIDGET.newButton{name="b8", x=1140, y=130,w=75,color=COLOR.water, code=setPen(8)},--B8
WIDGET.newButton{name="b1", x=580, y=130,w=75,fText="",color=COLOR.red, code=setPen(1)},--B1
WIDGET.newButton{name="b2", x=660, y=130,w=75,fText="",color=COLOR.fire, code=setPen(2)},--B2
WIDGET.newButton{name="b3", x=740, y=130,w=75,fText="",color=COLOR.orange, code=setPen(3)},--B3
WIDGET.newButton{name="b4", x=820, y=130,w=75,fText="",color=COLOR.yellow, code=setPen(4)},--B4
WIDGET.newButton{name="b5", x=900, y=130,w=75,fText="",color=COLOR.lame, code=setPen(5)},--B5
WIDGET.newButton{name="b6", x=980, y=130,w=75,fText="",color=COLOR.grass, code=setPen(6)},--B6
WIDGET.newButton{name="b7", x=1060, y=130,w=75,fText="",color=COLOR.green, code=setPen(7)},--B7
WIDGET.newButton{name="b8", x=1140, y=130,w=75,fText="",color=COLOR.water, code=setPen(8)},--B8
WIDGET.newButton{name="b9", x=580, y=210,w=75,color=COLOR.cyan, code=setPen(9)},--B9
WIDGET.newButton{name="b10", x=660, y=210,w=75,color=COLOR.sky, code=setPen(10)},--B10
WIDGET.newButton{name="b11", x=740, y=210,w=75,color=COLOR.sea, code=setPen(11)},--B11
WIDGET.newButton{name="b12", x=820, y=210,w=75,color=COLOR.blue, code=setPen(12)},--B12
WIDGET.newButton{name="b13", x=900, y=210,w=75,color=COLOR.purple, code=setPen(13)},--B13
WIDGET.newButton{name="b14", x=980, y=210,w=75,color=COLOR.grape, code=setPen(14)},--B14
WIDGET.newButton{name="b15", x=1060, y=210,w=75,color=COLOR.magenta, code=setPen(15)},--B15
WIDGET.newButton{name="b16", x=1140, y=210,w=75,color=COLOR.pink, code=setPen(16)},--B16
WIDGET.newButton{name="b9", x=580, y=210,w=75,fText="",color=COLOR.cyan, code=setPen(9)},--B9
WIDGET.newButton{name="b10", x=660, y=210,w=75,fText="",color=COLOR.sky, code=setPen(10)},--B10
WIDGET.newButton{name="b11", x=740, y=210,w=75,fText="",color=COLOR.sea, code=setPen(11)},--B11
WIDGET.newButton{name="b12", x=820, y=210,w=75,fText="",color=COLOR.blue, code=setPen(12)},--B12
WIDGET.newButton{name="b13", x=900, y=210,w=75,fText="",color=COLOR.purple, code=setPen(13)},--B13
WIDGET.newButton{name="b14", x=980, y=210,w=75,fText="",color=COLOR.grape, code=setPen(14)},--B14
WIDGET.newButton{name="b15", x=1060, y=210,w=75,fText="",color=COLOR.magenta,code=setPen(15)},--B15
WIDGET.newButton{name="b16", x=1140, y=210,w=75,fText="",color=COLOR.pink, code=setPen(16)},--B16
WIDGET.newButton{name="b17", x=580, y=290,w=75,color="dGrey", code=setPen(17)},--BONE
WIDGET.newButton{name="b18", x=660, y=290,w=75,color="black", code=setPen(18)},--HIDE
WIDGET.newButton{name="b19", x=740, y=290,w=75,color="lYellow", code=setPen(19)},--BOMB
WIDGET.newButton{name="b20", x=820, y=290,w=75,color="grey", code=setPen(20)},--GB1
WIDGET.newButton{name="b21", x=900, y=290,w=75,color="lGrey", code=setPen(21)},--GB2
WIDGET.newButton{name="b22", x=980, y=290,w=75,color="dPurple", code=setPen(22)},--GB3
WIDGET.newButton{name="b23", x=1060, y=290,w=75,color="dRed", code=setPen(23)},--GB4
WIDGET.newButton{name="b24", x=1140, y=290,w=75,color="dGreen", code=setPen(24)},--GB5
WIDGET.newButton{name="b17", x=580, y=290,w=75,fText="[ ]",color="dGrey", code=setPen(17)},--BONE
WIDGET.newButton{name="b18", x=660, y=290,w=75,fText="N", color="black", code=setPen(18)},--HIDE
WIDGET.newButton{name="b19", x=740, y=290,w=75,fText="B", color="lYellow",code=setPen(19)},--BOMB
WIDGET.newButton{name="b20", x=820, y=290,w=75,fText="_", color="grey", code=setPen(20)},--GB1
WIDGET.newButton{name="b21", x=900, y=290,w=75,fText="_", color="lGrey", code=setPen(21)},--GB2
WIDGET.newButton{name="b22", x=980, y=290,w=75,fText="_", color="dPurple",code=setPen(22)},--GB3
WIDGET.newButton{name="b23", x=1060, y=290,w=75,fText="_", color="dRed", code=setPen(23)},--GB4
WIDGET.newButton{name="b24", x=1140, y=290,w=75,fText="_", color="dGreen", code=setPen(24)},--GB5
WIDGET.newButton{name="any", x=600, y=400,w=120,color="lGrey", font=40,code=setPen(0)},
WIDGET.newButton{name="space", x=730, y=400,w=120,color="grey", font=65,code=setPen(-1)},

View File

@@ -42,8 +42,8 @@ function scene.draw()
end
scene.widgetList={
WIDGET.newKey{name="prev", x=1155, y=170,w=180,font=65,code=pressKey"up",hide=function()return scrollPos==1 end},
WIDGET.newKey{name="next", x=1155, y=400,w=180,font=65,code=pressKey"down",hide=function()return scrollPos==#texts end},
WIDGET.newKey{name="prev", x=1155, y=170,w=180,fText="",font=65,code=pressKey"up",hide=function()return scrollPos==1 end},
WIDGET.newKey{name="next", x=1155, y=400,w=180,fText="",font=65,code=pressKey"down",hide=function()return scrollPos==#texts end},
WIDGET.newButton{name="back", x=1140, y=640,w=170,h=80,font=40,code=backScene},
}

View File

@@ -6,14 +6,14 @@ end
local function setLang(n)return function()SETTING.lang=n LANG.set(n)end end
scene.widgetList={
WIDGET.newButton{name="zh", x=200, y=100,w=200,h=120,font=35,code=setLang(1)},
WIDGET.newButton{name="zh2", x=420, y=100,w=200,h=120,font=35,code=setLang(2)},
WIDGET.newButton{name="en", x=640, y=100,w=200,h=120,font=35,code=setLang(3)},
WIDGET.newButton{name="fr", x=860, y=100,w=200,h=120,font=35,code=setLang(4)},
WIDGET.newButton{name="sp", x=1080, y=100,w=200,h=120,font=35,code=setLang(5)},
WIDGET.newButton{name="pt", x=200, y=250,w=200,h=120,font=35,code=setLang(6)},
WIDGET.newButton{name="symbol", x=420, y=250,w=200,h=120,font=35,code=setLang(7)},
WIDGET.newButton{name="yygq", x=640, y=250,w=200,h=120,font=35,code=setLang(8)},
WIDGET.newButton{name="zh", x=200, y=100,w=200,h=120,fText="中文", font=35,code=setLang(1)},
WIDGET.newButton{name="zh2", x=420, y=100,w=200,h=120,fText="全中文", font=35,code=setLang(2)},
WIDGET.newButton{name="en", x=640, y=100,w=200,h=120,fText="English", font=35,code=setLang(3)},
WIDGET.newButton{name="fr", x=860, y=100,w=200,h=120,fText="Français", font=35,code=setLang(4)},
WIDGET.newButton{name="sp", x=1080, y=100,w=200,h=120,fText="Español", font=35,code=setLang(5)},
WIDGET.newButton{name="pt", x=200, y=250,w=200,h=120,fText="Português", font=35,code=setLang(6)},
WIDGET.newButton{name="symbol", x=420, y=250,w=200,h=120,fText="?????", font=35,code=setLang(7)},
WIDGET.newButton{name="yygq", x=640, y=250,w=200,h=120,fText="就这?", font=35,code=setLang(8)},
WIDGET.newButton{name="back", x=640, y=600,w=200,h=80,font=35,code=backScene},
}

View File

@@ -36,23 +36,23 @@ local function nextDir(n)return function()SKIN.rotate(n)end end
scene.widgetList={
WIDGET.newText{name="title", x=80,y=50,font=70,align="L"},
WIDGET.newButton{name="prev", x=700,y=100,w=140,h=100,font=50,code=function()SKIN.prevSet()end},
WIDGET.newButton{name="next", x=860,y=100,w=140,h=100,font=50,code=function()SKIN.nextSet()end},
WIDGET.newButton{name="prev1", x=130,y=230,w=90,h=65,code=prevSkin(1)},
WIDGET.newButton{name="prev2", x=270,y=230,w=90,h=65,code=prevSkin(2)},
WIDGET.newButton{name="prev3", x=410,y=230,w=90,h=65,code=prevSkin(3)},
WIDGET.newButton{name="prev4", x=550,y=230,w=90,h=65,code=prevSkin(4)},
WIDGET.newButton{name="prev5", x=690,y=230,w=90,h=65,code=prevSkin(5)},
WIDGET.newButton{name="prev6", x=830,y=230,w=90,h=65,code=prevSkin(6)},
WIDGET.newButton{name="prev7", x=970,y=230,w=90,h=65,code=prevSkin(7)},
WIDGET.newButton{name="prev", x=700,y=100,w=140,h=100,fText="",font=50,code=function()SKIN.prevSet()end},
WIDGET.newButton{name="next", x=860,y=100,w=140,h=100,fText="",font=50,code=function()SKIN.nextSet()end},
WIDGET.newButton{name="prev1", x=130,y=230,w=90,h=65,fText="",code=prevSkin(1)},
WIDGET.newButton{name="prev2", x=270,y=230,w=90,h=65,fText="",code=prevSkin(2)},
WIDGET.newButton{name="prev3", x=410,y=230,w=90,h=65,fText="",code=prevSkin(3)},
WIDGET.newButton{name="prev4", x=550,y=230,w=90,h=65,fText="",code=prevSkin(4)},
WIDGET.newButton{name="prev5", x=690,y=230,w=90,h=65,fText="",code=prevSkin(5)},
WIDGET.newButton{name="prev6", x=830,y=230,w=90,h=65,fText="",code=prevSkin(6)},
WIDGET.newButton{name="prev7", x=970,y=230,w=90,h=65,fText="",code=prevSkin(7)},
WIDGET.newButton{name="next1", x=130,y=450,w=90,h=65,code=nextSkin(1)},
WIDGET.newButton{name="next2", x=270,y=450,w=90,h=65,code=nextSkin(2)},
WIDGET.newButton{name="next3", x=410,y=450,w=90,h=65,code=nextSkin(3)},
WIDGET.newButton{name="next4", x=550,y=450,w=90,h=65,code=nextSkin(4)},
WIDGET.newButton{name="next5", x=690,y=450,w=90,h=65,code=nextSkin(5)},
WIDGET.newButton{name="next6", x=830,y=450,w=90,h=65,code=nextSkin(6)},
WIDGET.newButton{name="next7", x=970,y=450,w=90,h=65,code=nextSkin(7)},
WIDGET.newButton{name="next1", x=130,y=450,w=90,h=65,fText="",code=nextSkin(1)},
WIDGET.newButton{name="next2", x=270,y=450,w=90,h=65,fText="",code=nextSkin(2)},
WIDGET.newButton{name="next3", x=410,y=450,w=90,h=65,fText="",code=nextSkin(3)},
WIDGET.newButton{name="next4", x=550,y=450,w=90,h=65,fText="",code=nextSkin(4)},
WIDGET.newButton{name="next5", x=690,y=450,w=90,h=65,fText="",code=nextSkin(5)},
WIDGET.newButton{name="next6", x=830,y=450,w=90,h=65,fText="",code=nextSkin(6)},
WIDGET.newButton{name="next7", x=970,y=450,w=90,h=65,fText="",code=nextSkin(7)},
WIDGET.newButton{name="spin1", x=130,y=540,w=90,h=65,code=nextDir(1)},
WIDGET.newButton{name="spin2", x=270,y=540,w=90,h=65,code=nextDir(2)},