From 6073c171375ccde8c51368c8db21c9a9f57d81ec Mon Sep 17 00:00:00 2001 From: MrZ_26 <1046101471@qq.com> Date: Tue, 3 Oct 2023 07:18:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=9F=B3=E4=B9=90=E5=AE=A4?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E5=A4=9A=E4=B8=AA=E5=AD=97=E7=AC=A6=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/scene/musicroom.lua | 40 ++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/assets/scene/musicroom.lua b/assets/scene/musicroom.lua index 8e4f7a64..f5dfd39b 100644 --- a/assets/scene/musicroom.lua +++ b/assets/scene/musicroom.lua @@ -11,6 +11,8 @@ local collectCount=0 local noProgress=false local autoplay=false local fakeProgress=0 +local searchStr="" +local searchTimer=0 local bigTitle=setmetatable({},{ __index=function(self,name) @@ -107,6 +109,19 @@ function scene.enter() end end +local function searchMusic(str) + local bestID,bestDist=-1,999 + local list=musicListBox:getList() + for i=1,#list do + local dist=list[i]:find(str) + if dist and dist0 then + musicListBox:select(bestID) + end +end function scene.keyDown(key,isRep) local act=KEYMAP.sys:getAction(key) if act=='up' or act=='down' then @@ -116,14 +131,13 @@ function scene.keyDown(key,isRep) BGM.set('all','seek',key=='left' and max(BGM.tell()-5,0) or (BGM.tell()+5)%BGM.getDuration()) end elseif #key==1 and key:find'[0-9a-z]' then - local list=musicListBox:getList() - local sel=musicListBox:getSelect() - for _=1,#list do - sel=(sel-1+(isShiftPressed() and -1 or 1))%#list+1 - if list[sel]:sub(1,1)==key then - musicListBox:select(sel) - break - end + if searchTimer==0 then + searchStr="" + end + if #searchStr<26 then + searchStr=searchStr..key + searchTimer=1.26 + searchMusic(searchStr) end elseif not isRep then if key=='space' then @@ -154,6 +168,9 @@ function scene.keyDown(key,isRep) end function scene.update(dt) + if searchTimer>0 then + searchTimer=max(searchTimer-dt,0) + end if autoplay and BGM.isPlaying() then if autoplay>0 then autoplay=max(autoplay-dt,0) @@ -211,6 +228,13 @@ function scene.draw() gc_printf(STRING.time_simp(BGM.getDuration()),700-626,260,626,'right') end + -- Searching + if searchTimer>0 then + gc_setColor(1,1,1,searchTimer*1.26) + setFont(30) + gc_print(searchStr,0,-360) + end + -- Collecting progress gc_setColor(COLOR.L) gc.setLineWidth(2)