157 lines
4.6 KiB
Plaintext
157 lines
4.6 KiB
Plaintext
/*
|
|
文件名:233_HUD_Message.nut
|
|
路径:User/UI/Window/233_HUD_Message.nut
|
|
创建日期:2024-12-14 08:10
|
|
文件用途: 公告或信息弹窗
|
|
*/
|
|
|
|
class _Yosin_MessageBox extends Yosin_Window {
|
|
//调试模式
|
|
// DeBugMode = true;
|
|
|
|
//不是窗口
|
|
// NoWindow = true;
|
|
|
|
//是否可见
|
|
// Visible = false;
|
|
|
|
BackGroundMusic = null;
|
|
|
|
cacheW = 230;
|
|
cacheH = 155;
|
|
|
|
titleTextActor = null;
|
|
messageTextActor = null;
|
|
//确认回调函数
|
|
OnConfirm = null;
|
|
|
|
constructor(message, gX = 418, gY = 200, info = {
|
|
// 标题
|
|
title = "公告",
|
|
// 水平边距
|
|
horizontalMargin = 20,
|
|
// 垂直边距
|
|
verticalMargin = 20,
|
|
}) {
|
|
|
|
local title = info.rawin("title") ? info.title : "公告";
|
|
local horizontalMargin = info.rawin("horizontalMargin") ? info.horizontalMargin : 20;
|
|
local verticalMargin = info.rawin("verticalMargin") ? info.verticalMargin : 20;
|
|
|
|
// 标题
|
|
titleTextActor = FontAssetManager.GenerateNormal(title, true, {
|
|
color = sq_RGBA(206, 189, 140, 255),
|
|
alignment = TextAlign.Center,
|
|
});
|
|
|
|
// 标题动态宽度
|
|
if (titleTextActor.GetSize().w > cacheW - 40) {
|
|
cacheW = titleTextActor.GetSize().w + 40;
|
|
}
|
|
|
|
|
|
// 内容
|
|
messageTextActor = FontAssetManager.GenerateNormal(message, false, {
|
|
color = sq_RGBA(206, 189, 140, 255),
|
|
alignment = TextAlign.Center,
|
|
wrap_width = cacheW - horizontalMargin * 2,
|
|
});
|
|
|
|
// 内容动态高度
|
|
local verticalMargin = 50 + verticalMargin * 2;
|
|
cacheH = messageTextActor.GetSize().h + verticalMargin;
|
|
|
|
// 默认构造数据
|
|
base.constructor("公告或信息弹窗" + clock().tostring(), gX ? gX : 418, gY ? gY : 200, cacheW, cacheH, 20);
|
|
|
|
|
|
//注册控件
|
|
RegisterWidget();
|
|
//注册绘制
|
|
RegisterDraw();
|
|
|
|
ResetFocus();
|
|
}
|
|
|
|
function RegisterWidget() {
|
|
|
|
//背景
|
|
local background = Yosin_NineBoxStretch(cacheW + 1, cacheH, "sprite/interface/lenheartwindowcommon.img", 97);
|
|
background.SetPosition(-1, 15);
|
|
Addchild(background);
|
|
|
|
//文字背景
|
|
local twoBackground = Yosin_NineBoxStretch(cacheW - 8, cacheH - 36, "sprite/interface/lenheartwindowcommon.img", 97);
|
|
twoBackground.SetPosition(4, 20);
|
|
Addchild(twoBackground);
|
|
|
|
// 绘制标题背景
|
|
local titleBackground = Yosin_EmeStretch(cacheW, 20, "sprite/interface/lenheartwindowcommon.img", 609);
|
|
titleBackground.SetScale(1, 1.2);
|
|
Addchild(titleBackground);
|
|
|
|
// 标题背景光
|
|
local BackgroundBright = CL_SpriteObject("sprite/interface/lenheartwindowcommon.img", 483);
|
|
local BackgroundBrightSize = BackgroundBright.GetSize();
|
|
local scaleW = (cacheW / BackgroundBrightSize.w).tofloat();
|
|
BackgroundBright.SetScale(scaleW, 1);
|
|
BackgroundBright.SetPosition(0, 1);
|
|
Addchild(BackgroundBright);
|
|
|
|
//确认按钮
|
|
local confirmButton = Yosin_BaseButton(cacheW / 2 - 28, cacheH - 15, 56, 24 "sprite/interface/lenheartwindowcommon.img", 12);
|
|
confirmButton.OnClick = function(Button) {
|
|
//关闭本窗口
|
|
DestroyWindow();
|
|
if (OnConfirm) OnConfirm();
|
|
}.bindenv(this);
|
|
AddUIChild(confirmButton);
|
|
|
|
// 绘制标题
|
|
local confirmTextActor = FontAssetManager.GenerateNormal("确认", true, {
|
|
color = sq_RGBA(206, 189, 140, 255)
|
|
});
|
|
confirmTextActor.SetPosition(17, 6);
|
|
confirmButton.Addchild(confirmTextActor);
|
|
|
|
//关闭按钮
|
|
local closeButton = Yosin_BaseButton(cacheW - 15, 5, 10, 9 "sprite/interface/lenheartwindowcommon.img", 42);
|
|
closeButton.OnClick = function(Button) {
|
|
//关闭本窗口
|
|
DestroyWindow();
|
|
}.bindenv(this);
|
|
AddUIChild(closeButton);
|
|
|
|
|
|
}
|
|
|
|
function RegisterDraw() {
|
|
|
|
local titleX = cacheW / 2 - titleTextActor.GetSize().w / 2;
|
|
// 绘制标题
|
|
titleTextActor.SetPosition(titleX, 2);
|
|
Addchild(titleTextActor);
|
|
|
|
|
|
local messageX = cacheW / 2 - messageTextActor.GetSize().w / 2;
|
|
local messageY = cacheH / 2 - messageTextActor.GetSize().h / 2;
|
|
|
|
// 绘制内容
|
|
messageTextActor.SetPosition(messageX, messageY);
|
|
Addchild(messageTextActor);
|
|
|
|
}
|
|
|
|
//设置确认回调函数
|
|
function SetOnConfirmFunc(OnConfirm) {
|
|
this.OnConfirm = OnConfirm;
|
|
}
|
|
|
|
//逻辑入口
|
|
function Proc(Dt) {
|
|
|
|
SyncPos(X, Y);
|
|
base.Proc(Dt);
|
|
}
|
|
|
|
} |