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

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 max,min=math.max,math.min
local ins,rem=table.insert,table.remove
local posLists={
@@ -6,32 +8,52 @@ local posLists={
(function()
local L={}
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
return L
end)(),
--6~17
(function()
local L={}
for i=1,17 do
L[i]={x=40,y=65+50*i,w=1000,h=46}
for i=1,10 do
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
return L
end)(),
--18~31
(function()
local L={}
for i=1,31 do
L[i]={x=40,y=65+50*i,w=1000,h=46}
end
for i=1,11 do L[i]= {x=40,y=65+50*i,w=330,h=45}end
for i=1,11 do L[11+i]= {x=400,y=65+50*i,w=330,h=45}end
for i=1,9 do L[22+i]= {x=760,y=65+50*i,w=330,h=45}end
return L
end)(),
--32~49
(function()
local L={}
for i=1,49 do
L[i]={x=40,y=65+50*i,w=1000,h=46}
end
for i=1,10 do L[i]= {x=30,y=60+50*i,w=200,h=45}end
for i=1,10 do L[10+i]= {x=240,y=60+50*i,w=200,h=45}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
end)(),
}
@@ -52,10 +74,14 @@ local netPLY={list=PLY}
local function freshPosList()
if #PLY<=5 then
posList=posLists[1]
elseif #PLY<=15 then
elseif #PLY<=17 then
posList=posLists[2]
elseif #PLY<=30 then
elseif #PLY<=31 then
posList=posLists[3]
elseif #PLY<=49 then
posList=posLists[4]
else--if #PLY<=99 then
posList=posLists[5]
end
end
@@ -64,7 +90,7 @@ function netPLY.clear()
end
function netPLY.add(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()
end
function netPLY.remove(sid)
@@ -120,6 +146,19 @@ function netPLY.resetReady()
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)
for i=1,#PLY do
local p=PLY[i]
@@ -131,28 +170,58 @@ function netPLY.update(dt)
end
end
local stencilW,stencilH
local function plyStencil()
gc.rectangle('fill',0,0,stencilW,stencilH)
end
function netPLY.draw()
for i=1,#PLY do
local p=PLY[i]
gc.translate(p.x,p.y)
--Rectangle
gc.setColor(COLOR[p.ready and'G'or'Z'])
gc.setLineWidth(2)
gc.rectangle('line',0,0,p.w,p.h)
--Rectangle
gc.setColor(COLOR[p.ready and'G'or'Z'])
gc.setLineWidth(2)
gc.rectangle('line',0,0,p.w,p.h)
--UID
setFont(40)
gc.setColor(.5,.5,.5)
gc.print("#"..p.uid,10,-5)
--Stencil
stencilW,stencilH=p.w,p.h
gc.setStencilTest('equal',1)
gc.stencil(plyStencil,'replace',1)
gc.setColor(1,1,1)
--Avatar
gc.setColor(1,1,1)
gc.draw(USERS.getAvatar(p.uid),160,3,nil,.3125)
--Avatar
local avatarSize=min(p.h,50)/128*.9
gc.draw(USERS.getAvatar(p.uid),2,2,nil,avatarSize)
--Username
gc.print(p.username,210,-5)
--UID & Username
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)
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
return netPLY

View File

@@ -33,6 +33,7 @@ function scene.sceneInit(org)
end
scene.mouseDown=NULL
function scene.mouseMove(x,y)netPLY.mouseMove(x,y)end
function scene.touchDown(x,y)
if noTouch or not playing then return end
@@ -51,8 +52,9 @@ function scene.touchUp(x,y)
VK.release(n)
end
end
function scene.touchMove()
if noTouch or touchMoveLastFrame or not playing then return end
function scene.touchMove(x,y)
if not playing then netPLY.mouseMove(x,y)return end
if noTouch or touchMoveLastFrame then return end
touchMoveLastFrame=true
local L=tc.getTouches()
@@ -160,6 +162,7 @@ function scene.socketRead(cmd,d)
if not playing then
playing=true
netPLY.resetReady()
netPLY.mouseMove(0,0)
lastUpstreamTime=0
upstreamProgress=1
resetGameData('n',d.seed)
@@ -269,7 +272,7 @@ end
scene.widgetList={
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="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()
return
playing or

View File

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