/* 文件名:UiClassTool.nut 路径:Tool/UiClassTool.nut 创建日期:2024-03-20 11:27 文件用途:UI */ //新窗口队列 L_Windows_List <- []; //如果根空间没有选定AB层的Flag 就新建一个 默认是false 渲染在下层 if (!("WindowsShowABFlag" in getroottable())) { getroottable().WindowsShowABFlag <- false; } //是否鼠标悬停在窗口上 if (!("WindowsHoverFlag" in getroottable())) { getroottable().WindowsHoverFlag <- false; } //用于查询是否鼠标悬停在原生窗口上的Flag 以下编号代表着没有悬停其他均为悬停在原生窗口 NotOldWindowsMap <- {} NotOldWindowsMap.rawset(92, 1); NotOldWindowsMap.rawset(79, 1); NotOldWindowsMap.rawset(2396, 1); NotOldWindowsMap.rawset(3877, 1); NotOldWindowsMap.rawset(3878, 1); NotOldWindowsMap.rawset(3873, 1); NotOldWindowsMap.rawset(3874, 1); NotOldWindowsMap.rawset(3858, 1); NotOldWindowsMap.rawset(3871, 1); NotOldWindowsMap.rawset(3857, 1); NotOldWindowsMap.rawset(3861, 1); NotOldWindowsMap.rawset(3862, 1); // NotOldWindowsMap.rawset(-1, 1); NotOldWindowsMap.rawset(93, 1); NotOldWindowsMap.rawset(94, 1); NotOldWindowsMap.rawset(95, 1); NotOldWindowsMap.rawset(96, 1); NotOldWindowsMap.rawset(97, 1); NotOldWindowsMap.rawset(98, 1); NotOldWindowsMap.rawset(99, 1); NotOldWindowsMap.rawset(100, 1); NotOldWindowsMap.rawset(101, 1); NotOldWindowsMap.rawset(114, 1); NotOldWindowsMap.rawset(88, 1); NotOldWindowsMap.rawset(102, 1); NotOldWindowsMap.rawset(108, 1); NotOldWindowsMap.rawset(109, 1); NotOldWindowsMap.rawset(103, 1); NotOldWindowsMap.rawset(104, 1); NotOldWindowsMap.rawset(110, 1); NotOldWindowsMap.rawset(111, 1); NotOldWindowsMap.rawset(105, 1); NotOldWindowsMap.rawset(106, 1); NotOldWindowsMap.rawset(112, 1); NotOldWindowsMap.rawset(113, 1); NotOldWindowsMap.rawset(107, 1); NotOldWindowsMap.rawset(87, 1); NotOldWindowsMap.rawset(86, 1); NotOldWindowsMap.rawset(80, 1); NotOldWindowsMap.rawset(81, 1); NotOldWindowsMap.rawset(82, 1); NotOldWindowsMap.rawset(83, 1); NotOldWindowsMap.rawset(4067, 1); // NotOldWindowsMap.rawset(130, 1); NotOldWindowsMap.rawset(122, 1); //基础窗口类 class LenheartNewUI_BaseWindow extends BasicsDrawTool { //子控件 Childrens = null; constructor() {} //鼠标事件回调 function OnMouseProc(Flag, MousePos_X, MousePos_Y) { foreach(Window in Childrens) { Window.OnMouseProc(Flag, MousePos_X, MousePos_Y); } } //鼠标左键按下回调 function OnMouseLbDown(MousePos_X, MousePos_Y) { foreach(Window in Childrens) { Window.OnMouseLbDown(MousePos_X, MousePos_Y); } } //鼠标左键弹起回调 function OnMouseLbUp(MousePos_X, MousePos_Y) { foreach(Window in Childrens) { Window.OnMouseLbUp(MousePos_X, MousePos_Y); } } //鼠标右键按下回调 function OnMouseRbDown(MousePos_X, MousePos_Y) { foreach(Window in Childrens) { Window.OnMouseRbDown(MousePos_X, MousePos_Y); } } //鼠标右键弹起回调 function OnMouseRbUp(MousePos_X, MousePos_Y) { foreach(Window in Childrens) { Window.OnMouseRbUp(MousePos_X, MousePos_Y); } } //鼠标滚轮时间回调 function OnMouseWheel(Flag, MousePos_X, MousePos_Y) { foreach(Window in Childrens) { Window.OnMouseWheel(Flag, MousePos_X, MousePos_Y); } } function Show(obj) { foreach(Window in Childrens) { Window.Show(obj); } } function SyncPos(X, Y) { foreach(Window in Childrens) { Window.SyncPos(X, Y); } } } //窗口类 class LenheartNewUI_Windows extends LenheartNewUI_BaseWindow { //窗口名称 ObjectId = null; //可用性 Visible = true; //宽度 Width = null; //高度 Height = null; //标题高度 TitleH = null; //调试模式 DeBugMode = false; //X坐标 X = null; B_X = null; //Y坐标 Y = null; B_Y = null; M_Xpos = null; M_Ypos = null; //移动Flag MoveFlag = false; constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH) { ObjectId = gObjectId; //宽度 Width = gWidth; //高度 Height = gHeight; //标题高度 TitleH = gTitleH; //X坐标 X = gX; //Y坐标 Y = gY; ResetFocus(); //调用原生方法 LenheartNewUI_BaseWindow.constructor(); } //加入窗口队列 并且切换到最上层窗口 function ResetFocus() { foreach(Index, WindowObj in L_Windows_List) { if (WindowObj.ObjectId == this.ObjectId) L_Windows_List.remove(Index); } L_Windows_List.append(this); //切换上层显示 getroottable().WindowsShowABFlag <- true; } //关闭窗口 -并没有销毁只是隐藏 function CloseWindow() { this.Visible = false; if (L_sq_RAB(0x1B46886)) { L_sq_WAB(0x1B46886, 0); } L_sq_WA(0x1b46898, 0); } //销毁窗口 function DestroyWindow() { foreach(Index, WindowObj in L_Windows_List) { if (WindowObj.ObjectId == this.ObjectId) L_Windows_List.remove(Index); } if (L_sq_RAB(0x1B46886)) { L_sq_WAB(0x1B46886, 0); } L_sq_WA(0x1b46898, 0); } function Show(obj) { if (!Visible) return; //调用原生方法 LenheartNewUI_BaseWindow.Show(obj); if (DeBugMode) DeBug(obj); } function DeBug(obj) { sq_DrawBox(X, Y, Width, Height, 0xffffffff); sq_DrawBox(X, Y, Width, TitleH, 0xffffffff); } //override function OnMouseProc(Flag, MousePos_X, MousePos_Y) { if (!Visible) return; //设定拖动逻辑 if (Flag == 1) { if (MoveFlag) { //左键拖动 X = B_X - (M_Xpos - MousePos_X); Y = B_Y - (M_Ypos - MousePos_Y); } } //调用原生方法 LenheartNewUI_BaseWindow.OnMouseProc(Flag, MousePos_X, MousePos_Y); } //override //鼠标左键按下回调 function OnMouseLbDown(MousePos_X, MousePos_Y) { if (!Visible) return; //如果点击事件在窗口内 if (sq_IsIntersectRect(MousePos_X, MousePos_Y, 1, 1, X, Y, Width, Height)) { ResetFocus(); //如果点下去在标题栏 if (sq_IsIntersectRect(MousePos_X, MousePos_Y, 1, 1, X, Y, Width, TitleH)) { MoveFlag = true; M_Xpos = MousePos_X; //原始鼠标位置数据 M_Ypos = MousePos_Y; B_X = X; //原始窗口位置 B_Y = Y; } } //调用原生方法 LenheartNewUI_BaseWindow.OnMouseLbDown(MousePos_X, MousePos_Y); } //override //鼠标左键弹起回调 function OnMouseLbUp(MousePos_X, MousePos_Y) { if (!Visible) return; if (MoveFlag) { MoveFlag = false; M_Xpos = null; M_Ypos = null; B_X = null; B_Y = null; } //调用原生方法 LenheartNewUI_BaseWindow.OnMouseLbUp(MousePos_X, MousePos_Y); } //override //鼠标右键按下回调 function OnMouseRbDown(MousePos_X, MousePos_Y) { if (!Visible) return; //调用原生方法 LenheartNewUI_BaseWindow.OnMouseRbDown(MousePos_X, MousePos_Y); } //override //鼠标右键弹起回调 function OnMouseRbUp(MousePos_X, MousePos_Y) { if (!Visible) return; //调用原生方法 LenheartNewUI_BaseWindow.OnMouseRbUp(MousePos_X, MousePos_Y); } //override //鼠标滚轮时间回调 function OnMouseWheel(Flag, MousePos_X, MousePos_Y) { if (!Visible) return; //调用原生方法 LenheartNewUI_BaseWindow.OnMouseWheel(Flag, MousePos_X, MousePos_Y); } } //创建窗口 如果已存在则返回窗口 function LenheartNewUI_CreateWindow(ClassName, gObjectId, gX, gY, gWidth, gHeight, gTitleH) { foreach(Index, WindowObj in L_Windows_List) { if (WindowObj.ObjectId == gObjectId) { // WindowObj.Visible = true; return WindowObj; } } return ClassName(gObjectId, gX, gY, gWidth, gHeight, gTitleH); } //遍历窗口查询是否有悬停在新窗口中 function CheackMouseInNewWindows(MousePos_X, MousePos_Y) { local Flag = false; foreach(Window in L_Windows_List) { if (!Window.Visible) continue; if (sq_IsIntersectRect(MousePos_X, MousePos_Y, 1, 1, Window.X, Window.Y, Window.Width, Window.Height)) { Flag = true; getroottable().WindowsHoverFlag <- true; return Flag; } } getroottable().WindowsHoverFlag <- false; return Flag; } //遍历是否悬停在原生窗口上 function CheackMouseInOldWindows() { if (!NotOldWindowsMap.rawin(L_sq_RA(0x1A32950))) { return true; } return false; } //设定鼠标逻辑 function RunMouseLogic(MousePos_X, MousePos_Y) { //解锁鼠标 如果鼠标已处于锁定状态 并且没有悬停在任何窗口上 解锁鼠标 if (L_sq_RAB(0x1B46886)) { if (!CheackMouseInNewWindows(MousePos_X, MousePos_Y)) L_sq_WAB(0x1B46886, 0); else if (CheackMouseInOldWindows() && !getroottable().WindowsShowABFlag) L_sq_WAB(0x1B46886, 0); } //锁定鼠标 如果鼠标处于未锁定状态 并且悬停在任意一个窗口上 else if (!L_sq_RAB(0x1B46886) && CheackMouseInNewWindows(MousePos_X, MousePos_Y)) { //如果没有悬停任何原生窗口直接锁 if (!CheackMouseInOldWindows()) { L_sq_WAB(0x1B46886, 1); } //如果有悬停原生窗口 就要判断AB层 else { if (getroottable().WindowsShowABFlag) L_sq_WAB(0x1B46886, 1); } } } function L_MouseCallBack(MouseState, MouseFlag, MousePos_X, MousePos_Y) { if (MouseState == 0x200) { //常规事件就要设定鼠标是否锁定逻辑 RunMouseLogic(MousePos_X, MousePos_Y); } //如果渲染层级在下级 即A层 或者是 鼠标没有悬停在任何新窗口上时 执行判断 如果悬停在原生窗口 就解除鼠标锁定 如果点击 就改变渲染层级 if (!getroottable().WindowsShowABFlag || !CheackMouseInNewWindows(MousePos_X, MousePos_Y)) { if (CheackMouseInOldWindows()) { //如果点击了原生窗口 就把渲染队列改成下 if (MouseState == 0x201) getroottable().WindowsShowABFlag <- false; return; } } //克隆一遍窗口列表 local WindowListF = clone(L_Windows_List); WindowListF.reverse(); //判断滚轮是向上还是向下的 local Flag = MouseFlag == 0xff880000 ? 0 : 1; foreach(Window in WindowListF) { if (Window.Visible) { switch (MouseState) { //常规或者拖动事件 case 0x200: { Window.OnMouseProc(MouseFlag, MousePos_X, MousePos_Y); break; } //左键点击 case 0x201: { //如果点击了新窗口就把渲染队列改成上 getroottable().WindowsShowABFlag <- true; Window.OnMouseLbDown(MousePos_X, MousePos_Y); break; } //左键松开 case 0x202: { Window.OnMouseLbUp(MousePos_X, MousePos_Y); break; } //右键点击 case 0x204: { Window.OnMouseRbDown(MousePos_X, MousePos_Y); break; } //右键松开 case 0x205: { Window.OnMouseRbUp(MousePos_X, MousePos_Y); break; } //滚轮事件 case 0x20a: { Window.OnMouseWheel(Flag, MousePos_X, MousePos_Y); break; } } if (sq_IsIntersectRect(MousePos_X, MousePos_Y, 1, 1, Window.X, Window.Y, Window.Width, Window.Height)) return; } } } function L_OpenOldWindowCallBack(WindowIndex) { print(WindowIndex); //将新窗口渲染队列改为下层 if (WindowIndex != 170) getroottable().WindowsShowABFlag <- false; } //窗口逻辑入口 function L_WindowsLogic(obj) { // print(Clock()); //是否存在一个窗口Flag local WindowExistence = false; //遍历窗口队列 如果可见则调用Show 只要有一个可见就写入Flag foreach(Window in L_Windows_List) { Window.Proc(obj); if (Window.Visible) { Window.Show(obj); WindowExistence = true; } } //如果可见 需要调用一个原生窗口抵消ESC if (WindowExistence) { local W = sq_GetPopupWindowMainCotrol(170); if (!W) L_NewWindows("Lenheart", 170, 0x65535); else { W.SetVisible(false); W.SetEnable(false); } } //如果按下ESC键要将所有的窗口关闭 if (KeyPressNB.isKeyPress(48, "AllLenheartWindows")) { foreach(Window in L_Windows_List) { Window.Visible = false; } L_sq_WA(0x1b46898, 0); IMouse.ReleaseMouseClick(); } } function L_DrawWindow_A() { local obj = sq_GetMyMasterCharacter(); if (!obj) return; //A层只在下层渲染 if (getroottable().WindowsShowABFlag == false) L_WindowsLogic(obj); } function L_DrawWindow_B() { local obj = sq_GetMyMasterCharacter(); if (!obj) return; //B层只在上层渲染 if (getroottable().WindowsShowABFlag) L_WindowsLogic(obj); } class LenheartNewUI_CommonUi extends LenheartNewUI_BaseWindow { X = 0; Y = 0; Localtion_X = 0; Localtion_Y = 0; Width = null; Height = null; isLBDown = false; isInRect = false; OnClick = null; constructor(x, y, width, height) { this.Localtion_X = x; this.Localtion_Y = y; this.Width = width; this.Height = height; } //同步坐标 function SyncPos(x, y) { this.X = Localtion_X + x; this.Y = Localtion_Y + y; } //鼠标事件回调 function OnMouseProc(Flag, MousePos_X, MousePos_Y) { if (sq_IsIntersectRect(MousePos_X, MousePos_Y, 1, 1, X, Y, Width, Height)) isInRect = true; else isInRect = false; } //鼠标左键按下回调 function OnMouseLbDown(MousePos_X, MousePos_Y) { if (sq_IsIntersectRect(MousePos_X, MousePos_Y, 1, 1, X, Y, Width, Height)) isLBDown = true; } //鼠标左键弹起回调 function OnMouseLbUp(MousePos_X, MousePos_Y) { if (isLBDown && OnClick) { OnClick(); } isLBDown = false; } //鼠标右键按下回调 function OnMouseRbDown(MousePos_X, MousePos_Y) { } //鼠标右键弹起回调 function OnMouseRbUp(MousePos_X, MousePos_Y) { } //鼠标滚轮时间回调 function OnMouseWheel(Flag, MousePos_X, MousePos_Y) { } } class LenheartNewUI_BaseButton extends LenheartNewUI_CommonUi { State = 0; BaseIdx = 29; DWidth = null; Path = null; Idx = null; constructor(X, Y, W, H, Path, Idx) { this.DWidth = W; this.Path = Path; this.Idx = Idx; LenheartNewUI_CommonUi.constructor(X, Y, W, H); } function SetFrame(gPath, gIdx) { if (gPath) Path = gPath; Idx = gIdx; } function Show(obj) { //不可用 if (State == 8) { L_sq_DrawImg(Path, Idx + 3, X, Y + 1); } else { //按下 if (isLBDown) { L_sq_DrawImg(Path, Idx + 2, X, Y + 1); } //悬停 else if (isInRect) { L_sq_DrawImg(Path, Idx + 1, X, Y); } //普通 else { L_sq_DrawImg(Path, Idx, X, Y); } } } } class LenheartNewUI_Button extends LenheartNewUI_CommonUi { State = 0; BaseIdx = 29; DWidth = null; Path = "interface/lenheartwindowcommon.img"; Idx = 172; FillWidth = 2; FirstWidth = 28; constructor(X, Y, W) { this.DWidth = W; LenheartNewUI_CommonUi.constructor(X, Y, W + 28 * 2, 24); } function SetFrame(gPath, gIdx) { if (gPath) Path = gPath; Idx = gIdx; } function Show(obj) { //不可用 if (State == 8) { L_sq_DrawButton(X, Y + 1, this.DWidth, Path, Idx + 9, FillWidth, FirstWidth); } else { //按下 if (isLBDown) { L_sq_DrawButton(X, Y + 1, this.DWidth, Path, Idx + 3, FillWidth, FirstWidth); } //悬停 else if (isInRect) { L_sq_DrawButton(X, Y, this.DWidth, Path, Idx + 3, FillWidth, FirstWidth); } //普通 else { L_sq_DrawButton(X, Y, this.DWidth, Path, Idx, FillWidth, FirstWidth); } } } } class LenheartNewUI_ButtonText extends LenheartNewUI_Button { TextStr = null; TextX = null; TextY = null; TextColor = null; TextRColor = null; TextXoffset = null; TextYoffset = null; constructor(X, Y, W, Str) { LenheartNewUI_Button.constructor(X, Y, W); this.TextStr = Str; TextColor = sq_RGBA(185, 148, 96, 255); TextRColor = sq_RGBA(227, 212, 154, 255); TextXoffset = 19; TextYoffset = 3; } function SetTextColor(RGBA) { TextColor = RGBA; } function SetTextOffset(gX, gY) { TextXoffset = gX; TextYoffset = gY; } function Show(obj) { LenheartNewUI_Button.Show(obj); local Color = TextColor; local SY = Y + TextYoffset; if (State != 8) { if (isLBDown) { SY = Y + TextYoffset + 1; } if (isInRect || State == 1) { Color = TextRColor; } } L_sq_DrawCode(TextStr, X + TextXoffset + 19, SY + 5, Color, 0, 1); } } class LenheartNewUI_BaseInput extends LenheartNewUI_CommonUi { State = 0; InputState = 0; DWidth = null; str = ""; sliceCode = "|"; BaseTime = 0; InputController = null; constructor(X, Y, W, H) { this.DWidth = W; LenheartNewUI_CommonUi.constructor(X, Y, W, H); } function sliceCodeFlicker() { local T = Clock(); if ((T - 500) >= BaseTime) { BaseTime = T; if (sliceCode.len() > 0) sliceCode = ""; else if (sliceCode.len() == 0) sliceCode = "|"; } } function Show(obj) { //光标闪烁 if (InputState == 1) sliceCodeFlicker(); else sliceCode = ""; L_sq_DrawImg("interface/lenheartwindowcommon.img", 63, this.X, this.Y); for (local i = 0; i< this.Width; i++) { L_sq_DrawImg("interface/lenheartwindowcommon.img", 64, this.X + 3 + i, this.Y); } L_sq_DrawImg("interface/lenheartwindowcommon.img", 65, this.X + 3 + this.Width, this.Y); L_sq_DrawCode(str + sliceCode, this.X + 4, this.Y + 3, sq_RGBA(179, 169, 135, 255), 0, 1); this.OnClick = function() { InputController = L_sq_NewInputBox(this.X, this.Y, this.Width, this.Height, str); InputState = 1; } if (InputController) { local StrBuf = L_sq_GetInputBoxStr(InputController); if (StrBuf != "LenheartNULL") str = StrBuf; else { InputController = null; InputState = 0; } } } } //复选框 class LenheartNewUI_SwitchButton extends LenheartNewUI_CommonUi { State = 0; ImgIndex = null; constructor(X, Y) { LenheartNewUI_CommonUi.constructor(X, Y, 14, 15); } function Show(obj) { //不可用 if (State == 8) { L_sq_DrawImg("interface/lenheartwindowcommon.img", ImgIndex ? ImgIndex + 3 : 141, X, Y + 1); } else { //悬停 if (isLBDown) { L_sq_DrawImg("interface/lenheartwindowcommon.img", ImgIndex ? ImgIndex + 2 : 140, X, Y + 1); } //按下 else if (isInRect) { if (State == 0) L_sq_DrawImg("interface/lenheartwindowcommon.img", ImgIndex ? ImgIndex + 1 : 139, X, Y); if (State == 1) L_sq_DrawImg("interface/lenheartwindowcommon.img", ImgIndex ? ImgIndex + 2 : 140, X, Y); } //普通 else { if (State == 0) L_sq_DrawImg("interface/lenheartwindowcommon.img", ImgIndex ? ImgIndex : 138, X, Y); if (State == 1) L_sq_DrawImg("interface/lenheartwindowcommon.img", ImgIndex ? ImgIndex + 2 : 140, X, Y); } } } } class LenheartNewUI_SwitchButtonText extends LenheartNewUI_SwitchButton { TextStr = null; TextX = 0; TextY = 0; TextColor = null; TextRColor = null; constructor(X, Y, Str) { LenheartNewUI_SwitchButton.constructor(X, Y); this.TextStr = Str; TextColor = sq_RGBA(221, 197, 147, 250); TextRColor = sq_RGBA(255, 255, 184, 250); } function SetTextColor(RGBA) { TextColor = RGBA; } function SetTextPos(gX, gY) { TextX = gX; TextY = gY; } function Show(obj) { LenheartNewUI_SwitchButton.Show(obj); local Color = TextColor; local SY = Y; if (State != 8) { if (isLBDown) { SY = Y + 1; } if (isInRect || State == 1) { Color = TextRColor; } } L_sq_DrawCode(TextStr, X + 16 + TextX, SY + 1 + TextY, Color, 0, 1); } }