删除游戏结束后的排名菜单,直接在玩家框内显示数据,详细信息也会显示motto

This commit is contained in:
MrZ626
2021-06-05 17:26:27 +08:00
parent 77a5774965
commit 918acf2b58
3 changed files with 74 additions and 77 deletions

View File

@@ -20,7 +20,6 @@ local NET={
private=false,
start=false,
},
resultList={},--List of {place,survivalTime,uid,score}
spectate=false,--If player is spectating
specSRID=false,--Cached SRID when enter playing room, for connect WS after scene swapped
seed=false,
@@ -490,11 +489,24 @@ function NET.updateWS_play()
NET.connectingStream=true
NET.wsconn_stream(d.srid)
elseif res.action==9 then--Game finished
NET.roomState.start=false
NET.spectate=false
if NET.spectate then NET.signal_setMode(2) end
if SCN.socketRead then SCN.socketRead('finish',d)end
--d.result: list of {place,survivalTime,uid,score}
for _,p in next,d.result do
for _,P in next,PLAYERS do
if P.uid==p.uid then
netPLY.setStat(p.uid,P.stat)
netPLY.setPlace(p.uid,p.place)
break
end
end
end
netPLY.resetState()
netPLY.freshPos()
NET.roomState.start=false
if NET.spectate then NET.signal_setMode(2)end
NET.spectate=false
NET.wsclose_stream()
end
else

View File

@@ -1,5 +1,5 @@
local gc=love.graphics
local gc_draw,gc_rectangle,gc_print=gc.draw,gc.rectangle,gc.print
local gc_draw,gc_rectangle,gc_print,gc_printf=gc.draw,gc.rectangle,gc.print,gc.printf
local gc_setColor,gc_setLineWidth,gc_translate=gc.setColor,gc.setLineWidth,gc.translate
local gc_stencil,gc_setStencilTest=gc.stencil,gc.setStencilTest
@@ -94,7 +94,7 @@ function netPLY.add(p)
p.connected=false
p.username=USERS.getUsername(p.uid)
p.place=1e99
p.stat={}
p.stat=false
local a=rnd()*6.2832
p.x,p.y,p.w,p.h=640+2600*cos(a),360+2600*sin(a),47,47
@@ -105,7 +105,6 @@ end
function netPLY.getCount()return #PLYlist end
function netPLY.getSID(uid)return PLYmap[uid].sid end
function netPLY.getStat(uid)return PLYmap[uid].stat end
function netPLY.getSelfJoinMode()return PLYmap[USER.uid].mode end
function netPLY.getSelfReady()return PLYmap[USER.uid].mode>0 end
@@ -136,10 +135,11 @@ end
function netPLY.setConnect(uid)PLYmap[uid].connected=true end
function netPLY.setPlace(uid,place)PLYmap[uid].place=place end
function netPLY.setStat(uid,S)
local p=PLYmap[uid]
p.stat.lpm=("%.1f %s"):format(S.row/S.time*60,text.radarData[5])
p.stat.apm=("%.1f %s"):format(S.atk/S.time*60,text.radarData[3])
p.stat.adpm=("%.1f %s"):format((S.atk+S.dig)/S.time*60,text.radarData[2])
PLYmap[uid].stat={
lpm=("%.1f %s"):format(S.row/S.time*60,text.radarData[5]),
apm=("%.1f %s"):format(S.atk/S.time*60,text.radarData[3]),
adpm=("%.1f %s"):format((S.atk+S.dig)/S.time*60,text.radarData[2]),
}
end
function netPLY.resetState()
for i=1,#PLYlist do
@@ -210,6 +210,21 @@ function netPLY.draw()
setFont(30)
gc_print(p.username,p.h,8)
end
--Stat
local S=p.stat
if S and(p.h>=55 or p.w>=180)then
setFont(20)
local x=p.w-155
if p.h>=55 then
gc_printf(S.adpm,x,2,150,'right')
gc_printf(S.apm,x,24,150,'right')
gc_printf(S.lpm,x,46,150,'right')
else
gc_printf(S.adpm,x,0,150,'right')
gc_printf(S.lpm,x,19,150,'right')
end
end
gc_setStencilTest()
gc_translate(-p.x,-p.y)
end
@@ -226,6 +241,14 @@ function netPLY.draw()
gc_print("#"..selP.uid,75,0)
setFont(35)
gc_print(selP.username,75,25)
setFont(20)
gc_printf(USERS.getMotto(selP.uid),5,70,390)
if selP.stat then
local S=selP.stat
gc_print(S.lpm,5,193)
gc_print(S.apm,5,213)
gc_print(S.adpm,5,233)
end
gc_translate(-min(mouseX,880),-min(mouseY,460))
end
end

View File

@@ -1,8 +1,8 @@
local gc,kb,tc=love.graphics,love.keyboard,love.touch
local gc_setColor,gc_setLineWidth=gc.setColor,gc.setLineWidth
local gc_setColor=gc.setColor
local gc_print,gc_printf=gc.print,gc.printf
local gc_draw,gc_rectangle=gc.draw,gc.rectangle
local gc_draw=gc.draw
local setFont,mStr=setFont,mStr
local ins=table.insert
@@ -13,7 +13,7 @@ local PLAYERS,GAME=PLAYERS,GAME
local textBox=WIDGET.newTextBox{name="texts",x=340,y=80,w=600,h=560}
local inputBox=WIDGET.newInputBox{name="input",x=340,y=660,w=600,h=50}
local playing,stat
local playing
local lastUpstreamTime
local upstreamProgress
local lastBackTime=0
@@ -21,10 +21,9 @@ local noTouch,noKey=false,false
local touchMoveLastFrame=false
local newMessageTimer
local function _playerSort(a,b)return a.place<b.place end
local function _setCancel()NET.signal_setMode(0)end
local function _setReady()NET.signal_setMode(1)end
local function _setSpectate()NET.signal_setMode(2)end
local function _setCancel()NET.signal_setMode(0)end
local function _gotoSetting()
if not(netPLY.getSelfReady()or NET.getlock('ready'))then
SCN.go('setting_game')
@@ -38,11 +37,6 @@ local function _quit()
LOG.print(text.sureQuit,'warn')
end
end
local function _switchStat()
if not playing and #NET.resultList>0 then
stat=not stat
end
end
local function _switchChat()
if inputBox.hide then
textBox.hide=false
@@ -64,7 +58,6 @@ function scene.sceneInit(org)
noTouch=not SETTING.VKSwitch
playing=false
stat=false
lastUpstreamTime=0
upstreamProgress=1
newMessageTimer=0
@@ -76,7 +69,6 @@ function scene.sceneInit(org)
end
end
function scene.sceneBack()
NET.resultList={}
love.keyboard.setKeyRepeat(true)
end
@@ -145,6 +137,16 @@ function scene.keyDown(key)
elseif not inputBox.hide then
WIDGET.focus(inputBox)
inputBox:keypress(key)
elseif key:find("[123456789]")then
for _=1,tonumber(key)do
netPLY.add{
uid=tostring(6000+#netPLY.list+1),
username="Test Player"..tostring(#netPLY.list+1),
sid=tostring(#netPLY.list+1),
mode=0,
config="",
}
end
elseif playing then
if noKey then return end
local k=keyMap.keyboard[key]
@@ -159,8 +161,6 @@ function scene.keyDown(key)
else
_setCancel()
end
elseif key=="tab"then
_switchStat()
elseif key=="s"then
_gotoSetting()
end
@@ -230,19 +230,6 @@ function scene.socketRead(cmd,d)
elseif cmd=='finish'then
playing=false
love.keyboard.setKeyRepeat(true)
table.sort(d.result,_playerSort)
NET.resultList=d.result
for _,p in next,NET.resultList do
p.username=USERS.getUsername(p.uid)
for _,P in next,PLAYERS do
if P.uid==p.uid then
netPLY.setStat(p.uid,P.stat)
netPLY.setPlace(p.uid,p.place)
break
end
end
end
netPLY.resetState()
elseif cmd=='stream'then
if d.uid~=USER.uid then
for _,P in next,PLAYERS do
@@ -294,7 +281,7 @@ function scene.update(dt)
NET.uploadRecStream(stream)
lastUpstreamTime=PLAYERS[1].alive and P1.frameRun or 1e99
end
elseif not stat then
else
netPLY.update()
end
if newMessageTimer>0 then
@@ -323,32 +310,20 @@ function scene.draw()
gc_print(text.spectating,940,0)
end
else
if stat then
gc_setColor(1,1,1)
gc_setLineWidth(4)
gc_rectangle('line',75,90,730,555)
local L=NET.resultList
for i=1,#L do
local p=L[i]
setFont(30)gc_print("-"..p.place.."-",100,58+40*i)
setFont(25)gc_print(p.username,160,60+40*i)
end
else
--Users
netPLY.draw()
--Users
netPLY.draw()
--Ready & Set mark
setFont(50)
if NET.allReady then
gc_setColor(0,1,.5,.9)
mStr(text.ready,640,15)
elseif NET.connectingStream then
gc_setColor(.1,1,.8,.9)
mStr(text.connStream,640,15)
elseif NET.waitingStream then
gc_setColor(0,.8,1,.9)
mStr(text.waitStream,640,15)
end
--Ready & Set mark
setFont(50)
if NET.allReady then
gc_setColor(0,1,.5,.9)
mStr(text.ready,640,15)
elseif NET.connectingStream then
gc_setColor(.1,1,.8,.9)
mStr(text.connStream,640,15)
elseif NET.waitingStream then
gc_setColor(0,.8,1,.9)
mStr(text.waitStream,640,15)
end
--Room info.
@@ -402,19 +377,6 @@ scene.widgetList={
not netPLY.getSelfReady() or
NET.getlock('ready')
end},
WIDGET.newKey{name="showResult",x=310,y=35,w=60,font=35,code=_switchStat,
hideF=function()
return
playing or
#NET.resultList==0
end,
fText=DOGC{50,40,
{'setLW',4},
{'dRect',2,38,15,-15},
{'dRect',17,38,15,-24},
{'dRect',32,38,16,-10},
},
},
WIDGET.newKey{name="hideChat",fText="...",x=380,y=35,w=60,font=35,code=_switchChat},
WIDGET.newKey{name="quit",fText="X",x=900,y=35,w=60,font=40,code=_quit},
}