diff --git a/Project/Steal/Steal.nut b/Project/Steal/Steal.nut index 92e21e0..d1c364a 100644 --- a/Project/Steal/Steal.nut +++ b/Project/Steal/Steal.nut @@ -7,38 +7,97 @@ class StealC_Password_Box extends LenheartNewUI_CommonUi { - //数字序列 NumberSeq = null; + ScrollPixelOffset = 0; + ScrollBaseIndex = 0; + InitBaseIndex = 0; + ScrollStartTimeMs = 0; + RowDurationMs = 500; + RowHeight = 24; + ColumnYOffset = 0; - constructor(X, Y) { + constructor(X, Y, ...) { LenheartNewUI_CommonUi.constructor(X, Y, 30, 120); - //生成数字序列 + local PhaseIndex = 0; + if (vargc > 0) { + PhaseIndex = vargv[0]; + } + ColumnYOffset = -(PhaseIndex * 8); + NumberSeq = []; - for (local i = 0; i< 10; i++) { + for (local i = 0; i < 10; i++) { local Info = { num = sq_getRandom(0, 9), CorrectFlag = false, } NumberSeq.append(Info); } - //随机一个正确的数字 + local CorrectIndex = sq_getRandom(0, 9); NumberSeq[CorrectIndex].CorrectFlag = true; + + local SeqLen = NumberSeq.len(); + if (SeqLen > 0) { + local Phase = PhaseIndex % SeqLen; + if (Phase < 0) { + Phase += SeqLen; + } + ScrollBaseIndex = Phase; + InitBaseIndex = Phase; + } + ScrollStartTimeMs = Clock(); + } + + function GetLoopIndex(Index) { + local SeqLen = NumberSeq.len(); + if (SeqLen <= 0) { + return 0; + } + local Value = Index % SeqLen; + if (Value < 0) { + Value += SeqLen; + } + return Value; + } + + function UpdateScrollByClock() { + if (RowDurationMs <= 0) { + RowDurationMs = 1; + } + local RunTimeMs = Clock() - ScrollStartTimeMs; + if (RunTimeMs < 0) { + RunTimeMs = 0; + } + local PassedRows = (RunTimeMs / RowDurationMs).tointeger(); + local CycleMs = RunTimeMs % RowDurationMs; + ScrollPixelOffset = sq_GetUniformVelocity(0, RowHeight - 1, CycleMs, RowDurationMs).tointeger(); + ScrollBaseIndex = GetLoopIndex(InitBaseIndex - PassedRows); } function Show(obj) { - local Dt = Parent.Duration; Parent.Img.DrawExPng(10, X, Y, 0, sq_RGBA(255, 255, 255, 90), 1.0, 1.0); - //绘制数字 - for (local i = 0; i< 10; i++) { - local Info = NumberSeq[i]; + + local SeqLen = NumberSeq.len(); + if (SeqLen <= 0) { + return; + } + + UpdateScrollByClock(); + + local DrawCount = (Height / RowHeight).tointeger() + 4; + local TextY = Y + 10; + for (local i = -2; i < DrawCount - 2; i++) { + local Info = NumberSeq[GetLoopIndex(ScrollBaseIndex + i)]; + local NumStr = Info.num.tostring(); local Color = Info.CorrectFlag ? sq_RGBA(157, 245, 10, 255) : sq_RGBA(150, 150, 150, 255); - L_sq_DrawCode(Info.num.tostring(), X + 15 - LenheartTextClass.GetStringLength(Info.num.tostring()) / 2, Y + 10 + i * 24, Color, 0, 1); + local DrawY = TextY + i * RowHeight + ScrollPixelOffset + ColumnYOffset; + L_sq_DrawCode(NumStr, X + 15 - LenheartTextClass.GetStringLength(NumStr) / 2, DrawY, Color, 0, 1); } } } + class StealC extends LenheartNewUI_Windows { //调试模式 // DeBugMode = true; @@ -71,7 +130,7 @@ class StealC extends LenheartNewUI_Windows { // Childrens.append(CloseButton); for (local i = 0; i< 8; i++) { - local PasswordBox = StealC_Password_Box(280 + i * 30, 268); + local PasswordBox = StealC_Password_Box(280 + i * 30, 268, i); AddChild(PasswordBox); } } @@ -139,4 +198,4 @@ function Lenheart_Steal_Fun(obj) { } } -getroottable()["LenheartFuncTab"].rawset("StealFuncN", Lenheart_Steal_Fun); \ No newline at end of file +getroottable()["LenheartFuncTab"].rawset("StealFuncN", Lenheart_Steal_Fun);