Files
DNF_DEV_SQR/UI/ObjectClass/WindowNode.nut
2025-10-21 23:06:06 +08:00

127 lines
3.4 KiB
Plaintext

/*
文件名:WindowNode.nut
路径:UI/ObjectClass/WindowNode.nut
创建日期:2025-10-18 20:54
文件用途:窗口节点类
*/
_SYS_UI_SCENE_Instance_ <- null;
_SYS_WINDOW_LIST_ <- [];
class WindowNode extends Actor {
//演出状态
PerformanceState = false;
//子控件
Childrens = null;
//刷新函数
UpdateFunc = null;
//是否可见
Visible = true;
//宽度
Width = null;
//高度
Height = null;
//销毁Flag
DestroyFlag = false;
//X坐标
X = null;
B_X = null;
//Y坐标
Y = null;
B_Y = null;
function _typeof() {
return "WindowNode";
}
constructor() {
base.constructor();
//子控件list初始化
Childrens = [];
}
function SetVisible(Flag) {
Visible = Flag;
base.SetVisible(Flag);
}
function AddChild(Act) {
base.AddChild(Act);
Childrens.push(Act);
}
function Proc(Dt){
if (UpdateFunc != null) this.UpdateFunc(Dt);
SetPos(X, Y);
}
}
/**
*
* @function
* @param {any} WindowName
* @param {GameWindow} WindowClass
* @returns {any}
*/
function sq_CreaterWindowInstance(WindowName, WindowClass, gX, gY, gWidth, gHeight, gTitleHeight) {
foreach (idx, val in _SYS_WINDOW_LIST_) {
if (val.WindowName == WindowName) {
return val;
}
}
local NewWindow = WindowClass(WindowName, gX, gY, gWidth, gHeight, gTitleHeight);
getroottable()._SYS_WINDOW_LIST_.push(NewWindow);
return NewWindow;
}
/**
*
* @function
* @param {float} Dt
* @returns {void}
*/
function _Global_Windows_Logic_(Dt) {
if (_SYS_UI_SCENE_Instance_) {
for (local i = 0; i < _SYS_WINDOW_LIST_.len(); i++) {
local Window = _SYS_WINDOW_LIST_[i];
//如果窗口不可见并且 处于演出状态
if (!Window.Visible && Window.PerformanceState) {
Window.PerformanceState = false;
_SYS_UI_SCENE_Instance_.RemoveChild(Window);
if (Window.DestroyFlag) {
_SYS_WINDOW_LIST_.remove(i);
i--;
}
} else if (Window.Visible && !Window.PerformanceState) {
_SYS_UI_SCENE_Instance_.AddChild(Window);
Window.PerformanceState = true;
}
//无论窗口是否显示都需要调用Proc
Window.Proc(Dt);
}
}
}
function _Global_Windows_Events_(EventType, EventData) {
//先传递鼠标事件
local IMouse = Game_Cursor.GetInstance();
IMouse.Event(EventType, EventData);
//事件是否被响应Flag
local EventInteractiveFlag = false;
for (local i = _SYS_WINDOW_LIST_.len() - 1; i > -1; i--) {
local Window = _SYS_WINDOW_LIST_[i];
if (Window.Visible) {
if (EventType == UI_EVENT.MOUSEMOTION || EventType == UI_EVENT.MOUSEBUTTONDOWN || EventType == UI_EVENT.MOUSEBUTTONUP) {
Window.OnMouseEvent(EventType, EventData, EventInteractiveFlag);
} else if (EventType == UI_EVENT.KEYDOWN || EventType == UI_EVENT.KEYUP) {
Window.OnKeyEvent(EventType, EventData, EventInteractiveFlag);
}
if (Math.IsIntersectRect(IMouse.MouseX, IMouse.MouseY, 1, 1, Window.X, Window.Y, Window.Width, Window.Height)) {
EventInteractiveFlag = Window;
}
}
}
}