所有场景文件独立
This commit is contained in:
176
parts/scenes/dict.lua
Normal file
176
parts/scenes/dict.lua
Normal file
@@ -0,0 +1,176 @@
|
||||
local gc=love.graphics
|
||||
local Timer=love.timer.getTime
|
||||
|
||||
local setFont=setFont
|
||||
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
|
||||
|
||||
function sceneInit.dict()
|
||||
local location=(SETTING.lang==3 or SETTING.lang==4)and"en"or"zh"
|
||||
sceneTemp={
|
||||
dict=require("LANG/dict_"..location),
|
||||
|
||||
input="",
|
||||
result={},
|
||||
url=nil,
|
||||
|
||||
waiting=0,
|
||||
select=1,
|
||||
scroll=0,
|
||||
|
||||
lastSearch=false,
|
||||
}
|
||||
local S=sceneTemp
|
||||
S.url=(S.result[1]and S.result or S.dict)[S.select][5]
|
||||
BG.set("rainbow")
|
||||
end
|
||||
|
||||
local function clearResult()
|
||||
local S=sceneTemp
|
||||
local result=S.result
|
||||
for _=1,#result do rem(result)end
|
||||
S.select,S.scroll,S.waiting,S.lastSearch=1,0,0,false
|
||||
end
|
||||
local function search()
|
||||
clearResult()
|
||||
local S=sceneTemp
|
||||
local dict=S.dict
|
||||
local result=S.result
|
||||
local first
|
||||
for i=1,#dict do
|
||||
local pos=find(dict[i][2],S.input,nil,true)
|
||||
if pos==1 and not first then
|
||||
ins(result,1,dict[i])
|
||||
first=true
|
||||
elseif pos then
|
||||
ins(result,dict[i])
|
||||
end
|
||||
end
|
||||
if result[1]then
|
||||
SFX.play("reach")
|
||||
end
|
||||
S.url=(S.result[1]and S.result or S.dict)[S.select][5]
|
||||
S.lastSearch=S.input
|
||||
end
|
||||
|
||||
function keyDown.dict(key)
|
||||
local S=sceneTemp
|
||||
if #key==1 then
|
||||
if #S.input<15 then
|
||||
S.input=S.input..key
|
||||
S.waiting=.8
|
||||
end
|
||||
elseif key=="up"then
|
||||
if S.select and S.select>1 then
|
||||
S.select=S.select-1
|
||||
if S.select<S.scroll+1 then
|
||||
S.scroll=S.scroll-1
|
||||
end
|
||||
end
|
||||
elseif key=="down"then
|
||||
if S.select and S.select<#(S.result[1]and S.result or S.dict)then
|
||||
S.select=S.select+1
|
||||
if S.select>S.scroll+15 then
|
||||
S.scroll=S.select-15
|
||||
end
|
||||
end
|
||||
elseif key=="link"then
|
||||
love.system.openURL(S.url)
|
||||
elseif key=="delete"then
|
||||
if #S.input>0 then
|
||||
clearResult()
|
||||
S.input=""
|
||||
SFX.play("hold")
|
||||
end
|
||||
elseif key=="backspace"then
|
||||
S.input=sub(S.input,1,-2)
|
||||
if #S.input==0 then
|
||||
clearResult()
|
||||
else
|
||||
S.waiting=.8
|
||||
end
|
||||
elseif key=="escape"then
|
||||
if #S.input>0 then
|
||||
clearResult()
|
||||
S.input=""
|
||||
else
|
||||
SCN.back()
|
||||
end
|
||||
end
|
||||
S.url=(S.result[1]and S.result or S.dict)[S.select][5]
|
||||
end
|
||||
|
||||
function Tmr.dict(dt)
|
||||
local S=sceneTemp
|
||||
if S.waiting>0 then
|
||||
S.waiting=S.waiting-dt
|
||||
if S.waiting<=0 then
|
||||
if #S.input>0 and S.input~=S.lastSearch then
|
||||
search()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local typeColor={
|
||||
help=color.lGrey,
|
||||
other=color.lOrange,
|
||||
game=color.lCyan,
|
||||
term=color.lRed,
|
||||
english=color.green,
|
||||
name=color.lPurple,
|
||||
}
|
||||
function Pnt.dict()
|
||||
local S=sceneTemp
|
||||
|
||||
gc.setLineWidth(4)
|
||||
gc.setColor(1,1,1)
|
||||
gc.rectangle("line",20,110,726,60)
|
||||
setFont(40)
|
||||
gc.print(S.input,35,110)
|
||||
|
||||
local list=S.result[1]and S.result or S.dict
|
||||
gc.setColor(1,1,1)
|
||||
local text=list[S.select][4]
|
||||
if #text>900 then
|
||||
setFont(15)
|
||||
elseif #text>600 then
|
||||
setFont(20)
|
||||
elseif #text>400 then
|
||||
setFont(25)
|
||||
else
|
||||
setFont(30)
|
||||
end
|
||||
gc.printf(text,306,180,950)
|
||||
|
||||
setFont(30)
|
||||
gc.setColor(1,1,1,.4+.2*sin(Timer()*4))
|
||||
gc.rectangle("fill",20,143+35*(S.select-S.scroll),280,35)
|
||||
|
||||
setFont(30)
|
||||
for i=1,min(#list,15)do
|
||||
local y=142+35*i
|
||||
i=i+S.scroll
|
||||
local item=list[i]
|
||||
gc.setColor(0,0,0)
|
||||
gc.print(item[1],29,y-1)
|
||||
gc.print(item[1],29,y+1)
|
||||
gc.print(item[1],31,y-1)
|
||||
gc.print(item[1],31,y+1)
|
||||
gc.setColor(typeColor[item[3]])
|
||||
gc.print(item[1],30,y)
|
||||
end
|
||||
|
||||
gc.setColor(1,1,1)
|
||||
gc.rectangle("line",300,180,958,526)
|
||||
gc.rectangle("line",20,180,280,526)
|
||||
|
||||
if S.waiting>0 then
|
||||
local r=Timer()*2
|
||||
local R=int(r)%7+1
|
||||
gc.setColor(1,1,1,1-abs(r%1*2-1))
|
||||
gc.draw(TEXTURE.miniBlock[R],785,140,Timer()*10%6.2832,15,15,spinCenters[R][0][2]+.5,#blocks[R][0]-spinCenters[R][0][1]-.5)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user