79 lines
1.9 KiB
Plaintext
79 lines
1.9 KiB
Plaintext
/*
|
|
文件名:BaseWidget.nut
|
|
路径:UI/Windows/Widget/BaseWidget.nut
|
|
创建日期:2025-10-21 22:29
|
|
文件用途:基础控件
|
|
*/
|
|
|
|
class GameWidget_BaseButton extends GameWidget {
|
|
//按钮状态
|
|
ButtonState = 0;
|
|
//Img路径
|
|
Path = null;
|
|
//Img索引
|
|
Idx = null;
|
|
|
|
//帧集合
|
|
FrameList = null;
|
|
//精灵状态
|
|
SpriteState = -1;
|
|
|
|
//按下时的模拟偏移
|
|
DownSimulateOffset = true;
|
|
|
|
constructor(X, Y, W, H, Path, Idx) {
|
|
this.Path = Path;
|
|
this.Idx = Idx;
|
|
base.constructor(X, Y, W, H);
|
|
|
|
FrameList = [];
|
|
|
|
//构造4个精灵
|
|
for (local i = 0; i < 4; i++) {
|
|
local Buffer = Sprite(this.Path, this.Idx + i);
|
|
Buffer.SetVisible(false);
|
|
FrameList.push(Buffer);
|
|
AddChild(Buffer);
|
|
}
|
|
}
|
|
|
|
function ChangeFrame() {
|
|
//状态更改 刷新精灵帧
|
|
if (ButtonState != SpriteState) {
|
|
//按下时模拟偏移的Flag 如果按下 调整Y坐标向下一个单位
|
|
if (DownSimulateOffset) {
|
|
if (ButtonState == 2) {
|
|
Y += 1;
|
|
SetPos(X, Y);
|
|
} else if (SpriteState == 2) {
|
|
Y -= 1;
|
|
SetPos(X, Y);
|
|
}
|
|
}
|
|
if (SpriteState != -1) FrameList[SpriteState].SetVisible(false);
|
|
SpriteState = ButtonState;
|
|
FrameList[SpriteState].SetVisible(true);
|
|
}
|
|
}
|
|
|
|
function Proc(Dt) {
|
|
//不可用
|
|
if (ButtonState == 3) {
|
|
} else {
|
|
//按下
|
|
if (isLBDown) {
|
|
ButtonState = 2;
|
|
}
|
|
//悬停
|
|
else if (isInRect) {
|
|
ButtonState = 1;
|
|
}
|
|
//普通
|
|
else {
|
|
ButtonState = 0;
|
|
}
|
|
}
|
|
ChangeFrame();
|
|
}
|
|
}
|