房间内玩家布局基本完成,添加鼠标悬浮显示详细信息框功能

This commit is contained in:
MrZ626
2021-05-04 17:37:22 +08:00
parent 175d9bd7d7
commit f68aa26278
3 changed files with 101 additions and 29 deletions

View File

@@ -1,4 +1,6 @@
local gc=love.graphics local gc=love.graphics
local max,min=math.max,math.min
local ins,rem=table.insert,table.remove local ins,rem=table.insert,table.remove
local posLists={ local posLists={
@@ -6,32 +8,52 @@ local posLists={
(function() (function()
local L={} local L={}
for i=1,5 do for i=1,5 do
L[i]={x=40,y=65+50*i,w=1000,h=46} L[i]={x=70,y=20+90*i,w=1000,h=80}
end end
return L return L
end)(), end)(),
--6~17 --6~17
(function() (function()
local L={} local L={}
for i=1,17 do for i=1,10 do
L[i]={x=40,y=65+50*i,w=1000,h=46} L[i]={x=40,y=60+55*i,w=520,h=50}
end
for i=1,7 do
L[10+i]={x=600,y=60+55*i,w=520,h=50}
end end
return L return L
end)(), end)(),
--18~31 --18~31
(function() (function()
local L={} local L={}
for i=1,31 do for i=1,11 do L[i]= {x=40,y=65+50*i,w=330,h=45}end
L[i]={x=40,y=65+50*i,w=1000,h=46} for i=1,11 do L[11+i]= {x=400,y=65+50*i,w=330,h=45}end
end for i=1,9 do L[22+i]= {x=760,y=65+50*i,w=330,h=45}end
return L return L
end)(), end)(),
--32~49 --32~49
(function() (function()
local L={} local L={}
for i=1,49 do for i=1,10 do L[i]= {x=30,y=60+50*i,w=200,h=45}end
L[i]={x=40,y=65+50*i,w=1000,h=46} for i=1,10 do L[10+i]= {x=240,y=60+50*i,w=200,h=45}end
end for i=1,10 do L[20+i]= {x=450,y=60+50*i,w=200,h=45}end
for i=1,10 do L[30+i]= {x=660,y=60+50*i,w=200,h=45}end
for i=1,9 do L[40+i]= {x=870,y=60+50*i,w=200,h=45}end
return L
end)(),
--50~99
(function()
local L={}
for i=1,11 do L[i]= {x=30,y=60+50*i,w=100,h=45}end
for i=1,11 do L[i+11]= {x=135,y=60+50*i,w=100,h=45}end
for i=1,11 do L[i+22]= {x=240,y=60+50*i,w=100,h=45}end
for i=1,11 do L[i+33]= {x=345,y=60+50*i,w=100,h=45}end
for i=1,11 do L[i+44]= {x=450,y=60+50*i,w=100,h=45}end
for i=1,11 do L[i+55]= {x=555,y=60+50*i,w=100,h=45}end
for i=1,11 do L[i+66]= {x=660,y=60+50*i,w=100,h=45}end
for i=1,11 do L[i+77]= {x=765,y=60+50*i,w=100,h=45}end
for i=1,7 do L[i+88]= {x=870,y=60+50*i,w=100,h=45}end
for i=1,4 do L[i+95]= {x=975,y=60+50*i,w=100,h=45}end
return L return L
end)(), end)(),
} }
@@ -52,10 +74,14 @@ local netPLY={list=PLY}
local function freshPosList() local function freshPosList()
if #PLY<=5 then if #PLY<=5 then
posList=posLists[1] posList=posLists[1]
elseif #PLY<=15 then elseif #PLY<=17 then
posList=posLists[2] posList=posLists[2]
elseif #PLY<=30 then elseif #PLY<=31 then
posList=posLists[3] posList=posLists[3]
elseif #PLY<=49 then
posList=posLists[4]
else--if #PLY<=99 then
posList=posLists[5]
end end
end end
@@ -64,7 +90,7 @@ function netPLY.clear()
end end
function netPLY.add(p) function netPLY.add(p)
ins(PLY,p.uid==USER.uid and 1 or #PLY+1,p) ins(PLY,p.uid==USER.uid and 1 or #PLY+1,p)
p.x,p.y,p.w,p.h=640,2600,0,0 p.x,p.y,p.w,p.h=2600,2600,0,0
freshPosList() freshPosList()
end end
function netPLY.remove(sid) function netPLY.remove(sid)
@@ -120,6 +146,19 @@ function netPLY.resetReady()
end end
end end
local selP,mouseX,mouseY
function netPLY.mouseMove(x,y)
selP=nil
for i=1,#PLY do
local p=PLY[i]
if x>p.x and y>p.y and x<p.x+p.w and y<p.y+p.h then
mouseX,mouseY=x,y
selP=p
break
end
end
end
function netPLY.update(dt) function netPLY.update(dt)
for i=1,#PLY do for i=1,#PLY do
local p=PLY[i] local p=PLY[i]
@@ -131,28 +170,58 @@ function netPLY.update(dt)
end end
end end
local stencilW,stencilH
local function plyStencil()
gc.rectangle('fill',0,0,stencilW,stencilH)
end
function netPLY.draw() function netPLY.draw()
for i=1,#PLY do for i=1,#PLY do
local p=PLY[i] local p=PLY[i]
gc.translate(p.x,p.y) gc.translate(p.x,p.y)
--Rectangle --Rectangle
gc.setColor(COLOR[p.ready and'G'or'Z']) gc.setColor(COLOR[p.ready and'G'or'Z'])
gc.setLineWidth(2) gc.setLineWidth(2)
gc.rectangle('line',0,0,p.w,p.h) gc.rectangle('line',0,0,p.w,p.h)
--UID --Stencil
setFont(40) stencilW,stencilH=p.w,p.h
gc.setColor(.5,.5,.5) gc.setStencilTest('equal',1)
gc.print("#"..p.uid,10,-5) gc.stencil(plyStencil,'replace',1)
gc.setColor(1,1,1)
--Avatar --Avatar
gc.setColor(1,1,1) local avatarSize=min(p.h,50)/128*.9
gc.draw(USERS.getAvatar(p.uid),160,3,nil,.3125) gc.draw(USERS.getAvatar(p.uid),2,2,nil,avatarSize)
--Username --UID & Username
gc.print(p.username,210,-5) if p.h>=47 then
setFont(40)
gc.print("#"..p.uid,50,-5)
gc.print(p.username,210,-5)
else
setFont(159)
gc.print("#"..p.uid,p.h,-2)
setFont(30)
gc.print(p.username,p.h,8)
end
gc.setStencilTest()
gc.translate(-p.x,-p.y) gc.translate(-p.x,-p.y)
end end
if selP then
gc.translate(min(mouseX,880),min(mouseY,460))
gc.setColor(.2,.2,.2,.7)
gc.rectangle('fill',0,0,400,260)
gc.setColor(1,1,1)
gc.setLineWidth(2)
gc.rectangle('line',0,0,400,260)
gc.draw(USERS.getAvatar(selP.uid),5,5,nil,.5)
setFont(30)
gc.print("#"..selP.uid,75,0)
setFont(35)
gc.print(selP.username,75,25)
gc.translate(-min(mouseX,880),-min(mouseY,460))
end
end end
return netPLY return netPLY

View File

@@ -33,6 +33,7 @@ function scene.sceneInit(org)
end end
scene.mouseDown=NULL scene.mouseDown=NULL
function scene.mouseMove(x,y)netPLY.mouseMove(x,y)end
function scene.touchDown(x,y) function scene.touchDown(x,y)
if noTouch or not playing then return end if noTouch or not playing then return end
@@ -51,8 +52,9 @@ function scene.touchUp(x,y)
VK.release(n) VK.release(n)
end end
end end
function scene.touchMove() function scene.touchMove(x,y)
if noTouch or touchMoveLastFrame or not playing then return end if not playing then netPLY.mouseMove(x,y)return end
if noTouch or touchMoveLastFrame then return end
touchMoveLastFrame=true touchMoveLastFrame=true
local L=tc.getTouches() local L=tc.getTouches()
@@ -160,6 +162,7 @@ function scene.socketRead(cmd,d)
if not playing then if not playing then
playing=true playing=true
netPLY.resetReady() netPLY.resetReady()
netPLY.mouseMove(0,0)
lastUpstreamTime=0 lastUpstreamTime=0
upstreamProgress=1 upstreamProgress=1
resetGameData('n',d.seed) resetGameData('n',d.seed)
@@ -269,7 +272,7 @@ end
scene.widgetList={ scene.widgetList={
textBox, textBox,
WIDGET.newKey{name="setting",fText=TEXTURE.setting,x=1200,y=160,w=90,h=90,code=pressKey"s",hide=function()return playing or netPLY.getReady(1)or NET.getlock('ready')end}, WIDGET.newKey{name="setting",fText=TEXTURE.setting,x=1200,y=160,w=90,h=90,code=pressKey"s",hide=function()return playing or netPLY.getReady(1)or NET.getlock('ready')end},
WIDGET.newKey{name="ready",x=900,y=560,w=400,h=100,color='lB',font=40,code=pressKey"space", WIDGET.newKey{name="ready",x=1060,y=630,w=300,h=80,color='lB',font=40,code=pressKey"space",
hide=function() hide=function()
return return
playing or playing or

View File

@@ -139,7 +139,7 @@ function scene.draw()
end end
if R.start then if R.start then
gc.setColor(0,1,0) gc.setColor(0,1,0)
gc.print(text.started,620,66+40*i) gc.print(text.started,660,66+40*i)
end end
gc.setColor(.9,.9,1) gc.setColor(.9,.9,1)
gc.print(pos+i,95,66+40*i) gc.print(pos+i,95,66+40*i)