104 lines
3.5 KiB
Plaintext
104 lines
3.5 KiB
Plaintext
/*
|
|
文件名:235_HUD_QuantityInput.nut
|
|
路径:User/UI/Window/235_HUD_QuantityInput.nut
|
|
创建日期:2025-02-07 20:24
|
|
文件用途:数量输入
|
|
*/
|
|
class _QuantityInput extends Yosin_Window {
|
|
|
|
InputBox = null;
|
|
//确认回调函数
|
|
OnConfirm = null;
|
|
|
|
constructor(Xpos, Ypos) {
|
|
// 默认构造数据
|
|
base.constructor("数量输入交互窗口" + clock(), Xpos, Ypos, 176, 72, 0);
|
|
ResetFocus();
|
|
Init();
|
|
}
|
|
|
|
|
|
function Init() {
|
|
//背景
|
|
local Bg = Yosin_NineBoxStretch(178, 75, "sprite/interface/lenheartwindowcommon.img", 97);
|
|
Addchild(Bg);
|
|
|
|
//聊天输入框
|
|
InputBox = Yosin_NumberInputBox(94, 20);
|
|
InputBox.SetPosition(43, 16);
|
|
AddUIChild(InputBox);
|
|
|
|
//数量提示文字
|
|
local TextObject = FontAssetManager.GenerateNormal("数量:", false, {
|
|
color = sq_RGBA(255, 227, 171, 250)
|
|
});
|
|
TextObject.SetPosition(11, 16);
|
|
Addchild(TextObject);
|
|
|
|
//加号按钮
|
|
local AddButton = Yosin_BaseButton(140, 12, 26, 14, "sprite/interface/lenheartwindowcommon.img", 496);
|
|
AddButton.DownSimulateOffset = false;
|
|
AddUIChild(AddButton);
|
|
AddButton.OnClick = function(btn) {
|
|
InputBox.SetNumber(InputBox.GetNumber() + 10);
|
|
InputBox.SetFocus(true);
|
|
}.bindenv(this);
|
|
|
|
//减号按钮
|
|
local SubButton = Yosin_BaseButton(140, 28, 26, 14, "sprite/interface/lenheartwindowcommon.img", 499);
|
|
SubButton.DownSimulateOffset = false;
|
|
AddUIChild(SubButton);
|
|
SubButton.OnClick = function(btn) {
|
|
InputBox.SetNumber(InputBox.GetNumber() - 10);
|
|
InputBox.SetFocus(true);
|
|
}.bindenv(this);
|
|
|
|
//确认按钮
|
|
local confirmButton = Yosin_BaseButton(28, 42, 56, 24 "sprite/interface/lenheartwindowcommon.img", 12);
|
|
confirmButton.OnClick = function(Button) {
|
|
//关闭本窗口
|
|
DestroyWindow();
|
|
if (OnConfirm) OnConfirm(InputBox.GetNumber().tointeger());
|
|
}.bindenv(this);
|
|
AddUIChild(confirmButton);
|
|
// 绘制标题
|
|
local confirmTextActor = FontAssetManager.GenerateNormal("确认", false, {
|
|
color = sq_RGBA(185, 148, 96, 255)
|
|
});
|
|
confirmTextActor.SetPosition(16, 2);
|
|
confirmButton.Addchild(confirmTextActor);
|
|
|
|
//取消按钮
|
|
local cancelButton = Yosin_BaseButton(88, 42, 56, 24 "sprite/interface/lenheartwindowcommon.img", 12);
|
|
cancelButton.OnClick = function(Button) {
|
|
//关闭本窗口
|
|
DestroyWindow();
|
|
}.bindenv(this);
|
|
AddUIChild(cancelButton);
|
|
// 绘制标题
|
|
local cancelTextActor = FontAssetManager.GenerateNormal("取消", false, {
|
|
color = sq_RGBA(185, 148, 96, 255)
|
|
});
|
|
cancelTextActor.SetPosition(16, 2);
|
|
cancelButton.Addchild(cancelTextActor);
|
|
}
|
|
|
|
//设置确认回调函数
|
|
function SetOnConfirmFunc(OnConfirm) {
|
|
this.OnConfirm = OnConfirm;
|
|
}
|
|
|
|
//ovverride
|
|
//鼠标滚轮事件回调
|
|
function OnMouseWheel(Wheel, MousePos_X, MousePos_Y, WindowInteractiveFlag) {
|
|
base.OnMouseWheel(Wheel, MousePos_X, MousePos_Y, WindowInteractiveFlag);
|
|
if (!Visible) return;
|
|
if (InputBox.IsFocus) {
|
|
if (Wheel > 0) {
|
|
InputBox.SetNumber(InputBox.GetNumber() + 1);
|
|
} else {
|
|
InputBox.SetNumber(InputBox.GetNumber() - 1);
|
|
}
|
|
}
|
|
}
|
|
} |