From 8e075adf8fe682ca2a6fd078bb048349d6958a7e Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Thu, 16 Dec 2021 02:58:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=80=E4=B8=AA=E7=AE=80?= =?UTF-8?q?=E6=98=93=E7=A7=92=E8=A1=A8=E5=B0=8F=E7=A8=8B=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parts/scenes/app_console.lua | 5 +++ parts/scenes/app_stopwatch.lua | 70 ++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 parts/scenes/app_stopwatch.lua diff --git a/parts/scenes/app_console.lua b/parts/scenes/app_console.lua index 4b15c356..188eaddc 100644 --- a/parts/scenes/app_console.lua +++ b/parts/scenes/app_console.lua @@ -647,6 +647,11 @@ local commands={}do scene='app_triple', description="A Match-3 Game. Original idea from Sanlitun / Triple Town" }, + { + code="sw", + scene='app_stopwatch', + description="A stopwatch" + }, { code="spin", scene='app_spin', diff --git a/parts/scenes/app_stopwatch.lua b/parts/scenes/app_stopwatch.lua new file mode 100644 index 00000000..bd041414 --- /dev/null +++ b/parts/scenes/app_stopwatch.lua @@ -0,0 +1,70 @@ +local state +local pressTime +local releaseTime +local time1,time2 + +local function press() + if state==0 then + state=1 + pressTime=TIME() + releaseTime=false + time2=STRING.time(0) + elseif state==2 then + state=0 + end +end + +local function release() + if state==1 then + state=2 + releaseTime=TIME() + end +end + +local scene={} + +function scene.sceneInit() + state=0 + time1=STRING.time(0) + time2=STRING.time(0) +end + +function scene.mouseDown() + press() +end +function scene.mouseUp() + release() +end +function scene.keyDown(key,isRep) + if isRep then return end + if key=='escape'then + SCN.back() + else + press() + end +end +function scene.keyUp() + release() +end + +function scene.update() + if state~=0 then + time1=STRING.time(TIME()-pressTime) + if releaseTime then + time2=STRING.time(TIME()-releaseTime) + end + end +end + +function scene.draw() + FONT.set(60) + mStr(CHAR.icon.import,340,230) + mStr(CHAR.icon.export,940,230) + mStr(time1,340,300) + mStr(time2,940,300) +end + +scene.widgetList={ + WIDGET.newButton{name="back", x=1140,y=640,w=170,h=80,font=60,fText=CHAR.icon.back,code=backScene}, +} +return scene