diff --git a/Project/Steal/Steal.nut b/Project/Steal/Steal.nut index d1c364a..9decee4 100644 --- a/Project/Steal/Steal.nut +++ b/Project/Steal/Steal.nut @@ -15,6 +15,9 @@ class StealC_Password_Box extends LenheartNewUI_CommonUi { RowDurationMs = 500; RowHeight = 24; ColumnYOffset = 0; + CorrectIndex = 0; + IsStopped = false; + IsLockedCorrect = false; constructor(X, Y, ...) { @@ -34,7 +37,7 @@ class StealC_Password_Box extends LenheartNewUI_CommonUi { NumberSeq.append(Info); } - local CorrectIndex = sq_getRandom(0, 9); + CorrectIndex = sq_getRandom(0, 9); NumberSeq[CorrectIndex].CorrectFlag = true; local SeqLen = NumberSeq.len(); @@ -75,6 +78,44 @@ class StealC_Password_Box extends LenheartNewUI_CommonUi { ScrollBaseIndex = GetLoopIndex(InitBaseIndex - PassedRows); } + function GetCorrectCenterY(RefY) { + local SeqLen = NumberSeq.len(); + if (SeqLen <= 0) { + return Y; + } + local Delta = GetLoopIndex(CorrectIndex - ScrollBaseIndex); + local TextY = Y + 10; + local BaseY = TextY + Delta * RowHeight + ScrollPixelOffset + ColumnYOffset + 8; + local CycleHeight = SeqLen * RowHeight; + local BestY = BaseY; + local BestDist = abs(BestY - RefY); + for (local k = -2; k <= 2; k++) { + local CY = BaseY + (k * CycleHeight); + local Dist = abs(CY - RefY); + if (Dist < BestDist) { + BestY = CY; + BestDist = Dist; + } + } + return BestY; + } + + function TryLockByLine(LockCenterY, TolerancePx) { + if (IsStopped) { + return false; + } + if (!IsStopped) { + UpdateScrollByClock(); + } + local Dist = abs(GetCorrectCenterY(LockCenterY) - LockCenterY); + if (Dist <= TolerancePx) { + IsStopped = true; + IsLockedCorrect = true; + return true; + } + return false; + } + function Show(obj) { Parent.Img.DrawExPng(10, X, Y, 0, sq_RGBA(255, 255, 255, 90), 1.0, 1.0); @@ -83,7 +124,9 @@ class StealC_Password_Box extends LenheartNewUI_CommonUi { return; } - UpdateScrollByClock(); + if (!IsStopped) { + UpdateScrollByClock(); + } local DrawCount = (Height / RowHeight).tointeger() + 4; local TextY = Y + 10; @@ -112,6 +155,8 @@ class StealC extends LenheartNewUI_Windows { //解锁完成度 UnlockComplete = 0.57; + CorrectLockedCount = 0; + LockTolerancePx = 8; constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH) { Childrens = []; @@ -137,6 +182,35 @@ class StealC extends LenheartNewUI_Windows { //绘制主界面 + function GetLockCenterY() { + return Y + 268 + 60; + } + + function GetFocusPasswordBox() { + foreach(Child in Childrens) { + if ((Child instanceof StealC_Password_Box) && !Child.IsStopped) { + return Child; + } + } + return null; + } + + function CheckSpaceLock() { + if (!Visible) { + return; + } + if (!KeyPressNB.isKeyPress(7, "StealC")) { + return; + } + local FocusBox = GetFocusPasswordBox(); + if (!FocusBox) { + return; + } + if (FocusBox.TryLockByLine(GetLockCenterY(), LockTolerancePx)) { + CorrectLockedCount += 1; + } + } + function DrawMain(obj) { //灰色背景 DrawNineBoxAlpha(X, Y, 800, 600, "interface2/common/mypopup/popup.img", 0, 150); @@ -176,6 +250,7 @@ class StealC extends LenheartNewUI_Windows { //逻辑入口 function Proc(obj) { LenheartNewUI_Windows.SyncPos(X, Y); + CheckSpaceLock(); } }