From 1faacb54648c908de0ddb3c73f11bb23529753d0 Mon Sep 17 00:00:00 2001 From: Lenheart <947330670@qq.com> Date: Wed, 8 Apr 2026 23:24:34 +0800 Subject: [PATCH] =?UTF-8?q?feat(Steal):=20=E4=B8=BA=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E6=A1=86=E6=B7=BB=E5=8A=A0=E6=BB=9A=E5=8A=A8=E6=95=88=E6=9E=9C?= =?UTF-8?q?=E5=92=8C=E7=9B=B8=E4=BD=8D=E5=81=8F=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 实现密码数字序列的平滑滚动动画效果,支持不同密码框的相位偏移显示 修改密码框构造函数以接收相位参数,添加滚动相关属性和计算方法 优化数字显示逻辑,支持循环滚动和动态位置计算 --- Project/Steal/Steal.nut | 83 +++++++++++++++++++++++++++++++++++------ 1 file changed, 71 insertions(+), 12 deletions(-) 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);