feat(Steal): 添加密码框锁定功能及正确锁定计数
实现密码框滚动停止和锁定功能,当用户按下空格时尝试锁定当前焦点密码框 新增正确锁定计数功能,用于追踪成功锁定的次数 添加相关状态变量和方法支持锁定逻辑
This commit is contained in:
@@ -15,6 +15,9 @@ class StealC_Password_Box extends LenheartNewUI_CommonUi {
|
|||||||
RowDurationMs = 500;
|
RowDurationMs = 500;
|
||||||
RowHeight = 24;
|
RowHeight = 24;
|
||||||
ColumnYOffset = 0;
|
ColumnYOffset = 0;
|
||||||
|
CorrectIndex = 0;
|
||||||
|
IsStopped = false;
|
||||||
|
IsLockedCorrect = false;
|
||||||
|
|
||||||
|
|
||||||
constructor(X, Y, ...) {
|
constructor(X, Y, ...) {
|
||||||
@@ -34,7 +37,7 @@ class StealC_Password_Box extends LenheartNewUI_CommonUi {
|
|||||||
NumberSeq.append(Info);
|
NumberSeq.append(Info);
|
||||||
}
|
}
|
||||||
|
|
||||||
local CorrectIndex = sq_getRandom(0, 9);
|
CorrectIndex = sq_getRandom(0, 9);
|
||||||
NumberSeq[CorrectIndex].CorrectFlag = true;
|
NumberSeq[CorrectIndex].CorrectFlag = true;
|
||||||
|
|
||||||
local SeqLen = NumberSeq.len();
|
local SeqLen = NumberSeq.len();
|
||||||
@@ -75,6 +78,44 @@ class StealC_Password_Box extends LenheartNewUI_CommonUi {
|
|||||||
ScrollBaseIndex = GetLoopIndex(InitBaseIndex - PassedRows);
|
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) {
|
function Show(obj) {
|
||||||
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);
|
||||||
|
|
||||||
@@ -83,7 +124,9 @@ class StealC_Password_Box extends LenheartNewUI_CommonUi {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!IsStopped) {
|
||||||
UpdateScrollByClock();
|
UpdateScrollByClock();
|
||||||
|
}
|
||||||
|
|
||||||
local DrawCount = (Height / RowHeight).tointeger() + 4;
|
local DrawCount = (Height / RowHeight).tointeger() + 4;
|
||||||
local TextY = Y + 10;
|
local TextY = Y + 10;
|
||||||
@@ -112,6 +155,8 @@ class StealC extends LenheartNewUI_Windows {
|
|||||||
|
|
||||||
//解锁完成度
|
//解锁完成度
|
||||||
UnlockComplete = 0.57;
|
UnlockComplete = 0.57;
|
||||||
|
CorrectLockedCount = 0;
|
||||||
|
LockTolerancePx = 8;
|
||||||
|
|
||||||
constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH) {
|
constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH) {
|
||||||
Childrens = [];
|
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) {
|
function DrawMain(obj) {
|
||||||
//灰色背景
|
//灰色背景
|
||||||
DrawNineBoxAlpha(X, Y, 800, 600, "interface2/common/mypopup/popup.img", 0, 150);
|
DrawNineBoxAlpha(X, Y, 800, 600, "interface2/common/mypopup/popup.img", 0, 150);
|
||||||
@@ -176,6 +250,7 @@ class StealC extends LenheartNewUI_Windows {
|
|||||||
//逻辑入口
|
//逻辑入口
|
||||||
function Proc(obj) {
|
function Proc(obj) {
|
||||||
LenheartNewUI_Windows.SyncPos(X, Y);
|
LenheartNewUI_Windows.SyncPos(X, Y);
|
||||||
|
CheckSpaceLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user