drawNext系列函数整理合并(略微牺牲性能),玩家用的绘制函数完全放入draw.lua

游戏参数新增holdMode
默认'hold'为普通hold模式
'swap'为跟next第一个交换(跟物理hold/多hold均兼容)
This commit is contained in:
MrZ626
2021-09-24 13:35:17 +08:00
parent 9fa4b97e5e
commit 4f939d7ea4
15 changed files with 250 additions and 209 deletions

View File

@@ -205,6 +205,7 @@ ROOMENV={
--Control
nextCount=6,
holdMode='hold',
holdCount=1,
infHold=false,
phyHold=false,
@@ -249,6 +250,7 @@ SETTING={--Settings
dascut=0,dropcut=0,
sddas=0,sdarr=2,
ihs=true,irs=true,ims=true,
holdMode='hold',
RS='TRS',
swap=true,
FTLock=true,

View File

@@ -300,6 +300,7 @@ return{
eventSet="Rule Set",
holdMode="Hold Mode",
nextCount="Next",
holdCount="Hold",
infHold="Infinite Hold",
@@ -491,6 +492,7 @@ return{
eventSet="Rule Set",
holdMode="Hold Mode",
nextCount="Next",
holdCount="Hold",
infHold="Infinite Hold",

View File

@@ -266,6 +266,7 @@ return{
-- eventSet="Rule Set",
-- holdMode="Hold Mode",
nextCount="Siguiente",
holdCount="Reserva",
infHold="Reserva Inft.",
@@ -455,6 +456,7 @@ return{
-- eventSet="Rule Set",
-- holdMode="Hold Mode",
nextCount="Siguiente",
holdCount="Reserva",
infHold="Reserva Inft.",

View File

@@ -262,6 +262,7 @@ return{
-- eventSet="Rule Set",
-- holdMode="Hold Mode",
nextCount="Prévisualisations de pièces",
holdCount="Réserve",
infHold="Réserver une fois",
@@ -457,6 +458,7 @@ return{
-- eventSet="Rule Set",
-- holdMode="Hold Mode",
nextCount="Prévisualisations de pièces",
holdCount="Réserve",
infHold="Réserver une fois",

View File

@@ -288,6 +288,7 @@ return{
-- eventSet="Rule Set",
-- holdMode="Hold Mode",
nextCount="Prox.",
holdCount="Segurar",
infHold="Segurar Infinito",
@@ -479,6 +480,7 @@ return{
-- eventSet="Rule Set",
-- holdMode="Hold Mode",
nextCount="Prox.",
holdCount="Segurar",
infHold="Segurar Infinito",

View File

@@ -181,6 +181,7 @@ return{
eventSet="Rule Set",
holdMode="? [ ]",
nextCount="",
holdCount="[ ]",
infHold="∞*[ ]",
@@ -370,6 +371,7 @@ return{
eventSet="Rule Set",
holdMode="? [ ]",
nextCount="",
holdCount="[ ]",
infHold="∞*[ ]",

View File

@@ -300,6 +300,7 @@ return{
eventSet="规则包",
holdMode="Hold模式",
nextCount="Next",
holdCount="Hold",
infHold="无限Hold",
@@ -490,6 +491,7 @@ return{
eventSet="规则包",
holdMode="Hold模式",
nextCount="Next",
holdCount="Hold",
infHold="无限Hold",

View File

@@ -56,6 +56,14 @@ return{
mod={
title="模组",
},
net_newRoom={
ospin="O旋",
holdMode="暂存模式",
nextCount="预览个数",
holdCount="暂存个数",
infHold="无限暂存",
phyHold="物理暂存",
},
setting_control={
das="首次移动延迟",arr="移动重复延迟",
sddas="首次软降延迟",sdarr="软降重复延迟",
@@ -67,6 +75,8 @@ return{
customGame={
mod="模组(F1)",
ospin="O旋",
holdMode="暂存模式",
nextCount="预览个数",
holdCount="暂存个数",
infHold="无限暂存",

View File

@@ -301,6 +301,7 @@ return{
eventSet="规则集",
holdMode="持有模式",
nextCount="下一个",
holdCount="持有",
infHold="无限持有",
@@ -491,6 +492,7 @@ return{
eventSet="规则集",
holdMode="持有模式",
nextCount="下一个",
holdCount="持有",
infHold="无限持有",

View File

@@ -86,7 +86,7 @@ local function _parseNotice(str)
str[m:sub(1,m:find("=")-1)]=m:sub(m:find("=")+1)
end
end
return str[SETTING.locale]or str[1]
return str[SETTING.locale]or str[SETTING.locale:find'zh'and'zh'or'en']
else
return str
end

View File

@@ -386,6 +386,8 @@ local function _drawHold(holdQueue,holdCount,holdTime,skinLib)
N=#holdQueue<holdCount and holdQueue[1]and 1 or holdTime+1
gc_push('transform')
gc_translate(50,40)
gc_setLineWidth(8)
gc_setColor(1,1,1)
gc_setShader(shader_blockSatur)
for n=1,#holdQueue do
if n==N then gc_setColor(.6,.4,.4)end
@@ -405,6 +407,80 @@ local function _drawHold(holdQueue,holdCount,holdTime,skinLib)
gc_pop()
gc_pop()
end
local function _drawNext(P,repMode)
local ENV=P.gameEnv
local texture=P.skinLib
gc_translate(488,20)
gc_setLineWidth(2)
local N=ENV.nextCount*72
gc_setColor(ENV.nextStartPos>1 and .5 or 0,0,0,.4)
gc_rectangle('fill',0,0,100,N+8,5)
gc_setColor(.97,.97,.97)
if ENV.holdMode=='swap'then gc_rectangle('fill',1,72*ENV.holdCount+2,50,4)end
gc_rectangle('line',0,0,100,N+8,5)
gc_push('transform')
gc_translate(50,40)
--Draw nexts
gc_setLineWidth(6)
gc_setColor(1,1,1,.2)
gc_setShader(shader_blockSatur)
gc_setColor(1,1,1,.8)
local queue=P.nextQueue
local hiding=true
local startNID=min(ENV.nextStartPos,P.pieceCount+1)
N=1
while N<=ENV.nextCount and queue[N]do
if hiding and N==startNID then
gc_setColor(1,1,1)
hiding=false
end
if not hiding or repMode then
local bk,sprite=queue[N].bk,texture[queue[N].color]
local k=min(2.3/#bk,3/#bk[1],.85)
gc_scale(k)
for i=1,#bk do for j=1,#bk[1]do
if bk[i][j]then
gc_draw(sprite,30*(j-#bk[1]*.5)-30,-30*(i-#bk*.5))
end
end end
gc_scale(1/k)
end
if ENV.holdMode=='swap'and N<=ENV.holdCount-P.holdTime then
gc_line(-40,-25,40,25)
end
gc_translate(0,72)
N=N+1
end
gc_setShader()
--Draw more nexts
if repMode then
gc_translate(50,-28)
local blockImg=TEXTURE.miniBlock
local skinSet=ENV.skin
local n=N
while n<=12 and queue[n]do
local id=queue[n].id
local _=minoColor[skinSet[id]]
gc_setColor(_[1],_[2],_[3],.2)
_=blockImg[id]
local h=_:getHeight()
gc_draw(_,-_:getWidth()*10,0,nil,10,nil)
gc_translate(0,10*h+3)
n=n+1
end
end
gc_pop()
if ENV.bagLine then
gc_setColor(.8,.8,.8,.8)
for i=-P.pieceCount%ENV.bagLine,N-1,ENV.bagLine do--i=phase
gc_rectangle('fill',1,72*i+3,98,2)
end
end
gc_translate(-488,-20)
end
local function _drawDial(x,y,speed)
gc_setColor(1,1,1,.7)
gc_draw(dialFrame,x,y)
@@ -506,129 +582,6 @@ local draw={}
draw.drawGhost=drawGhost
draw.applyField=_applyField
draw.cancelField=_cancelField
function draw.drawNext_norm(P,repMode)
local ENV=P.gameEnv
local texture=P.skinLib
gc_translate(488,20)
gc_setLineWidth(2)
local N=ENV.nextCount*72
gc_setColor(0,0,0,.4)gc_rectangle('fill',0,0,100,N+8,5)
gc_setColor(.97,.97,.97)gc_rectangle('line',0,0,100,N+8,5)
N=1
gc_push('transform')
gc_translate(50,40)
gc_setColor(1,1,1)
--Draw nexts
gc_setShader(shader_blockSatur)
local queue=P.nextQueue
while N<=ENV.nextCount and queue[N]do
local bk,sprite=queue[N].bk,texture[queue[N].color]
local k=min(2.3/#bk,3/#bk[1],.85)
gc_scale(k)
for i=1,#bk do for j=1,#bk[1]do
if bk[i][j]then
gc_draw(sprite,30*(j-#bk[1]*.5)-30,-30*(i-#bk*.5))
end
end end
gc_scale(1/k)
N=N+1
gc_translate(0,72)
end
gc_setShader()
--Draw more nexts
if repMode then
gc_translate(50,-28)
local blockImg=TEXTURE.miniBlock
local skinSet=ENV.skin
local n=N
while n<=12 and queue[n]do
local id=queue[n].id
local _=minoColor[skinSet[id]]
gc_setColor(_[1],_[2],_[3],.2)
_=blockImg[id]
local h=_:getHeight()
gc_draw(_,-_:getWidth()*10,0,nil,10,nil)
gc_translate(0,10*h+3)
n=n+1
end
end
gc_pop()
if ENV.bagLine then
gc_setColor(.8,.8,.8,.8)
for i=-P.pieceCount%ENV.bagLine,N-1,ENV.bagLine do--i=phase
gc_rectangle('fill',1,72*i+3,98,2)
end
end
gc_translate(-488,-20)
end
function draw.drawNext_hidden(P,repMode)
local ENV=P.gameEnv
local texture=P.skinLib
gc_translate(488,20)
gc_setLineWidth(2)
local N=ENV.nextCount*72
gc_setColor(.5,0,0,.4)gc_rectangle('fill',0,0,100,N+8,5)
gc_setColor(.97,.97,.97)gc_rectangle('line',0,0,100,N+8,5)
local startN=min(ENV.nextStartPos,P.pieceCount+1)
if repMode then
gc_setColor(1,1,1,.2)
N=1
else
gc_setColor(1,1,1)
N=startN
end
gc_push('transform')
gc_translate(50,72*N-32)
--Draw nexts
gc_setShader(shader_blockSatur)
local queue=P.nextQueue
while N<=ENV.nextCount and queue[N]do
if N==startN then gc_setColor(1,1,1)end
local bk,sprite=queue[N].bk,texture[queue[N].color]
local k=min(2.3/#bk,3/#bk[1],.85)
gc_scale(k)
for i=1,#bk do for j=1,#bk[1]do
if bk[i][j]then
gc_draw(sprite,30*(j-#bk[1]*.5)-30,-30*(i-#bk*.5))
end
end end
gc_scale(1/k)
N=N+1
gc_translate(0,72)
end
gc_setShader()
--Draw more nexts
if repMode then
gc_translate(50,-28)
local blockImg=TEXTURE.miniBlock
local skinSet=ENV.skin
local n=N
while n<=12 and queue[n]do
local id=queue[n].id
local _=minoColor[skinSet[id]]
gc_setColor(_[1],_[2],_[3],.2)
_=blockImg[id]
local h=_:getHeight()
gc_draw(_,-_:getWidth()*10,0,nil,10,nil)
gc_translate(0,10*h+3)
n=n+1
end
end
gc_pop()
if ENV.bagLine then
gc_setColor(.8,.8,.8,.8)
for i=-P.pieceCount%ENV.bagLine,N-1,ENV.bagLine do--i=phase
gc_rectangle('fill',1,72*i+3,98,2)
end
end
gc_translate(-476,-20)
end
function draw.drawTargetLine(P,r)
if r<=20+(P.fieldBeneath+P.fieldUp+10)/30 and r>0 then
gc_setLineWidth(3)
@@ -680,9 +633,9 @@ function draw.norm(P,repMode)
mStr(P.username,300,-60)
--Draw HUD
P:drawNext(repMode)
if ENV.nextCount>0 then _drawNext(P,repMode)end
if ENV.holdMode=='hold'and ENV.holdCount>0 then _drawHold(P.holdQueue,ENV.holdCount,P.holdTime,P.skinLib)end
if P.curMission then _drawMission(P.curMission,ENV.mission,ENV.missionKill)end
if ENV.holdCount>0 then _drawHold(P.holdQueue,ENV.holdCount,P.holdTime,P.skinLib)end
_drawDial(499,505,P.dropSpeed)
if P.life>0 then _drawLife(P.life)end

View File

@@ -34,7 +34,8 @@ return{
bone=false,
fieldH=20,heightLimit=1e99,
nextCount=6,nextStartPos=1,
holdCount=1,infHold=false,phyHold=false,
holdMode='hold',holdCount=1,
infHold=false,phyHold=false,
ospin=true,deepDrop=false,
RS='TRS',
sequence='bag',

View File

@@ -362,7 +362,7 @@ local function _applyGameEnv(P)--Finish gameEnv processing
)
P:set20G(P._20G)
P:setHold(ENV.holdCount)
P:setNext(ENV.nextCount,ENV.nextStartPos>1)
P:setNext(ENV.nextCount)
P:setRS(ENV.RS)
if type(ENV.mission)=='table'then

View File

@@ -13,8 +13,6 @@ local SFX,BGM,VOC,VIB,SYSFX=SFX,BGM,VOC,VIB,SYSFX
local FREEROW,TABLE,TEXT,TASK=FREEROW,TABLE,TEXT,TASK
local PLAYERS,PLY_ALIVE,GAME=PLAYERS,PLY_ALIVE,GAME
local ply_draw=require"parts.player.draw"
--------------------------<FX>--------------------------
function Player:_showText(text,dx,dy,font,style,spd,stop)
ins(self.bonus,TEXT.getText(text,150+dx,300+dy,font,style,spd,stop))
@@ -266,15 +264,8 @@ function Player:setHold(count)--Set hold count (false/true as 0/1)
self.holdTime=count
while self.holdQueue[count+1]do rem(self.holdQueue)end
end
function Player:setNext(next,hidden)--Set next count (use hidden=true if set env.nextStartPos>1)
function Player:setNext(next)--Set next count
self.gameEnv.nextCount=next
if next==0 then
self.drawNext=NULL
elseif not hidden then
self.drawNext=ply_draw.drawNext_norm
else
self.drawNext=ply_draw.drawNext_hidden
end
end
function Player:setInvisible(time)--Time in frames
if time<0 then
@@ -813,86 +804,155 @@ local phyHoldKickX={
[true]={0,-1,1},--X==?.0 tests
[false]={-.5,.5},--X==?.5 tests
}
function Player:hold(ifpre)
function Player:hold_norm(ifpre)
local ENV=self.gameEnv
if self.holdTime>0 and(ifpre or self.waiting==-1)then
if #self.holdQueue<ENV.holdCount and self.nextQueue[1]then--Skip
local C=self.cur
ins(self.holdQueue,self:getBlock(C.id,C.name,C.color))
if #self.holdQueue<ENV.holdCount and self.nextQueue[1]then--Skip
local C=self.cur
ins(self.holdQueue,self:getBlock(C.id,C.name,C.color))
local t=self.holdTime
self:popNext(true)
self.holdTime=t
else--Hold
local C,H=self.cur,self.holdQueue[1]
local t=self.holdTime
self:popNext(true)
self.holdTime=t
else--Hold
local C,H=self.cur,self.holdQueue[1]
self.ctrlCount=0
--Finesse check
if H and C and H.id==C.id and H.name==C.name then
self.ctrlCount=self.ctrlCount+1
elseif self.ctrlCount<=1 then
self.ctrlCount=0
end
if ENV.phyHold and C and not ifpre then--Physical hold
local x,y=self.curX,self.curY
x=x+(#C.bk[1]-#H.bk[1])*.5
y=y+(#C.bk-#H.bk)*.5
if ENV.phyHold and C and not ifpre then--Physical hold
local x,y=self.curX,self.curY
x=x+(#C.bk[1]-#H.bk[1])*.5
y=y+(#C.bk-#H.bk)*.5
local iki=phyHoldKickX[x==int(x)]
for Y=int(y),ceil(y+.5)do
for i=1,#iki do
local X=x+iki[i]
if not self:ifoverlap(H.bk,X,Y)then
x,y=X,Y
goto BREAK_success
end
local iki=phyHoldKickX[x==int(x)]
for Y=int(y),ceil(y+.5)do
for i=1,#iki do
local X=x+iki[i]
if not self:ifoverlap(H.bk,X,Y)then
x,y=X,Y
goto BREAK_success
end
end
--<for-else> All test failed, interrupt with sound
SFX.play('finesseError')
do return end
--<for-end>
::BREAK_success::
end
--<for-else> All test failed, interrupt with sound
SFX.play('finesseError')
do return end
--<for-end>
::BREAK_success::
self.spinLast=false
self.spinLast=false
local hb=self:getBlock(C.id)
hb.name=C.name
hb.color=C.color
ins(self.holdQueue,hb)
self.cur=rem(self.holdQueue,1)
self.curX,self.curY=x,y
else--Normal hold
self.spinLast=false
if C then
local hb=self:getBlock(C.id)
hb.name=C.name
hb.color=C.color
hb.name=C.name
ins(self.holdQueue,hb)
self.cur=rem(self.holdQueue,1)
self.curX,self.curY=x,y
else--Normal hold
self.spinLast=false
end
self.cur=rem(self.holdQueue,1)
if C then
local hb=self:getBlock(C.id)
hb.color=C.color
hb.name=C.name
ins(self.holdQueue,hb)
self:resetBlock()
end
self:freshBlock('move')
self.dropDelay=ENV.drop
self.lockDelay=ENV.lock
if self:ifoverlap(self.cur.bk,self.curX,self.curY)then
self:lock()
self:lose()
end
end
self.freshTime=int(min(self.freshTime+ENV.freshLimit*.25,ENV.freshLimit*((self.holdTime+1)/ENV.holdCount),ENV.freshLimit))
if not ENV.infHold then
self.holdTime=self.holdTime-1
end
if self.sound then
SFX.play(ifpre and'prehold'or'hold')
end
self.stat.hold=self.stat.hold+1
end
function Player:hold_swap(ifpre)
local ENV=self.gameEnv
local hid=ENV.holdCount-self.holdTime+1
if self.nextQueue[hid]then
local C,H=self.cur,self.nextQueue[hid]
self.ctrlCount=0
if ENV.phyHold and C and not ifpre then--Physical hold
local x,y=self.curX,self.curY
x=x+(#C.bk[1]-#H.bk[1])*.5
y=y+(#C.bk-#H.bk)*.5
local iki=phyHoldKickX[x==int(x)]
for Y=int(y),ceil(y+.5)do
for i=1,#iki do
local X=x+iki[i]
if not self:ifoverlap(H.bk,X,Y)then
x,y=X,Y
goto BREAK_success
end
end
self.cur=rem(self.holdQueue,1)
self:resetBlock()
end
self:freshBlock('move')
self.dropDelay=ENV.drop
self.lockDelay=ENV.lock
if self:ifoverlap(self.cur.bk,self.curX,self.curY)then
self:lock()
self:lose()
end
end
--<for-else> All test failed, interrupt with sound
SFX.play('finesseError')
do return end
--<for-end>
::BREAK_success::
self.freshTime=int(min(self.freshTime+ENV.freshLimit*.25,ENV.freshLimit*((self.holdTime+1)/ENV.holdCount),ENV.freshLimit))
if not ENV.infHold then
self.holdTime=self.holdTime-1
end
self.spinLast=false
if self.sound then
SFX.play(ifpre and'prehold'or'hold')
end
local hb=self:getBlock(C.id)
hb.name=C.name
hb.color=C.color
self.cur,self.nextQueue[hid]=self.nextQueue[hid],hb
self.stat.hold=self.stat.hold+1
self.curX,self.curY=x,y
else--Normal hold
self.spinLast=false
local hb=self:getBlock(C.id)
hb.color=C.color
hb.name=C.name
self.cur,self.nextQueue[hid]=self.nextQueue[hid],hb
self:resetBlock()
end
self:freshBlock('move')
self.dropDelay=ENV.drop
self.lockDelay=ENV.lock
if self:ifoverlap(self.cur.bk,self.curX,self.curY)then
self:lock()
self:lose()
end
end
self.freshTime=int(min(self.freshTime+ENV.freshLimit*.25,ENV.freshLimit*((self.holdTime+1)/ENV.holdCount),ENV.freshLimit))
if not ENV.infHold then
self.holdTime=self.holdTime-1
end
if self.sound then
SFX.play(ifpre and'prehold'or'hold')
end
self.stat.hold=self.stat.hold+1
end
function Player:hold(ifpre)
if self.holdTime>0 and(ifpre or self.waiting==-1)then
if self.gameEnv.holdMode=='hold'then
self:hold_norm(ifpre)
elseif self.gameEnv.holdMode=='swap'then
self:hold_swap(ifpre)
end
end
end

View File

@@ -236,18 +236,19 @@ scene.widgetList={
WIDGET.newButton{name="puzzle", x=1070,y=540,w=310,h=70,color='lM',font=35,code=pressKey"return2",hideF=function()return not initField end},
WIDGET.newButton{name="back", x=1140,y=640,w=170,h=80,fText=TEXTURE.back,code=pressKey"escape"},
--Rule set
WIDGET.newSelector{name="eventSet", x=930, y=740,w=360,color='H',list=sList.eventSet,disp=CUSval('eventSet'),code=CUSsto('eventSet')},
--Special rules
WIDGET.newSwitch{name="ospin", x=850, y=750,lim=210,disp=CUSval('ospin'), code=CUSrev('ospin')},
WIDGET.newSwitch{name="fineKill", x=850, y=840,lim=210,disp=CUSval('fineKill'), code=CUSrev('fineKill')},
WIDGET.newSwitch{name="ospin", x=850, y=810,lim=210,disp=CUSval('ospin'), code=CUSrev('ospin')},
WIDGET.newSwitch{name="fineKill", x=850, y=870,lim=210,disp=CUSval('fineKill'), code=CUSrev('fineKill')},
WIDGET.newSwitch{name="b2bKill", x=850, y=930,lim=210,disp=CUSval('b2bKill'), code=CUSrev('b2bKill')},
WIDGET.newSwitch{name="easyFresh", x=1170,y=750,lim=250,disp=CUSval('easyFresh'),code=CUSrev('easyFresh')},
WIDGET.newSwitch{name="deepDrop", x=1170,y=840,lim=250,disp=CUSval('deepDrop'), code=CUSrev('deepDrop')},
WIDGET.newSwitch{name="easyFresh", x=1170,y=810,lim=250,disp=CUSval('easyFresh'),code=CUSrev('easyFresh')},
WIDGET.newSwitch{name="deepDrop", x=1170,y=870,lim=250,disp=CUSval('deepDrop'), code=CUSrev('deepDrop')},
WIDGET.newSwitch{name="bone", x=1170,y=930,lim=250,disp=CUSval('bone'), code=CUSrev('bone')},
--Rule set
WIDGET.newSelector{name="eventSet", x=310, y=880,w=360,color='H',list=sList.eventSet,disp=CUSval('eventSet'),code=CUSsto('eventSet')},
--Next & Hold
WIDGET.newSelector{name="holdMode", x=310, y=890, w=300,color='lY',list={'hold','swap'},disp=CUSval('holdMode'),code=CUSsto('holdMode')},
WIDGET.newSlider{name="nextCount", x=140, y=960, lim=130,w=180,unit=6,disp=CUSval('nextCount'),code=CUSsto('nextCount')},
WIDGET.newSlider{name="holdCount", x=140, y=1030,lim=130,w=180,unit=6,disp=CUSval('holdCount'),code=CUSsto('holdCount')},
WIDGET.newSwitch{name="infHold", x=560, y=960, lim=200, disp=CUSval('infHold'),code=CUSrev('infHold'),hideF=function()return CUSTOMENV.holdCount==0 end},