Compare commits

..

3 Commits

Author SHA1 Message Date
Lenheart 230ddba3f6 窗口UI更新 2024-12-15 20:15:29 +08:00
WONIU 3d8c996f6b 公告消息弹窗(动态大小)
(cherry picked from commit c7dfe7c994)
2024-12-14 23:46:53 +08:00
WONIU 7d5a49862c 九宫格拉伸
(cherry picked from commit 68068e79ff)
2024-12-14 23:46:41 +08:00
6 changed files with 322 additions and 23 deletions

View File

@ -185,6 +185,94 @@ class Yosin_EmeStretch extends Yosin_CommonUi {
} }
} }
//九宫格拉伸
class Yosin_NineBoxStretch extends Yosin_CommonUi {
constructor(X, Y, W, H, Path, Idx) {
base.constructor(X, Y, W, H);
DrawBackground( W, H, Path, Idx);
}
// 绘制
function DrawBackground(width, height, path, imgId) {
local x = 0;
local y = 0;
// 左上角
local backgroundTopLeft = CL_SpriteObject(path, imgId);
backgroundTopLeft.SetPosition(x, y);
Addchild(backgroundTopLeft);
// 左上角图片大小
local cornerImgSize = backgroundTopLeft.GetSize();
local cornerWidth = cornerImgSize.w;
local cornerHeight = cornerImgSize.h;
// 中间
local backgroundCenter = CL_SpriteObject(path, imgId + 4);
backgroundCenter.SetPosition(cornerWidth, y + cornerHeight);
Addchild(backgroundCenter);
// 中间图片大小
local centerImgSize = backgroundCenter.GetSize();
local centerWidth = centerImgSize.w;
local centerHeight = centerImgSize.h;
local scaleW = (width.tofloat() - cornerWidth.tofloat() * 2.0) / centerWidth.tofloat();
local scaleH = (height.tofloat() - y.tofloat() - cornerHeight.tofloat()) / centerHeight.tofloat();
// 上边
local backgroundTop = CL_SpriteObject(path, imgId + 1);
backgroundTop.SetPosition(cornerWidth, y);
backgroundTop.SetScale(scaleW, 1);
Addchild(backgroundTop);
// 右上角
local backgroundTopRight = CL_SpriteObject(path, imgId + 2);
backgroundTopRight.SetPosition(width - cornerWidth, y);
Addchild(backgroundTopRight);
// 左边
local backgroundLeft = CL_SpriteObject(path, imgId + 3);
backgroundLeft.SetPosition(x, y + cornerHeight );
backgroundLeft.SetScale(1, scaleH);
Addchild(backgroundLeft);
// 中间
backgroundCenter.SetScale(scaleW, scaleH);
// 右边
local backgroundRight = CL_SpriteObject(path, imgId + 5);
backgroundRight.SetPosition(width - cornerWidth, y + cornerHeight);
backgroundRight.SetScale(1, scaleH);
Addchild(backgroundRight);
// 左下角
local backgroundBottomLeft = CL_SpriteObject(path, imgId + 6);
backgroundBottomLeft.SetPosition(x, height - cornerHeight);
Addchild(backgroundBottomLeft);
// 下边
local backgroundBottom = CL_SpriteObject(path, imgId + 7);
backgroundBottom.SetPosition(cornerWidth, height - cornerHeight);
backgroundBottom.SetScale( scaleW , 1);
Addchild(backgroundBottom);
// 右下角
local backgroundBottomRight = CL_SpriteObject(path, imgId + 8);
backgroundBottomRight.SetPosition(width - cornerWidth, height - cornerHeight);
Addchild(backgroundBottomRight);
}
}
//拼接按钮 //拼接按钮
class Yosin_SplicingButton extends Yosin_CommonUi { class Yosin_SplicingButton extends Yosin_CommonUi {
//按钮状态 //按钮状态

View File

@ -66,5 +66,6 @@ sqr/User/UI/Widget/Scroll_Bar.nut
sqr/User/UI/Window/0_Login.nut sqr/User/UI/Window/0_Login.nut
sqr/User/UI/Window/1_Select_Character.nut sqr/User/UI/Window/1_Select_Character.nut
sqr/User/UI/Window/233_HUD_Message.nut
sqr/User/main.nut sqr/User/main.nut

View File

@ -19,6 +19,9 @@ class _Login_Window extends Yosin_Window {
BackGroundMusic = null; BackGroundMusic = null;
//信息
PackInfo = null;
constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH) { constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH) {
base.constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH); base.constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH);
@ -30,6 +33,35 @@ class _Login_Window extends Yosin_Window {
//播放音乐 //播放音乐
PlayBackgroundMusic(); PlayBackgroundMusic();
//注册登录回调包
MySocket.RegisterHandler(2, function(Jso) {
//登录成功
if (Jso.state) {
HUD_Message(500, 200, "登录成功,正在进入游戏...");
MySocket.Send(9, null);
} else {
HUD_Message(500, 200, "登录失败");
}
}.bindenv(this));
//注册获取角色列表回包
MySocket.RegisterHandler(10, function(Jso) {
PackInfo = Jso;
}.bindenv(this));
//注册获取角色列表的装备回包
MySocket.RegisterBinaryHandler(10, function(Blob) {
Blob.readn('i');
foreach(info in PackInfo.charac) {
info.equip <- [];
for (local i = 0; i< 15; i++) {
local value = Blob.readn('i');
info.equip.append(value);
}
}
local Window = Sq_CreateWindow(_Select_Character_Window, "选择角色界面窗口", 0, 0, 1066, 600, 0);
Window.Init(PackInfo);
}.bindenv(this));
} }
function PlayBackgroundMusic() { function PlayBackgroundMusic() {

View File

@ -77,11 +77,12 @@ class _Select_Character_SettingBackground_Window extends Yosin_Window {
IsIndependent = false; IsIndependent = false;
//是否可见 //是否可见
// Visible = false; Visible = false;
//选择背景按钮集合 //选择背景按钮集合
SettingBackgroundButtonList = null; SettingBackgroundButtonList = null;
//背景对象
Background = null; Background = null;
ScrollObject = null; ScrollObject = null;
@ -90,9 +91,7 @@ class _Select_Character_SettingBackground_Window extends Yosin_Window {
base.constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH); base.constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH);
SettingBackgroundButtonList = []; SettingBackgroundButtonList = [];
SetClipRect(0, 0, gWidth, gHeight); SetClipRect(5, 9, gWidth, gHeight - 9);
// ShowBorder(true);
// SetLayerOpacity(1);
} }
function Init() { function Init() {
@ -103,13 +102,17 @@ class _Select_Character_SettingBackground_Window extends Yosin_Window {
function RegisterDraw() { function RegisterDraw() {
//背景 //背景
Background = CL_SpriteObject("sprite/interface2/selectcharacter_ver2/setup/setup.img", 17); Background = CL_SpriteObject("sprite/interface2/selectcharacter_ver2/setup/setup.img", 17);
Addchild(Background); Background.SetPosition(X, Y);
Background.SetZOrder(-10);
Background.SetVisible(false);
//因为裁切原因 所以要添加到父对象中
Parent.Addchild(Background);
for (local i = 0; i< 24; i++) { for (local i = 0; i< 24; i++) {
local Buf = _Select_Character_SettingBackground_Object_Window(5 + (101 * (i % 2)), 9 + (61 * (i / 2)), 91, 51, i); local Buf = _Select_Character_SettingBackground_Object_Window(5 + (101 * (i % 2)), 9 + (61 * (i / 2)), 91, 51, i);
SettingBackgroundButtonList.push(Buf); SettingBackgroundButtonList.push(Buf);
//如果是父对象默认构造的默认是勾选状态 //如果是父对象默认构造的默认是勾选状态
if (i == Parent.Info.Background) { if (i == Parent.Info.loginImg) {
Buf.SelectMask.SetVisible(true); Buf.SelectMask.SetVisible(true);
Buf.SelectFlag = true; Buf.SelectFlag = true;
} }
@ -126,10 +129,45 @@ class _Select_Character_SettingBackground_Window extends Yosin_Window {
} }
//逻辑入口 //override
function Proc(Dt) { //设置是否可见 通过重载设置可见同步Background的可见性
SyncPos(X, Y); function SetVisible(Flag) {
base.Proc(Dt); base.SetVisible(Flag);
if (Flag) {
if (Background) Background.SetVisible(true);
} else {
if (Background) Background.SetVisible(false);
}
}
}
//角色
class _Select_Character_Chr extends Yosin_Window {
//是否为独立窗口
IsIndependent = false;
Info = null;
constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH) {
base.constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH);
RegisterDraw();
}
function Init(Info) {
this.Info = Info;
RegisterCharac();
}
function RegisterDraw() {
local Magic = CL_SpriteObject("sprite/interface2/selectcharacter_ver2/selectcharacter.img", 10);
Addchild(Magic);
}
function RegisterCharac() {
local Charc = GameObject.CreateCharacter(Info.job, Info.equip);
Charc.SetAnimation("RestAni");
Charc.SetPosition(48, 12, 0);
Addchild(Charc);
} }
} }
@ -150,6 +188,8 @@ class _Select_Character_Window extends Yosin_Window {
SettingBackgroundWindow = null; SettingBackgroundWindow = null;
//背景图片 //背景图片
BackGround = null; BackGround = null;
//角色遮罩栏
CharacterMaskBox = null;
//信息 //信息
Info = null; Info = null;
@ -193,6 +233,13 @@ class _Select_Character_Window extends Yosin_Window {
AddUIChild(SettingBackgroundWindow); AddUIChild(SettingBackgroundWindow);
//先添加为子对象 因为子对象需要用到父对象 //先添加为子对象 因为子对象需要用到父对象
SettingBackgroundWindow.Init(); SettingBackgroundWindow.Init();
//角色对象
for (local i = 0; i< 5; i++) {
local Buf = _Select_Character_Chr("选择角色角色对象" + i, 190 + (i * 144), ((i % 2) ? 15 : 0) + 225, 126, 208, 0);
if (i< Info.charac.len()) Buf.Init(Info.charac[i]);
AddUIChild(Buf);
}
} }
function RegisterWidget() { function RegisterWidget() {
@ -217,7 +264,6 @@ class _Select_Character_Window extends Yosin_Window {
}) })
SettingButton.Addchild(LoginTextActor); SettingButton.Addchild(LoginTextActor);
} }
//切换背景 //切换背景
@ -227,23 +273,18 @@ class _Select_Character_Window extends Yosin_Window {
BackGround = null; BackGround = null;
} }
BackGround = CL_SpriteObject("sprite/interface2/selectcharacter_ver2/background/large/background_large_event.img", Idx); BackGround = CL_SpriteObject("sprite/interface2/selectcharacter_ver2/background/large/background_large_event.img", Idx);
BackGround.SetZOrder(-10); BackGround.SetZOrder(-100);
/*
BackGround = Layer();
BackGround.Addchild(CL_SpriteObject("sprite/interface2/selectcharacter_ver2/background/large/background_large_event.img", Idx));
BackGround.SetZOrder(-10);
BackGround.SetPosition(100, 100);
BackGround.SetClipRect(0, 0, 200, 200);
*/
Addchild(BackGround); Addchild(BackGround);
} }
function RegisterDraw() { function RegisterDraw() {
//大背景 根据玩家的设定背景决定 //大背景 根据玩家的设定背景决定
ChangeBackground(Info.Background); ChangeBackground(Info.loginImg);
//角色遮罩栏
CharacterMaskBox = Yosin_NineBoxStretch(-4, 330, 1074, 680, "sprite/interface/lenheartwindowcommon.img", 0);
AddUIChild(CharacterMaskBox);
} }

View File

@ -0,0 +1,134 @@
/*
文件名: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;
// 默认构造数据
base.constructor("公告或信息弹窗" + clock().tostring(), gX, gY, cacheW, cacheH, 20);
//注册控件
RegisterWidget();
//注册绘制
RegisterDraw();
ResetFocus();
}
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) {
//关闭本窗口
CloseWindow();
}.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) {
//关闭本窗口
CloseWindow();
}.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);
}
}

View File

@ -169,5 +169,8 @@
}, },
"User/UI/Widget/Drag_Button.nut": { "User/UI/Widget/Drag_Button.nut": {
"description": "拖动按钮" "description": "拖动按钮"
},
"User/UI/Window/233_HUD_Message.nut": {
"description": "公告弹窗"
} }
} }