From 3d8c996f6bf4386282483e649ae41f4531fcf901 Mon Sep 17 00:00:00 2001 From: WONIU Date: Sat, 14 Dec 2024 22:22:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=AC=E5=91=8A=E6=B6=88=E6=81=AF=E5=BC=B9?= =?UTF-8?q?=E7=AA=97(=E5=8A=A8=E6=80=81=E5=A4=A7=E5=B0=8F)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit c7dfe7c994f24d3a7d9ece7414782fa3d240093f) --- sqr/SquirrelFileConfig.cfg | 1 + sqr/User/UI/Window/233_HUD_Message.nut | 133 +++++++++++++++++++++++++ sqr/folder-alias.json | 3 + 3 files changed, 137 insertions(+) create mode 100644 sqr/User/UI/Window/233_HUD_Message.nut diff --git a/sqr/SquirrelFileConfig.cfg b/sqr/SquirrelFileConfig.cfg index 37d3433..74b3fff 100644 --- a/sqr/SquirrelFileConfig.cfg +++ b/sqr/SquirrelFileConfig.cfg @@ -66,5 +66,6 @@ sqr/User/UI/Widget/Scroll_Bar.nut sqr/User/UI/Window/0_Login.nut sqr/User/UI/Window/1_Select_Character.nut +sqr/User/UI/Window/233_HUD_Message.nut sqr/User/main.nut \ No newline at end of file diff --git a/sqr/User/UI/Window/233_HUD_Message.nut b/sqr/User/UI/Window/233_HUD_Message.nut new file mode 100644 index 0000000..9030c52 --- /dev/null +++ b/sqr/User/UI/Window/233_HUD_Message.nut @@ -0,0 +1,133 @@ +/* +文件名:233_HUD_Message.nut +路径:User/UI/Window/233_HUD_Message.nut +创建日期:2024-12-14 08:10 +文件用途: 公告或信息弹窗 +*/ + +class HUD_Message extends Yosin_Window { + //调试模式 + // DeBugMode = true; + + //不是窗口 + // NoWindow = true; + + //是否可见 + // Visible = false; + + BackGroundMusic = null; + + cacheW = 230; + cacheH = 155; + + titleTextActor = null; + messageTextActor = null; + + constructor(gX, gY, message, 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; + + print("cacheW:" + cacheW.tostring()); + print("cacheH:" + cacheH.tostring()); + + // 默认构造数据 + base.constructor("公告或信息弹窗" + clock().tostring() , gX, gY, cacheW, cacheH, 20); + + + //注册控件 + RegisterWidget(); + //注册绘制 + RegisterDraw(); + } + + function RegisterWidget() { + //背景 + local background = Yosin_NineBoxStretch(-1, 15, cacheW + 2, cacheH, "sprite/interface/lenheartwindowcommon.img", 97); + AddUIChild(background); + local twoBackground = Yosin_NineBoxStretch(4, 20, cacheW - 8, cacheH - 36, "sprite/interface/lenheartwindowcommon.img", 97); + AddUIChild(twoBackground); + + // 绘制标题背景 + local titleBackground = Yosin_EmeStretch(0, 0, cacheW, 20, "sprite/interface/lenheartwindowcommon.img", 609); + AddUIChild(titleBackground); + + //确认按钮 + local confirmButton = Yosin_BaseButton( cacheW / 2 - 28, cacheH - 15, 56, 24 "sprite/interface/lenheartwindowcommon.img", 12); + confirmButton.OnClick = function(Button) { + this.RemoveSelf(); + }.bindenv(this); + AddUIChild(confirmButton); + + // 绘制标题 + local confirmTextActor = FontAssetManager.GenerateNormal("确认", sq_RGBA(206, 189, 140, 255), true); + 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) { + this.RemoveSelf(); + }.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 Proc(Dt) { + + SyncPos(X, Y); + base.Proc(Dt); + } + +} \ No newline at end of file diff --git a/sqr/folder-alias.json b/sqr/folder-alias.json index 5b2926c..1867f3c 100644 --- a/sqr/folder-alias.json +++ b/sqr/folder-alias.json @@ -169,5 +169,8 @@ }, "User/UI/Widget/Drag_Button.nut": { "description": "拖动按钮" + }, + "User/UI/Window/233_HUD_Message.nut": { + "description": "公告弹窗" } } \ No newline at end of file