Files
DNF_DEV_SQR/UI/ObjectClass/GameWidget.nut
2025-10-25 15:51:53 +08:00

81 lines
2.4 KiB
Plaintext

/*
文件名:GameWidget.nut
路径:UI/ObjectClass/GameWidget.nut
创建日期:2025-10-21 22:05
文件用途:
*/
class GameWidget extends WindowNode {
//组件ID
ObjectId = null;
//本地坐标
Localtion_X = 0;
Localtion_Y = 0;
//是否按下
isLBDown = false;
//是否悬停
isInRect = false;
//点击事件
OnClick = null;
//点击音效
ClickSound = null;
//悬停音效
HoverSound = null;
HoverSoundFlag = false;
constructor(x, y, width, height) {
this.Localtion_X = x;
this.Localtion_Y = y;
this.Width = width;
this.Height = height;
this.X = x;
this.Y = y;
ObjectId = clock();
base.constructor();
SetPos(x, y);
}
function OnMouseEvent(Type, Data, EventInteractiveFlag) {
if (!Visible) return;
//鼠标移动事件
if (Type == UI_EVENT.MOUSEMOTION) {
local Pos = GetWorldPos();
if (Math.IsIntersectRect(Data[0], Data[1], 1, 1, Pos.x, Pos.y, Width, Height)) {
//如果有配置悬停音效
if (HoverSound && !HoverSoundFlag) {
HoverSoundFlag = true;
//TODO 音效系统
// Sq_PlaySoundEffect(HoverSound);
}
isInRect = true;
} else {
HoverSoundFlag = false;
isInRect = false;
}
} else if (Type == UI_EVENT.MOUSEBUTTONDOWN) {
local IMouse = Game_Cursor.GetInstance();
local Pos = GetWorldPos();
if (Math.IsIntersectRect(IMouse.MouseX, IMouse.MouseY, 1, 1, Pos.x, Pos.y, Width, Height)) {
isLBDown = true;
}
} else if (Type == UI_EVENT.MOUSEBUTTONUP) {
local IMouse = Game_Cursor.GetInstance();
local Pos = GetWorldPos();
if (isLBDown && Math.IsIntersectRect(IMouse.MouseX, IMouse.MouseY, 1, 1, Pos.x, Pos.y, Width, Height)) {
if (OnClick) this.OnClick.call(this,this);
if (ClickSound) {
//TODO 音效系统
// Sq_PlaySoundEffect(ClickSound);
}
}
isLBDown = false;
}
foreach (Window in Childrens) {
if (Window instanceof WindowNode) Window.OnMouseEvent(Type, Data);
}
}
}