鼠标框架完成 窗口事件框架完成
This commit is contained in:
@@ -6,22 +6,23 @@
|
||||
*/
|
||||
//主界面UI初始化回调
|
||||
function _MainUI_Enter_(UI_Scene) {
|
||||
if (!_SYS_UI_SCENE_Instance_) _SYS_UI_SCENE_Instance_ = Actor(UI_Scene)
|
||||
if (!_SYS_UI_SCENE_Instance_) _SYS_UI_SCENE_Instance_ = Actor(UI_Scene);
|
||||
//初始化随机数种子
|
||||
srand(time());
|
||||
|
||||
local TestWindow = sq_CreaterWindow("测试窗口", GameWindow)
|
||||
TestWindow.ResetFoucus()
|
||||
//初始化鼠标
|
||||
Game_Cursor.GetInstance();
|
||||
|
||||
local Sp = Sprite(
|
||||
"sprite/interface2/worldmap/step_2(area)/step_2(area)_bg.img",
|
||||
12
|
||||
)
|
||||
TestWindow.AddChild(Sp)
|
||||
local TestWindow = sq_CreaterWindowInstance("HUD窗口", Window_hud, 0, 0, 1280, 720, 0);
|
||||
TestWindow.ResetFoucus();
|
||||
}
|
||||
//主界面UI事件回调
|
||||
function _MainUI_HandleEvents_(event) {}
|
||||
function _MainUI_HandleEvents_(EventType, EventData) {
|
||||
_Global_Windows_Events_(EventType, EventData);
|
||||
}
|
||||
//主界面UI更新回调
|
||||
function _MainUI_Update_(deltaTime) {
|
||||
_Global_Windows_Logic_(deltaTime)
|
||||
_Global_Windows_Logic_(deltaTime);
|
||||
}
|
||||
//主界面UI退出回调
|
||||
function _MainUI_Exit_() {}
|
||||
|
||||
@@ -6,26 +6,41 @@
|
||||
*/
|
||||
class Actor extends BaseNode {
|
||||
function _typeof() {
|
||||
return "Actor"
|
||||
return "Actor";
|
||||
}
|
||||
|
||||
constructor(obj = null) {
|
||||
if (obj) {
|
||||
base.constructor(obj, false)
|
||||
base.constructor(obj, false);
|
||||
} else {
|
||||
base.constructor(sq_CreateActor())
|
||||
base.constructor(sq_CreateActor());
|
||||
}
|
||||
}
|
||||
|
||||
function AddChild(Act) {
|
||||
sq_AddChild(this.C_Object, Act.C_Object)
|
||||
sq_AddChild(this.C_Object, Act.C_Object);
|
||||
}
|
||||
|
||||
function RemoveChild(Act) {
|
||||
sq_RemoveChild(this.C_Object, Act.C_Object)
|
||||
sq_RemoveChild(this.C_Object, Act.C_Object);
|
||||
}
|
||||
|
||||
function SetZOrder(Order){
|
||||
function SetZOrder(Order) {
|
||||
sq_SetZOrder(this.C_Object, Order);
|
||||
}
|
||||
|
||||
function SetScale(Value, ...) {
|
||||
if (vargv.len() == 0)
|
||||
sq_SetScale(this.C_Object, Value);
|
||||
else if (vargv.len() == 1)
|
||||
sq_SetScale(this.C_Object, Value, vargv[0]);
|
||||
}
|
||||
|
||||
function SetPos(Value, ...) {
|
||||
if (vargv.len() == 0) {
|
||||
sq_SetPos(this.C_Object, Value);
|
||||
} else if (vargv.len() == 1) {
|
||||
sq_SetPos(this.C_Object, Value, vargv[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,36 +4,52 @@
|
||||
创建日期:2025-10-18 20:58
|
||||
文件用途:游戏窗口类
|
||||
*/
|
||||
_SYS_UI_SCENE_Instance_ <- null
|
||||
_SYS_WINDOW_LIST_ <- []
|
||||
_SYS_UI_SCENE_Instance_ <- null;
|
||||
_SYS_WINDOW_LIST_ <- [];
|
||||
|
||||
class GameWindow extends WindowNode {
|
||||
//窗口名称
|
||||
WindowName = "undefined"
|
||||
WindowName = "undefined";
|
||||
//是否活动窗口Flag
|
||||
IsActiveFlag = false;
|
||||
|
||||
function _typeof() {
|
||||
return "GameWindow"
|
||||
return "GameWindow";
|
||||
}
|
||||
|
||||
constructor(WindowName) {
|
||||
base.constructor()
|
||||
constructor(WindowName, gX, gY, gWidth, gHeight, gTitleHeight) {
|
||||
base.constructor();
|
||||
}
|
||||
|
||||
function ResetFoucus() {
|
||||
SetVisible(true)
|
||||
SetVisible(true);
|
||||
//遍历全局窗口数组将自己移除重新添加在末尾
|
||||
foreach (Index, WindowObj in _SYS_WINDOW_LIST_) {
|
||||
if (WindowObj.WindowName == this.WindowName) {
|
||||
_SYS_WINDOW_LIST_.remove(Index)
|
||||
break
|
||||
_SYS_WINDOW_LIST_.remove(Index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
_SYS_WINDOW_LIST_.append(this)
|
||||
SetZOrder(_SYS_WINDOW_LIST_.len())
|
||||
_SYS_WINDOW_LIST_.append(this);
|
||||
SetZOrder(_SYS_WINDOW_LIST_.len());
|
||||
}
|
||||
|
||||
function Proc(Dt) {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,36 +60,36 @@ class GameWindow extends WindowNode {
|
||||
* @param {GameWindow} WindowClass
|
||||
* @returns {any}
|
||||
*/
|
||||
function sq_CreaterWindow(WindowName, WindowClass) {
|
||||
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);
|
||||
local NewWindow = WindowClass(WindowName, gX, gY, gWidth, gHeight, gTitleHeight);
|
||||
getroottable()._SYS_WINDOW_LIST_.push(NewWindow);
|
||||
return NewWindow;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @function
|
||||
*
|
||||
* @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]
|
||||
local Window = _SYS_WINDOW_LIST_[i];
|
||||
//如果窗口不可见并且 处于演出状态
|
||||
if (!Window.Visible && Window.PerformanceState) {
|
||||
Window.PerformanceState = false
|
||||
_SYS_UI_SCENE_Instance_.RemoveChild(Window)
|
||||
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)
|
||||
_SYS_UI_SCENE_Instance_.AddChild(Window);
|
||||
Window.PerformanceState = true;
|
||||
}
|
||||
//无论窗口是否显示都需要调用Proc
|
||||
@@ -82,6 +98,19 @@ function _Global_Windows_Logic_(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,24 +20,23 @@ class WindowNode extends Actor {
|
||||
//销毁Flag
|
||||
DestroyFlag = false;
|
||||
|
||||
|
||||
function _typeof() {
|
||||
return "WindowNode"
|
||||
return "WindowNode";
|
||||
}
|
||||
|
||||
constructor() {
|
||||
base.constructor()
|
||||
base.constructor();
|
||||
|
||||
//子控件list初始化
|
||||
Childrens = []
|
||||
Childrens = [];
|
||||
}
|
||||
|
||||
function SetVisible(Flag) {
|
||||
Visible = Flag
|
||||
Visible = Flag;
|
||||
}
|
||||
|
||||
function AddChild(Act) {
|
||||
base.AddChild(Act)
|
||||
Childrens.push(Act)
|
||||
if (!(Act instanceof WindowNode)) base.AddChild(Act);
|
||||
Childrens.push(Act);
|
||||
}
|
||||
}
|
||||
|
||||
20
UI/Windows/HUD/Window_hud.nut
Normal file
20
UI/Windows/HUD/Window_hud.nut
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
文件名:Window_hud.nut
|
||||
路径:UI/Windows/HUD/Window_hud.nut
|
||||
创建日期:2025-10-19 20:36
|
||||
文件用途:
|
||||
*/
|
||||
|
||||
class Window_hud extends GameWindow {
|
||||
constructor(Name, gX, gY, gWidth, gHeight, gTitleHeight) {
|
||||
base.constructor(Name, gX, gY, gWidth, gHeight, gTitleHeight);
|
||||
|
||||
InitSprite();
|
||||
}
|
||||
|
||||
function InitSprite() {
|
||||
local Sp = Sprite("sprite/interface2/hud/hud.img", 0);
|
||||
Sp.SetPos((1280 - 403) / 2, 720 - 75);
|
||||
AddChild(Sp);
|
||||
}
|
||||
}
|
||||
75
UI/Windows/System/Cursor.nut
Normal file
75
UI/Windows/System/Cursor.nut
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
文件名:Cursor.nut
|
||||
路径:UI/Windows/System/Cursor.nut
|
||||
创建日期:2025-10-21 18:46
|
||||
文件用途:
|
||||
*/
|
||||
|
||||
class Game_Cursor extends GameWindow {
|
||||
//鼠标精灵数组
|
||||
MouseSprite = null;
|
||||
//当前鼠标工作ID
|
||||
CurrentMouseTaskId = 0;
|
||||
|
||||
//鼠标X坐标
|
||||
MouseX = 0;
|
||||
//鼠标Y坐标
|
||||
MouseY = 0;
|
||||
|
||||
constructor() {
|
||||
if (getroottable().rawin("__Game_Cursor__")) {
|
||||
// 防止重复实例化
|
||||
throw "Game_Cursor 不能重复实例化!";
|
||||
}
|
||||
base.constructor("系统鼠标", 0, 0, 1280, 720, 0);
|
||||
|
||||
Init();
|
||||
//设置鼠标的层级最高
|
||||
this.SetZOrder(10000000);
|
||||
_SYS_UI_SCENE_Instance_.AddChild(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 静态方法:获取唯一实例
|
||||
* @function
|
||||
* @returns {Game_Cursor}
|
||||
*/
|
||||
function GetInstance() {
|
||||
if (!getroottable().rawin("__Game_Cursor__")) {
|
||||
// 首次调用时创建实例
|
||||
getroottable()["__Game_Cursor__"] <- Game_Cursor();
|
||||
}
|
||||
return getroottable()["__Game_Cursor__"];
|
||||
}
|
||||
|
||||
function Init() {
|
||||
MouseSprite = [];
|
||||
for (local i = 0; i < 254; i++) {
|
||||
//初始化鼠标精灵
|
||||
local Buffer = Sprite("sprite/interface/newstyle/windows/cursor.img", i);
|
||||
MouseSprite.push(Buffer);
|
||||
}
|
||||
SetNormalTask(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置鼠标的普通任务
|
||||
* @function
|
||||
* @returns {void}
|
||||
*/
|
||||
function SetNormalTask(TaskId) {
|
||||
RemoveChild(MouseSprite[CurrentMouseTaskId]);
|
||||
CurrentMouseTaskId = TaskId;
|
||||
AddChild(MouseSprite[CurrentMouseTaskId]);
|
||||
MouseSprite[CurrentMouseTaskId].SetPos(MouseX, MouseY);
|
||||
}
|
||||
|
||||
//事件
|
||||
function Event(EventType, EventData) {
|
||||
if (EventType == UI_EVENT.MOUSEMOTION) {
|
||||
MouseX = EventData[0];
|
||||
MouseY = EventData[1];
|
||||
MouseSprite[CurrentMouseTaskId].SetPos(MouseX, MouseY);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user