From 74d493199ff6ff48e6d6ea60582269d9a9d1fb0f Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Tue, 27 Apr 2021 15:18:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=BF=E9=97=B4=E9=80=89=E6=8B=A9=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=94=AF=E6=8C=81=E5=B9=B3=E6=BB=91=E6=BB=9A=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parts/scenes/net_rooms.lua | 75 ++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/parts/scenes/net_rooms.lua b/parts/scenes/net_rooms.lua index 82fb9e10..3002fd9c 100644 --- a/parts/scenes/net_rooms.lua +++ b/parts/scenes/net_rooms.lua @@ -22,23 +22,8 @@ function scene.sceneInit() fetchRoom() end -local floatWheel=0 function scene.wheelMoved(_,y) - if y>0 then - if floatWheel<0 then floatWheel=0 end - floatWheel=floatWheel+y^1.2 - elseif y<0 then - if floatWheel>0 then floatWheel=0 end - floatWheel=floatWheel-(-y)^1.2 - end - while floatWheel>=1 do - scrollPos=max(0,min(scrollPos-1,#NET.roomList-10)) - floatWheel=floatWheel-1 - end - while floatWheel<=-1 do - scrollPos=max(0,min(scrollPos+1,#NET.roomList-10)) - floatWheel=floatWheel+1 - end + scrollPos=max(0,min(scrollPos-y,#NET.roomList-10)) end function scene.keyDown(k) if k=="r"then @@ -84,23 +69,29 @@ function scene.keyDown(k) end end -function scene.mouseMove(_,_,_,dy) - if ms.isDown(1)then - scene.wheelMoved(0,dy/30) +function scene.mouseMove(x,y,_,dy) + if ms.isDown(1)and x>50 and x<1230 and y>110 and y<510 then + scene.wheelMoved(0,dy/40) + end +end +function scene.touchMove(x,y,_,dy) + if x>50 and x<1230 and y>110 and y<510 then + scene.wheelMoved(0,dy/40) end end function scene.mouseClick(x,y) if x>50 and x<1230 then y=int((y-70)/40) if y>=1 and y<=10 then - print(y+scrollPos) - selected=y+scrollPos + local s=int(y+scrollPos) + if selected~=s then + selected=s + else + scene.keyDown("return") + end end end end -function scene.touchMove(_,_,_,dy) - scene.wheelMoved(0,dy/30) -end scene.touchClick=scene.mouseClick function scene.update(dt) @@ -110,11 +101,12 @@ function scene.update(dt) fetchRoom() end end - if #NET.roomList>0 and not NET.roomList[selected]then - selected=#NET.roomList - end + selected=min(selected,#NET.roomList) end +local function roomListStencil() + gc.rectangle("fill",50,110,1180,400) +end function scene.draw() --Fetching timer gc.setColor(1,1,1,.12) @@ -124,29 +116,40 @@ function scene.draw() gc.setColor(1,1,1) gc.setLineWidth(2) gc.rectangle("line",50,110,1180,400) - if #NET.roomList>0 then + local roomCount=#NET.roomList + if roomCount>0 then setFont(35) - for i=1,math.min(10,#NET.roomList-scrollPos)do - local R=NET.roomList[scrollPos+i] - if scrollPos+i==selected then + gc.push("transform") + gc.stencil(roomListStencil,"replace",1) + gc.setStencilTest("equal",1) + gc.translate(0,scrollPos%1*-40) + 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",50,70+40*i,1180,40) end - if R.private then - gc.setColor(1,1,1) - gc.draw(IMG.lock,59,75+40*i) - end if R.start then gc.setColor(0,1,0) gc.print(text.started,800,66+40*i) end gc.setColor(.9,.9,1) - gc.print(scrollPos+i,95,66+40*i) + gc.print(pos+i,95,66+40*i) gc.setColor(1,1,.7) gc.print(R.name,250,66+40*i) gc.setColor(1,1,1) gc.printf(R.type,550,66+40*i,500,"right") gc.print(R.count.."/"..R.capacity,1100,66+40*i) + if R.private then + gc.draw(IMG.lock,59,75+40*i) + end + end + gc.setStencilTest() + gc.pop() + if roomCount>10 then + local len=400*10/roomCount + gc.rectangle("fill",1218,110+(400-len)*scrollPos/(roomCount-10),12,len) end end