词典交互优化,可以用中文查了

This commit is contained in:
MrZ626
2021-02-27 23:38:16 +08:00
parent a330d29a28
commit 33101665e3
8 changed files with 72 additions and 84 deletions

View File

@@ -3,15 +3,15 @@ local gc=love.graphics
local int,abs=math.floor,math.abs
local min,sin=math.min,math.sin
local ins,rem=table.insert,table.remove
local find,sub=string.find,string.sub
local find=string.find
local scene={}
local dict--Dict list
local input--Input string
local result--Result Lable
local url
local lastTickInput
local waiting--Searching animation timer
local selected--Selected option
local scrollPos--Scroll down length
@@ -22,7 +22,7 @@ function scene.sceneInit()
BG.set("rainbow")
dict=require("parts/language/dict_"..({"zh","zh","zh","en","en","en","en","en"})[SETTING.lang])
input=""
WIDGET.active.input:clear()
result={}
url=dict[1][5]
@@ -35,7 +35,8 @@ end
local function clearResult()
for _=1,#result do rem(result)end
selected,scrollPos,waiting,lastSearch=1,0,0,false
selected,scrollPos=1,0
waiting,lastSearch=0,false
end
local eggInput={
["15p"]=goScene"mg_15p",
@@ -77,6 +78,7 @@ local eggInput={
spring="sprfes",
}for k,v in next,eggInput do if type(v)=="string"then eggInput[k]=eggInput[v]end end
local function search()
local input=WIDGET.active.input.value
if eggInput[input]then
eggInput[input]()
else
@@ -91,7 +93,7 @@ local function search()
ins(result,dict[i])
end
end
if result[1]then
if #result>0 then
SFX.play("reach")
end
url=(result[1]and result or dict)[selected][5]
@@ -100,12 +102,7 @@ local function search()
end
function scene.keyDown(key)
if #key==1 then
if #input<15 then
input=input..key
waiting=.8
end
elseif key=="up"then
if key=="up"then
if selected and selected>1 then
selected=selected-1
if selected<scrollPos+1 then
@@ -122,22 +119,16 @@ function scene.keyDown(key)
elseif key=="link"then
love.system.openURL(url)
elseif key=="delete"then
if #input>0 then
if #WIDGET.active.input.value>0 then
clearResult()
input=""
WIDGET.active.input:clear()
SFX.play("hold")
end
elseif key=="backspace"then
input=sub(input,1,-2)
if #input==0 then
clearResult()
else
waiting=.8
end
WIDGET.keyPressed("backspace")
elseif key=="escape"then
if #input>0 then
clearResult()
input=""
if #WIDGET.active.input.value>0 then
scene.keyDown("delete")
else
SCN.back()
end
@@ -146,6 +137,15 @@ function scene.keyDown(key)
end
function scene.update(dt)
local input=WIDGET.active.input.value
if input~=lastTickInput then
if #input==0 then
clearResult()
else
waiting=.8
end
lastTickInput=input
end
if waiting>0 then
waiting=waiting-dt
if waiting<=0 then
@@ -167,13 +167,6 @@ local typeColor={
name=COLOR.lPurple,
}
function scene.draw()
gc.setLineWidth(4)
gc.setColor(1,1,1)
gc.rectangle("line",20,110,726,60)
setFont(40)
gc.print(input,35,110)
local list=result[1]and result or dict
gc.setColor(1,1,1)
local t=list[selected][4]
@@ -206,6 +199,7 @@ function scene.draw()
gc.print(item[1],30,y)
end
gc.setLineWidth(4)
gc.setColor(1,1,1)
gc.rectangle("line",300,180,958,526)
gc.rectangle("line",20,180,280,526)
@@ -220,7 +214,7 @@ end
scene.widgetList={
WIDGET.newText{name="title", x=20, y=5,font=70,align="L"},
WIDGET.newKey{name="keyboard", x=960, y=60,w=200,h=80,font=35,code=function()love.keyboard.setTextInput(true,0,0,1,1)end,hide=not MOBILE},
WIDGET.newInputBox{name="input",x=20, y=110,w=726,h=60,font=40},
WIDGET.newKey{name="link", x=1140, y=650,w=200,h=80,font=35,code=pressKey"link",hide=function()return not url end},
WIDGET.newKey{name="up", x=1190, y=440,w=100,h=100,font=35,code=pressKey"up",hide=not MOBILE},
WIDGET.newKey{name="down", x=1190, y=550,w=100,h=100,font=35,code=pressKey"down",hide=not MOBILE},