feat(Steal): 为密码框添加滚动效果和相位偏移
实现密码数字序列的平滑滚动动画效果,支持不同密码框的相位偏移显示 修改密码框构造函数以接收相位参数,添加滚动相关属性和计算方法 优化数字显示逻辑,支持循环滚动和动态位置计算
This commit is contained in:
@@ -7,38 +7,97 @@
|
|||||||
|
|
||||||
class StealC_Password_Box extends LenheartNewUI_CommonUi {
|
class StealC_Password_Box extends LenheartNewUI_CommonUi {
|
||||||
|
|
||||||
//数字序列
|
|
||||||
NumberSeq = null;
|
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);
|
LenheartNewUI_CommonUi.constructor(X, Y, 30, 120);
|
||||||
//生成数字序列
|
local PhaseIndex = 0;
|
||||||
|
if (vargc > 0) {
|
||||||
|
PhaseIndex = vargv[0];
|
||||||
|
}
|
||||||
|
ColumnYOffset = -(PhaseIndex * 8);
|
||||||
|
|
||||||
NumberSeq = [];
|
NumberSeq = [];
|
||||||
for (local i = 0; i< 10; i++) {
|
for (local i = 0; i < 10; i++) {
|
||||||
local Info = {
|
local Info = {
|
||||||
num = sq_getRandom(0, 9),
|
num = sq_getRandom(0, 9),
|
||||||
CorrectFlag = false,
|
CorrectFlag = false,
|
||||||
}
|
}
|
||||||
NumberSeq.append(Info);
|
NumberSeq.append(Info);
|
||||||
}
|
}
|
||||||
//随机一个正确的数字
|
|
||||||
local CorrectIndex = sq_getRandom(0, 9);
|
local CorrectIndex = sq_getRandom(0, 9);
|
||||||
NumberSeq[CorrectIndex].CorrectFlag = true;
|
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) {
|
function Show(obj) {
|
||||||
local Dt = Parent.Duration;
|
|
||||||
Parent.Img.DrawExPng(10, X, Y, 0, sq_RGBA(255, 255, 255, 90), 1.0, 1.0);
|
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 SeqLen = NumberSeq.len();
|
||||||
local Info = NumberSeq[i];
|
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);
|
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 {
|
class StealC extends LenheartNewUI_Windows {
|
||||||
//调试模式
|
//调试模式
|
||||||
// DeBugMode = true;
|
// DeBugMode = true;
|
||||||
@@ -71,7 +130,7 @@ class StealC extends LenheartNewUI_Windows {
|
|||||||
// Childrens.append(CloseButton);
|
// Childrens.append(CloseButton);
|
||||||
|
|
||||||
for (local i = 0; i< 8; i++) {
|
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);
|
AddChild(PasswordBox);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user