新增列表框控件,并用于房间列表,整理代码
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
local gc=love.graphics
|
local gc=love.graphics
|
||||||
local gc_clear,gc_origin=gc.clear,gc.origin
|
local gc_origin=gc.origin
|
||||||
local gc_translate,gc_replaceTransform=gc.translate,gc.replaceTransform
|
local gc_translate,gc_replaceTransform=gc.translate,gc.replaceTransform
|
||||||
|
local gc_stencil,gc_setStencilTest=gc.stencil,gc.setStencilTest
|
||||||
|
local gc_push,gc_pop=gc.push,gc.pop
|
||||||
local gc_setCanvas,gc_setBlendMode=gc.setCanvas,gc.setBlendMode
|
local gc_setCanvas,gc_setBlendMode=gc.setCanvas,gc.setBlendMode
|
||||||
local gc_setColor,gc_setLineWidth=gc.setColor,gc.setLineWidth
|
local gc_setColor,gc_setLineWidth=gc.setColor,gc.setLineWidth
|
||||||
local gc_draw,gc_line=gc.draw,gc.line
|
local gc_draw,gc_line=gc.draw,gc.line
|
||||||
@@ -10,7 +12,7 @@ local gc_print,gc_printf=gc.print,gc.printf
|
|||||||
local kb=love.keyboard
|
local kb=love.keyboard
|
||||||
|
|
||||||
local next=next
|
local next=next
|
||||||
local int,abs=math.floor,math.abs
|
local int,ceil,abs=math.floor,math.ceil,math.abs
|
||||||
local max,min=math.max,math.min
|
local max,min=math.max,math.min
|
||||||
local sub,ins=string.sub,table.insert
|
local sub,ins=string.sub,table.insert
|
||||||
local getFont,setFont,mStr=getFont,setFont,mStr
|
local getFont,setFont,mStr=getFont,setFont,mStr
|
||||||
@@ -422,6 +424,7 @@ end
|
|||||||
|
|
||||||
local slider={
|
local slider={
|
||||||
type='slider',
|
type='slider',
|
||||||
|
dragAble=true,
|
||||||
ATV=0,--Activating time(0~8)
|
ATV=0,--Activating time(0~8)
|
||||||
TAT=0,--Text activating time(0~180)
|
TAT=0,--Text activating time(0~180)
|
||||||
pos=0,--Position shown
|
pos=0,--Position shown
|
||||||
@@ -877,19 +880,25 @@ end
|
|||||||
|
|
||||||
local textBox={
|
local textBox={
|
||||||
type='textBox',
|
type='textBox',
|
||||||
|
dragAble=true,
|
||||||
scrollPos=0,--Which line display at bottom
|
scrollPos=0,--Which line display at bottom
|
||||||
scrollPix=0,--Hidden wheel move value
|
scrollPix=0,--Hidden wheel move value
|
||||||
sure=0,--Sure-timer for clear history
|
sure=0,--Sure-timer for clear history
|
||||||
new=false,--If there is a new message
|
new=false,--If there is a new message
|
||||||
-- texts={},
|
|
||||||
}
|
}
|
||||||
function textBox:reset()
|
function textBox:reset()
|
||||||
--haha nothing here, but techmino is fun!
|
--haha nothing here, techmino is so fun!
|
||||||
end
|
end
|
||||||
function textBox:setTexts(t)
|
function textBox:setTexts(t)
|
||||||
self.texts=t
|
self.texts=t
|
||||||
self.scrollPos=min(#self.texts,self.capacity)
|
self.scrollPos=min(#self.texts,self.capacity)
|
||||||
end
|
end
|
||||||
|
function textBox:clear()
|
||||||
|
self.texts={}
|
||||||
|
self.scrollPos=0
|
||||||
|
self.new=false
|
||||||
|
SFX.play('fall')
|
||||||
|
end
|
||||||
function textBox:isAbove(x,y)
|
function textBox:isAbove(x,y)
|
||||||
return
|
return
|
||||||
x>self.x and
|
x>self.x and
|
||||||
@@ -929,8 +938,8 @@ end
|
|||||||
function textBox:drag(_,_,_,dy)
|
function textBox:drag(_,_,_,dy)
|
||||||
_=self.scrollPix+dy
|
_=self.scrollPix+dy
|
||||||
local sign=_>0 and 1 or -1
|
local sign=_>0 and 1 or -1
|
||||||
while abs(_)>30 do
|
while abs(_)>self.lineH do
|
||||||
_=_-30*sign
|
_=_-self.lineH*sign
|
||||||
self:scroll(-sign)
|
self:scroll(-sign)
|
||||||
end
|
end
|
||||||
self.scrollPix=_
|
self.scrollPix=_
|
||||||
@@ -942,12 +951,6 @@ function textBox:scroll(n)
|
|||||||
self.scrollPos=min(self.scrollPos+n,#self.texts)
|
self.scrollPos=min(self.scrollPos+n,#self.texts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function textBox:clear()
|
|
||||||
self.texts={}
|
|
||||||
self.scrollPos=0
|
|
||||||
self.new=false
|
|
||||||
SFX.play('fall')
|
|
||||||
end
|
|
||||||
function textBox:draw()
|
function textBox:draw()
|
||||||
local x,y,w,h=self.x,self.y,self.w,self.h
|
local x,y,w,h=self.x,self.y,self.w,self.h
|
||||||
local texts=self.texts
|
local texts=self.texts
|
||||||
@@ -965,7 +968,7 @@ function textBox:draw()
|
|||||||
|
|
||||||
--Frame
|
--Frame
|
||||||
gc_setLineWidth(4)
|
gc_setLineWidth(4)
|
||||||
gc_setColor(1,1,WIDGET.sel==self and .8 or 1)
|
gc_setColor(WIDGET.sel==self and COLOR.lN or COLOR.Z)
|
||||||
gc_rectangle('line',x,y,w,h)
|
gc_rectangle('line',x,y,w,h)
|
||||||
|
|
||||||
--Slider
|
--Slider
|
||||||
@@ -1026,13 +1029,146 @@ function WIDGET.newTextBox(D)--name,x,y,w,h[,font=30][,lineH][,fix],hide
|
|||||||
hide= D.hide,
|
hide= D.hide,
|
||||||
}
|
}
|
||||||
_.lineH=D.lineH or _.font*7/5
|
_.lineH=D.lineH or _.font*7/5
|
||||||
_.capacity=int((D.h-10)/_.lineH)
|
_.capacity=ceil((D.h-10)/_.lineH)
|
||||||
|
|
||||||
for k,v in next,textBox do _[k]=v end
|
for k,v in next,textBox do _[k]=v end
|
||||||
setmetatable(_,widgetMetatable)
|
setmetatable(_,widgetMetatable)
|
||||||
return _
|
return _
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local listBox={
|
||||||
|
type='listBox',
|
||||||
|
dragAble=true,
|
||||||
|
scrollPos=0,--Which line display at bottom
|
||||||
|
selected=0,--Hidden wheel move value
|
||||||
|
}
|
||||||
|
function listBox:reset()
|
||||||
|
--haha nothing here too, techmino is really fun!
|
||||||
|
end
|
||||||
|
function listBox:clear()
|
||||||
|
self.list={}
|
||||||
|
self.scrollPos=0
|
||||||
|
end
|
||||||
|
function listBox:setList(t)
|
||||||
|
self.list=t
|
||||||
|
self.selected=1
|
||||||
|
self.scrollPos=0
|
||||||
|
end
|
||||||
|
function listBox:getList()
|
||||||
|
return self.list
|
||||||
|
end
|
||||||
|
function listBox:getLen()
|
||||||
|
return #self.list
|
||||||
|
end
|
||||||
|
function listBox:getSel()
|
||||||
|
return self.list[self.selected]
|
||||||
|
end
|
||||||
|
function listBox:isAbove(x,y)
|
||||||
|
return
|
||||||
|
x>self.x and
|
||||||
|
y>self.y and
|
||||||
|
x<self.x+self.w and
|
||||||
|
y<self.y+self.h
|
||||||
|
end
|
||||||
|
function listBox:getCenter()
|
||||||
|
return self.x+self.w*.5,self.y+self.w
|
||||||
|
end
|
||||||
|
function listBox:push(t)
|
||||||
|
ins(self.list,t)
|
||||||
|
end
|
||||||
|
function listBox:press(x,y)
|
||||||
|
if not(x and y)then return end
|
||||||
|
self:drag(nil,nil,nil,0)
|
||||||
|
x,y=x-self.x,y-self.y
|
||||||
|
y=int(y/40+self.scrollPos)+1
|
||||||
|
if self.list[y]then
|
||||||
|
if self.selected~=y then
|
||||||
|
self.selected=y
|
||||||
|
SFX.play('click',.4)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function listBox:drag(_,_,_,dy)
|
||||||
|
self.scrollPos=max(0,min(self.scrollPos-dy,(#self.list-self.capacity)*self.lineH))
|
||||||
|
print(self.scrollPos)
|
||||||
|
end
|
||||||
|
function listBox:scroll(n)
|
||||||
|
self.scrollPos=max(0,min(self.scrollPos-n*self.lineH,(#self.list-self.capacity)*self.lineH))
|
||||||
|
print(self.scrollPos)
|
||||||
|
end
|
||||||
|
local SSW,SSH--stencil-size-w/h
|
||||||
|
local function listBoxStencil()
|
||||||
|
gc.rectangle('fill',1,1,SSW-2,SSH-2)
|
||||||
|
end
|
||||||
|
function listBox:draw()
|
||||||
|
local x,y,w,h=self.x,self.y,self.w,self.h
|
||||||
|
local list=self.list
|
||||||
|
local scrollPos=self.scrollPos
|
||||||
|
local cap=self.capacity
|
||||||
|
local lineH=self.lineH
|
||||||
|
|
||||||
|
gc_push('transform')
|
||||||
|
gc_translate(x,y)
|
||||||
|
gc_setColor(WIDGET.sel==self and COLOR.lN or COLOR.Z)
|
||||||
|
gc_setLineWidth(3)
|
||||||
|
gc_rectangle('line',0,0,w,h)
|
||||||
|
|
||||||
|
if #list>cap then
|
||||||
|
gc_setColor(1,1,1)
|
||||||
|
local len=h*h/(#list*lineH)
|
||||||
|
gc_rectangle('fill',-15,(h-len)*scrollPos/((#list-cap)*lineH),12,len)
|
||||||
|
end
|
||||||
|
|
||||||
|
gc_setStencilTest('equal',1)
|
||||||
|
SSW,SSH=w,h
|
||||||
|
gc_stencil(listBoxStencil)
|
||||||
|
setFont(35)
|
||||||
|
local pos=int(scrollPos/lineH)
|
||||||
|
gc_translate(0,-(scrollPos%lineH))
|
||||||
|
for i=pos+1,min(pos+cap+1,#list)do
|
||||||
|
self.drawF(i==self.selected,i,list[i])
|
||||||
|
gc_translate(0,lineH)
|
||||||
|
end
|
||||||
|
gc_setStencilTest()
|
||||||
|
gc_pop()
|
||||||
|
end
|
||||||
|
function listBox:getInfo()
|
||||||
|
return("x=%d,y=%d,w=%d,h=%d"):format(self.x+self.w*.5,self.y+self.h*.5,self.w,self.h)
|
||||||
|
end
|
||||||
|
function WIDGET.newListBox(D)--name,x,y,w,h[,lineH],hide,drawF
|
||||||
|
local _={
|
||||||
|
name= D.name or"_",
|
||||||
|
|
||||||
|
resCtr={
|
||||||
|
D.x+D.w*.5,D.y+D.h*.5,
|
||||||
|
D.x+D.w*.5,D.y,
|
||||||
|
D.x-D.w*.5,D.y,
|
||||||
|
D.x,D.y+D.h*.5,
|
||||||
|
D.x,D.y-D.h*.5,
|
||||||
|
D.x,D.y,
|
||||||
|
D.x+D.w,D.y,
|
||||||
|
D.x,D.y+D.h,
|
||||||
|
D.x+D.w,D.y+D.h,
|
||||||
|
},
|
||||||
|
|
||||||
|
x= D.x,
|
||||||
|
y= D.y,
|
||||||
|
w= D.w,
|
||||||
|
h= D.h,
|
||||||
|
|
||||||
|
list= {},
|
||||||
|
lineH= D.lineH,
|
||||||
|
capacity=ceil(D.h/D.lineH),
|
||||||
|
drawF= D.drawF,
|
||||||
|
hideF= D.hideF,
|
||||||
|
hide= D.hide,
|
||||||
|
}
|
||||||
|
|
||||||
|
for k,v in next,listBox do _[k]=v end
|
||||||
|
setmetatable(_,widgetMetatable)
|
||||||
|
return _
|
||||||
|
end
|
||||||
|
|
||||||
WIDGET.active={}--Table contains all active widgets
|
WIDGET.active={}--Table contains all active widgets
|
||||||
WIDGET.scrollHeight=0--Max drag height, not actual container height!
|
WIDGET.scrollHeight=0--Max drag height, not actual container height!
|
||||||
WIDGET.scrollPos=0--Current scroll position
|
WIDGET.scrollPos=0--Current scroll position
|
||||||
@@ -1135,7 +1271,7 @@ end
|
|||||||
function WIDGET.drag(x,y,dx,dy)
|
function WIDGET.drag(x,y,dx,dy)
|
||||||
if WIDGET.sel then
|
if WIDGET.sel then
|
||||||
local W=WIDGET.sel
|
local W=WIDGET.sel
|
||||||
if W.type=='slider'or W.type=='textBox'then
|
if W.dragAble then
|
||||||
W:drag(x,y+WIDGET.scrollPos,dx,dy)
|
W:drag(x,y+WIDGET.scrollPos,dx,dy)
|
||||||
elseif not W:isAbove(x,y)then
|
elseif not W:isAbove(x,y)then
|
||||||
WIDGET.unFocus(true)
|
WIDGET.unFocus(true)
|
||||||
@@ -1272,8 +1408,7 @@ function WIDGET.resize(w,h)
|
|||||||
widgetCanvas=gc.newCanvas(w,h)
|
widgetCanvas=gc.newCanvas(w,h)
|
||||||
end
|
end
|
||||||
function WIDGET.draw()
|
function WIDGET.draw()
|
||||||
gc_setCanvas(widgetCanvas)
|
gc_setCanvas({stencil=true},widgetCanvas)
|
||||||
gc_clear(0,0,0,0)
|
|
||||||
gc_translate(0,-WIDGET.scrollPos)
|
gc_translate(0,-WIDGET.scrollPos)
|
||||||
for _,W in next,WIDGET.active do
|
for _,W in next,WIDGET.active do
|
||||||
if not W.hide then W:draw()end
|
if not W.hide then W:draw()end
|
||||||
@@ -1290,7 +1425,7 @@ function WIDGET.draw()
|
|||||||
gc_setBlendMode('multiply','premultiplied')
|
gc_setBlendMode('multiply','premultiplied')
|
||||||
gc_draw(widgetCover,nil,nil,nil,scr_w,scr_h/360)
|
gc_draw(widgetCover,nil,nil,nil,scr_w,scr_h/360)
|
||||||
end
|
end
|
||||||
gc_setCanvas()
|
gc_setCanvas({stencil=false})
|
||||||
gc_setBlendMode('alpha','premultiplied')
|
gc_setBlendMode('alpha','premultiplied')
|
||||||
gc_draw(widgetCanvas)
|
gc_draw(widgetCanvas)
|
||||||
gc_setBlendMode('alpha')
|
gc_setBlendMode('alpha')
|
||||||
|
|||||||
@@ -544,6 +544,7 @@ return{
|
|||||||
stat={
|
stat={
|
||||||
path="Open Data Folder",
|
path="Open Data Folder",
|
||||||
save="Data Management",
|
save="Data Management",
|
||||||
|
replays="Saved Replays",
|
||||||
},
|
},
|
||||||
music={
|
music={
|
||||||
title="Music Room",
|
title="Music Room",
|
||||||
|
|||||||
@@ -499,6 +499,7 @@ return{
|
|||||||
stat={
|
stat={
|
||||||
path="Abrir carpeta del juego",
|
path="Abrir carpeta del juego",
|
||||||
save="Manejo de Datos",
|
save="Manejo de Datos",
|
||||||
|
-- replays="Saved Replays",
|
||||||
},
|
},
|
||||||
music={
|
music={
|
||||||
title="Sala de Música",
|
title="Sala de Música",
|
||||||
|
|||||||
@@ -498,6 +498,7 @@ return{
|
|||||||
stat={
|
stat={
|
||||||
path="Ouvrir dossier des données",
|
path="Ouvrir dossier des données",
|
||||||
save="Gestion des données",
|
save="Gestion des données",
|
||||||
|
-- replays="Saved Replays",
|
||||||
},
|
},
|
||||||
music={
|
music={
|
||||||
title="Salon musical",
|
title="Salon musical",
|
||||||
|
|||||||
@@ -541,6 +541,7 @@ return{
|
|||||||
stat={
|
stat={
|
||||||
path="Abrir Pasta De Data",
|
path="Abrir Pasta De Data",
|
||||||
save="Gestão De Dados",
|
save="Gestão De Dados",
|
||||||
|
-- replays="Saved Replays",
|
||||||
},
|
},
|
||||||
music={
|
music={
|
||||||
title="Sala De Música",
|
title="Sala De Música",
|
||||||
|
|||||||
@@ -354,7 +354,8 @@ return{
|
|||||||
},
|
},
|
||||||
stat={
|
stat={
|
||||||
path="%$%",
|
path="%$%",
|
||||||
save="%0101%",
|
save="%0123%",
|
||||||
|
replays="%0101%",
|
||||||
},
|
},
|
||||||
music={
|
music={
|
||||||
title="(~~~~)",
|
title="(~~~~)",
|
||||||
|
|||||||
@@ -621,6 +621,7 @@ return{
|
|||||||
stat={
|
stat={
|
||||||
path="打开存储目录",
|
path="打开存储目录",
|
||||||
save="用户档案管理",
|
save="用户档案管理",
|
||||||
|
replays="录像菜单",
|
||||||
},
|
},
|
||||||
login={
|
login={
|
||||||
title="登录",
|
title="登录",
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ local NET={
|
|||||||
accessToken=false,
|
accessToken=false,
|
||||||
cloudData={},
|
cloudData={},
|
||||||
|
|
||||||
roomList={},--Local roomlist, updated frequently
|
|
||||||
roomState={--A copy of room structure on server
|
roomState={--A copy of room structure on server
|
||||||
roomInfo={
|
roomInfo={
|
||||||
name=false,
|
name=false,
|
||||||
@@ -508,7 +507,24 @@ function NET.updateWS_play()
|
|||||||
NET.unlock('access_and_login')
|
NET.unlock('access_and_login')
|
||||||
SFX.play('connected')
|
SFX.play('connected')
|
||||||
elseif res.action==0 then--Fetch rooms
|
elseif res.action==0 then--Fetch rooms
|
||||||
NET.roomList=res.roomList
|
if SCN.cur=="net_rooms"then
|
||||||
|
for i=1,16 do
|
||||||
|
res.roomList[i]={
|
||||||
|
rid="qwe",
|
||||||
|
roomInfo={
|
||||||
|
name="Test room "..i,
|
||||||
|
type="classic",
|
||||||
|
version=VERSION.short,
|
||||||
|
description="x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x ",
|
||||||
|
},
|
||||||
|
private=i%3==0,
|
||||||
|
start=i%4==0,
|
||||||
|
count=i%5,
|
||||||
|
capacity=5,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
WIDGET.active.roomList:setList(res.roomList)
|
||||||
|
end
|
||||||
NET.unlock('fetchRoom')
|
NET.unlock('fetchRoom')
|
||||||
elseif res.action==1 then--Create room (not used)
|
elseif res.action==1 then--Create room (not used)
|
||||||
--?
|
--?
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ function netPLY.draw()
|
|||||||
--Stencil
|
--Stencil
|
||||||
stencilW,stencilH=p.w,p.h
|
stencilW,stencilH=p.w,p.h
|
||||||
gc_setStencilTest('equal',1)
|
gc_setStencilTest('equal',1)
|
||||||
gc_stencil(plyStencil,'replace',1)
|
gc_stencil(plyStencil)
|
||||||
gc_setColor(1,1,1)
|
gc_setColor(1,1,1)
|
||||||
|
|
||||||
--Avatar
|
--Avatar
|
||||||
|
|||||||
@@ -568,7 +568,7 @@ function draw.norm(P)
|
|||||||
gc_rectangle('fill',0,-10,300,610)
|
gc_rectangle('fill',0,-10,300,610)
|
||||||
|
|
||||||
--Stenciled in-field things
|
--Stenciled in-field things
|
||||||
gc_stencil(stencilBoard,'replace',1)
|
gc_stencil(stencilBoard)
|
||||||
gc_setStencilTest('equal',1)
|
gc_setStencilTest('equal',1)
|
||||||
gc_push('transform')
|
gc_push('transform')
|
||||||
boardTransform(ENV.flipBoard)
|
boardTransform(ENV.flipBoard)
|
||||||
@@ -675,7 +675,7 @@ function draw.norm(P)
|
|||||||
|
|
||||||
--Board cover
|
--Board cover
|
||||||
if ENV.hideBoard then
|
if ENV.hideBoard then
|
||||||
gc_stencil(hideBoardStencil[ENV.hideBoard],'replace',1)
|
gc_stencil(hideBoardStencil[ENV.hideBoard])
|
||||||
gc_setStencilTest('equal',1)
|
gc_setStencilTest('equal',1)
|
||||||
gc_setLineWidth(20)
|
gc_setLineWidth(20)
|
||||||
for i=0,24 do
|
for i=0,24 do
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ local seqGenerators={
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
return function(P)--Return a piece-generating funtion for player P
|
return function(P)--Return a piece-generating function for player P
|
||||||
local s=P.gameEnv.sequence
|
local s=P.gameEnv.sequence
|
||||||
if type(s)=='function'then
|
if type(s)=='function'then
|
||||||
return s
|
return s
|
||||||
|
|||||||
@@ -283,7 +283,7 @@ function scene.draw()
|
|||||||
gc.setColor(.15,.15,.15)
|
gc.setColor(.15,.15,.15)
|
||||||
gc.rectangle('fill',340,0,600,720)
|
gc.rectangle('fill',340,0,600,720)
|
||||||
|
|
||||||
gc.stencil(doorStencil,'replace',1)
|
gc.stencil(doorStencil)
|
||||||
gc.setStencilTest('equal',1)
|
gc.setStencilTest('equal',1)
|
||||||
gc.push('transform')
|
gc.push('transform')
|
||||||
|
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ function scene.draw()
|
|||||||
gc.translate(260,650)
|
gc.translate(260,650)
|
||||||
gc.setLineWidth(2)
|
gc.setLineWidth(2)
|
||||||
gc.rectangle('line',0,0,tipLength,42)
|
gc.rectangle('line',0,0,tipLength,42)
|
||||||
gc.stencil(tipStencil,'replace',1)
|
gc.stencil(tipStencil)
|
||||||
gc.setStencilTest('equal',1)
|
gc.setStencilTest('equal',1)
|
||||||
gc.draw(tip,0+scrollX,0)
|
gc.draw(tip,0+scrollX,0)
|
||||||
gc.setColor(1,1,1,.2)
|
gc.setColor(1,1,1,.2)
|
||||||
|
|||||||
@@ -1,29 +1,34 @@
|
|||||||
local gc=love.graphics
|
local gc=love.graphics
|
||||||
local ms=love.mouse
|
|
||||||
|
|
||||||
local int,max,min=math.floor,math.max,math.min
|
|
||||||
|
|
||||||
local NET=NET
|
local NET=NET
|
||||||
local scrollPos,selected
|
|
||||||
local fetchTimer
|
local fetchTimer
|
||||||
|
|
||||||
|
local roomList=WIDGET.newListBox{name="roomList",x=50,y=50,w=800,h=440,lineH=40,drawF=function(ifSel,id,item)
|
||||||
|
if ifSel then
|
||||||
|
gc.setColor(1,1,1,.3)
|
||||||
|
gc.rectangle('fill',0,0,800,40)
|
||||||
|
end
|
||||||
|
gc.setColor(1,1,1)
|
||||||
|
if item.private then gc.draw(IMG.lock,10,5)end
|
||||||
|
gc.print(item.count.."/"..item.capacity,670,-4)
|
||||||
|
|
||||||
|
gc.setColor(.9,.9,1)
|
||||||
|
gc.print(id,45,-4)
|
||||||
|
|
||||||
|
if item.start then
|
||||||
|
gc.setColor(0,.4,.1)
|
||||||
|
else
|
||||||
|
gc.setColor(1,1,.7)
|
||||||
|
end
|
||||||
|
gc.print(item.roomInfo.name,200,-4)
|
||||||
|
end}
|
||||||
local function hidePW()
|
local function hidePW()
|
||||||
local R=NET.roomList[selected]
|
local R=roomList:getSel()
|
||||||
return not R or not R.private
|
return not R or not R.private
|
||||||
end
|
end
|
||||||
local passwordBox=WIDGET.newInputBox{name="password",x=350,y=505,w=500,h=50,secret=true,hideF=hidePW}
|
local passwordBox=WIDGET.newInputBox{name="password",x=350,y=505,w=500,h=50,secret=true,hideF=hidePW}
|
||||||
|
|
||||||
local listBoxPos={
|
--[[roomList[n]={
|
||||||
x=50,y=90,
|
|
||||||
w=800,h=400,
|
|
||||||
x2=850,y2=510,
|
|
||||||
}
|
|
||||||
local function focusPWbox()
|
|
||||||
passwordBox.value=""
|
|
||||||
WIDGET.focus(passwordBox)
|
|
||||||
end
|
|
||||||
|
|
||||||
--[[NET.roomList[n]={
|
|
||||||
rid="qwerty",
|
rid="qwerty",
|
||||||
roomInfo={
|
roomInfo={
|
||||||
name="MrZ's room",
|
name="MrZ's room",
|
||||||
@@ -43,15 +48,9 @@ local scene={}
|
|||||||
|
|
||||||
function scene.sceneInit()
|
function scene.sceneInit()
|
||||||
BG.set()
|
BG.set()
|
||||||
scrollPos=0
|
|
||||||
selected=1
|
|
||||||
focusPWbox()
|
|
||||||
fetchRoom()
|
fetchRoom()
|
||||||
end
|
end
|
||||||
|
|
||||||
function scene.wheelMoved(_,y)
|
|
||||||
scrollPos=max(0,min(scrollPos-y,#NET.roomList-10))
|
|
||||||
end
|
|
||||||
function scene.keyDown(key)
|
function scene.keyDown(key)
|
||||||
if key=="r"then
|
if key=="r"then
|
||||||
if fetchTimer<=7 then
|
if fetchTimer<=7 then
|
||||||
@@ -63,125 +62,40 @@ function scene.keyDown(key)
|
|||||||
SCN.go('net_newRoom')
|
SCN.go('net_newRoom')
|
||||||
elseif key=="escape"then
|
elseif key=="escape"then
|
||||||
SCN.back()
|
SCN.back()
|
||||||
elseif #NET.roomList>0 then
|
elseif roomList:getLen()>0 and key=="return"then
|
||||||
if key=="down"then
|
local R=roomList:getSel()
|
||||||
if selected<#NET.roomList then
|
if NET.getlock('fetchRoom')or not R then return end
|
||||||
selected=selected+1
|
|
||||||
focusPWbox()
|
|
||||||
scrollPos=max(selected-10,min(scrollPos,selected-1))
|
|
||||||
end
|
|
||||||
elseif key=="up"then
|
|
||||||
if selected>1 then
|
|
||||||
selected=selected-1
|
|
||||||
focusPWbox()
|
|
||||||
scrollPos=max(selected-10,min(scrollPos,selected-1))
|
|
||||||
end
|
|
||||||
elseif key=="return"then
|
|
||||||
if NET.getlock('fetchRoom')or not NET.roomList[selected]then return end
|
|
||||||
local R=NET.roomList[selected]
|
|
||||||
if R.roomInfo.version:find("^V0%.15%.[234]$")then
|
if R.roomInfo.version:find("^V0%.15%.[234]$")then
|
||||||
NET.enterRoom(R,passwordBox.value)
|
NET.enterRoom(R,passwordBox.value)
|
||||||
else
|
else
|
||||||
MES.new('error',"Version doesn't match 版本不一致")
|
MES.new('error',"Version doesn't compatible 版本不兼容")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
WIDGET.keyPressed(key)
|
WIDGET.keyPressed(key)
|
||||||
end
|
end
|
||||||
else
|
|
||||||
WIDGET.keyPressed(key)
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
function scene.mouseMove(x,y,_,dy)
|
|
||||||
if ms.isDown(1)and x>listBoxPos.x and x<listBoxPos.x2 and y>listBoxPos.y and y<listBoxPos.y2 then
|
|
||||||
scene.wheelMoved(0,dy/40)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
function scene.touchMove(x,y,_,dy)
|
|
||||||
if x>listBoxPos.x and x<listBoxPos.x2 and y>listBoxPos.y and y<listBoxPos.y2 then
|
|
||||||
scene.wheelMoved(0,dy/40)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
function scene.mouseClick(x,y)
|
|
||||||
if x>listBoxPos.x and x<listBoxPos.x2 and y>listBoxPos.y and y<listBoxPos.y2 then
|
|
||||||
y=int((y-listBoxPos.y)/40+scrollPos)+1
|
|
||||||
if NET.roomList[y]then
|
|
||||||
if selected~=y then
|
|
||||||
selected=y
|
|
||||||
focusPWbox()
|
|
||||||
SFX.play('click',.4)
|
|
||||||
else
|
|
||||||
scene.keyDown("return")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
scene.touchClick=scene.mouseClick
|
|
||||||
|
|
||||||
function scene.update(dt)
|
function scene.update(dt)
|
||||||
if not NET.getlock('fetchRoom')then
|
if not NET.getlock('fetchRoom')and hidePW()then
|
||||||
fetchTimer=fetchTimer-dt
|
fetchTimer=fetchTimer-dt
|
||||||
if fetchTimer<=0 then
|
if fetchTimer<=0 then
|
||||||
fetchRoom()
|
fetchRoom()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if #NET.roomList>0 then
|
|
||||||
selected=min(selected,#NET.roomList)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function roomListStencil()
|
|
||||||
gc.rectangle('fill',1,1,listBoxPos.w-2,listBoxPos.h-2)
|
|
||||||
end
|
|
||||||
function scene.draw()
|
function scene.draw()
|
||||||
--Fetching timer
|
--Fetching timer
|
||||||
gc.setColor(1,1,1,.12)
|
gc.setColor(1,1,1,.12)
|
||||||
gc.arc('fill','pie',250,630,40,-1.5708,-1.5708-.6283*fetchTimer)
|
gc.arc('fill','pie',250,630,40,-1.5708,-1.5708-.6283*fetchTimer)
|
||||||
|
|
||||||
--Room list
|
--Room list
|
||||||
gc.push('transform')
|
local R=roomList:getSel()
|
||||||
gc.translate(listBoxPos.x,listBoxPos.y)
|
if R then
|
||||||
gc.setColor(1,1,1)
|
gc.translate(870,220)
|
||||||
gc.setLineWidth(2)
|
|
||||||
gc.rectangle('line',0,0,listBoxPos.w,listBoxPos.h)
|
|
||||||
local roomCount=#NET.roomList
|
|
||||||
if roomCount>0 then
|
|
||||||
if roomCount>10 then
|
|
||||||
local len=10*listBoxPos.h/roomCount
|
|
||||||
gc.rectangle('fill',-15,(listBoxPos.h-len)*scrollPos/(roomCount-10),12,len)
|
|
||||||
end
|
|
||||||
gc.stencil(roomListStencil,'replace',1)
|
|
||||||
gc.setStencilTest('equal',1)
|
|
||||||
gc.translate(0,scrollPos%1*-40)
|
|
||||||
setFont(35)
|
|
||||||
local pos=int(scrollPos)
|
|
||||||
for i=1,math.min(11,roomCount-pos)do
|
|
||||||
local R=NET.roomList[pos+i]
|
|
||||||
if pos+i==selected then
|
|
||||||
gc.setColor(1,1,1,.3)
|
|
||||||
gc.rectangle('fill',0,40*i-40,listBoxPos.w,40)
|
|
||||||
end
|
|
||||||
gc.setColor(1,1,1)
|
|
||||||
if R.private then gc.draw(IMG.lock,10,40*i-35)end
|
|
||||||
gc.print(R.count.."/"..R.capacity,670,40*i-44)
|
|
||||||
|
|
||||||
gc.setColor(.9,.9,1)
|
|
||||||
gc.print(pos+i,45,40*i-44)
|
|
||||||
|
|
||||||
if R.start then
|
|
||||||
gc.setColor(0,.4,.1)
|
|
||||||
else
|
|
||||||
gc.setColor(1,1,.7)
|
|
||||||
end
|
|
||||||
gc.print(R.roomInfo.name,200,40*i-44)
|
|
||||||
end
|
|
||||||
gc.setStencilTest()
|
|
||||||
|
|
||||||
gc.translate(820,130+scrollPos%1*40)
|
|
||||||
gc.setColor(1,1,1)
|
gc.setColor(1,1,1)
|
||||||
|
gc.setLineWidth(3)
|
||||||
gc.rectangle('line',0,0,385,335)
|
gc.rectangle('line',0,0,385,335)
|
||||||
if NET.roomList[selected]then
|
|
||||||
local R=NET.roomList[selected]
|
|
||||||
setFont(25)
|
setFont(25)
|
||||||
gc.print(R.roomInfo.type,10,25)
|
gc.print(R.roomInfo.type,10,25)
|
||||||
gc.setColor(1,1,.7)
|
gc.setColor(1,1,.7)
|
||||||
@@ -195,9 +109,8 @@ function scene.draw()
|
|||||||
end
|
end
|
||||||
gc.setColor(1,.2,0)
|
gc.setColor(1,.2,0)
|
||||||
gc.printf(R.roomInfo.version,10,300,365,'right')
|
gc.printf(R.roomInfo.version,10,300,365,'right')
|
||||||
|
gc.translate(-870,-220)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
gc.pop()
|
|
||||||
|
|
||||||
--Profile
|
--Profile
|
||||||
drawSelfProfile()
|
drawSelfProfile()
|
||||||
@@ -207,13 +120,14 @@ function scene.draw()
|
|||||||
end
|
end
|
||||||
|
|
||||||
scene.widgetList={
|
scene.widgetList={
|
||||||
|
roomList,
|
||||||
passwordBox,
|
passwordBox,
|
||||||
WIDGET.newKey{name="setting",fText=TEXTURE.setting,x=1200,y=160,w=90,h=90,code=pressKey"s"},
|
WIDGET.newKey{name="setting",fText=TEXTURE.setting,x=1200,y=160,w=90,h=90,code=pressKey"s"},
|
||||||
WIDGET.newText{name="refreshing",x=450,y=255,font=45,hideF=function()return not NET.getlock('fetchRoom')end},
|
WIDGET.newText{name="refreshing",x=450,y=255,font=45,hideF=function()return not NET.getlock('fetchRoom')end},
|
||||||
WIDGET.newText{name="noRoom", x=450,y=260,font=40,hideF=function()return #NET.roomList>0 or NET.getlock('fetchRoom')end},
|
WIDGET.newText{name="noRoom", x=450,y=260,font=40,hideF=function()return roomList:getLen()>0 or NET.getlock('fetchRoom')end},
|
||||||
WIDGET.newKey{name="refresh", x=250,y=630,w=140,h=120,font=35,code=fetchRoom,hideF=function()return fetchTimer>7 end},
|
WIDGET.newKey{name="refresh", x=250,y=630,w=140,h=120,font=35,code=fetchRoom,hideF=function()return fetchTimer>7 end},
|
||||||
WIDGET.newKey{name="new", x=510,y=630,w=260,h=120,font=30,code=pressKey"n"},
|
WIDGET.newKey{name="new", x=510,y=630,w=260,h=120,font=30,code=pressKey"n"},
|
||||||
WIDGET.newKey{name="join", x=780,y=630,w=140,h=120,font=40,code=pressKey"return",hideF=function()return #NET.roomList==0 or NET.getlock('enterRoom')end},
|
WIDGET.newKey{name="join", x=780,y=630,w=140,h=120,font=40,code=pressKey"return",hideF=function()return roomList:getLen()==0 or NET.getlock('enterRoom')end},
|
||||||
WIDGET.newButton{name="back", x=1140,y=640,w=170,h=80,fText=TEXTURE.back,code=backScene},
|
WIDGET.newButton{name="back", x=1140,y=640,w=170,h=80,fText=TEXTURE.back,code=backScene},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
15
parts/scenes/replays.lua
Normal file
15
parts/scenes/replays.lua
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
local gc=love.graphics
|
||||||
|
|
||||||
|
local scene={}
|
||||||
|
|
||||||
|
function scene.sceneInit()
|
||||||
|
end
|
||||||
|
|
||||||
|
function scene.draw()
|
||||||
|
end
|
||||||
|
|
||||||
|
scene.widgetList={
|
||||||
|
WIDGET.newButton{name="back", x=1140,y=640,w=170,h=80,fText=TEXTURE.back,code=backScene},
|
||||||
|
}
|
||||||
|
|
||||||
|
return scene
|
||||||
@@ -100,8 +100,9 @@ function scene.draw()
|
|||||||
end
|
end
|
||||||
|
|
||||||
scene.widgetList={
|
scene.widgetList={
|
||||||
WIDGET.newButton{name="path",x=780,y=540,w=250,h=80,font=25,code=function()love.system.openURL(SAVEDIR)end,hide=MOBILE},
|
WIDGET.newButton{name="path", x=800,y=540,w=250,h=80,font=25,code=function()love.system.openURL(SAVEDIR)end,hide=MOBILE},
|
||||||
WIDGET.newButton{name="save",x=780,y=640,w=250,h=80,font=25,code=goScene'savedata'},
|
WIDGET.newButton{name="save", x=800,y=640,w=250,h=80,font=25,code=goScene'savedata'},
|
||||||
|
WIDGET.newButton{name="replays",x=1100,y=540,w=250,h=80,font=25,code=goScene'replays'},
|
||||||
WIDGET.newButton{name="back", x=1140,y=640,w=170,h=80,fText=TEXTURE.back,code=backScene},
|
WIDGET.newButton{name="back", x=1140,y=640,w=170,h=80,fText=TEXTURE.back,code=backScene},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user