117 lines
3.4 KiB
Plaintext
117 lines
3.4 KiB
Plaintext
/*
|
|
文件名:GameWindow.nut
|
|
路径:UI/ObjectClass/GameWindow.nut
|
|
创建日期:2025-10-18 20:58
|
|
文件用途:游戏窗口类
|
|
*/
|
|
_SYS_UI_SCENE_Instance_ <- null;
|
|
_SYS_WINDOW_LIST_ <- [];
|
|
|
|
class GameWindow extends WindowNode {
|
|
//窗口名称
|
|
WindowName = "undefined";
|
|
//是否活动窗口Flag
|
|
IsActiveFlag = false;
|
|
|
|
function _typeof() {
|
|
return "GameWindow";
|
|
}
|
|
|
|
constructor(WindowName, gX, gY, gWidth, gHeight, gTitleHeight) {
|
|
base.constructor();
|
|
}
|
|
|
|
function ResetFoucus() {
|
|
SetVisible(true);
|
|
//遍历全局窗口数组将自己移除重新添加在末尾
|
|
foreach (Index, WindowObj in _SYS_WINDOW_LIST_) {
|
|
if (WindowObj.WindowName == this.WindowName) {
|
|
_SYS_WINDOW_LIST_.remove(Index);
|
|
break;
|
|
}
|
|
}
|
|
_SYS_WINDOW_LIST_.append(this);
|
|
SetZOrder(_SYS_WINDOW_LIST_.len());
|
|
}
|
|
|
|
function Proc(Dt) {}
|
|
|
|
//鼠标事件回调
|
|
function OnMouseEvent(Type, Data) {
|
|
if (!Visible) return;
|
|
foreach (Window in Childrens) {
|
|
if (Window instanceof WindowNode) Window.OnMouseEvent(Type, Data);
|
|
}
|
|
}
|
|
|
|
//键盘事件回调
|
|
function OnKeyEvent(Type, Data) {
|
|
if (!Visible) return;
|
|
foreach (Window in Childrens) {
|
|
if (Window instanceof WindowNode) Window.OnKeyEvent(Type, Data);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @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) {
|
|
//先传递鼠标事件
|
|
Game_Cursor.GetInstance().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);
|
|
} else if (EventType == UI_EVENT.KEYDOWN || EventType == UI_EVENT.KEYUP) {
|
|
Window.OnKeyEvent(EventType, EventData);
|
|
}
|
|
}
|
|
}
|
|
}
|