152 lines
4.3 KiB
Plaintext
152 lines
4.3 KiB
Plaintext
/*
|
|
文件名:ItemSlot.nut
|
|
路径:User/UI/Window/9_HUD/ItemSlot.nut
|
|
创建日期:2025-02-18 07:36
|
|
文件用途:HUD血槽的物品槽
|
|
*/
|
|
class UISpace_Hud.ItemSlot extends Yosin_CommonUi {
|
|
Pos = null;
|
|
|
|
//悬停特效
|
|
HoverEffect = null;
|
|
|
|
//物品对象
|
|
Item = null;
|
|
//物品对象的图标
|
|
ItemIcon = null;
|
|
//物品对象的详细信息窗口
|
|
ItemInfo = null;
|
|
//详细信息窗口显示Flag
|
|
ItemInfoShowFlag = false;
|
|
|
|
constructor(gPos) {
|
|
this.Pos = gPos;
|
|
base.constructor(0, 0, 28, 28);
|
|
// OpenDeBug();
|
|
|
|
//角标绘制
|
|
local CornerMarkerDrawing = CL_SpriteObject("sprite/interface/keyshortcut.img", 46 + gPos);
|
|
CornerMarkerDrawing.SetZOrder(9);
|
|
Addchild(CornerMarkerDrawing);
|
|
|
|
HoverEffect = CL_SpriteObject("sprite/interface/newstyle/windows/inventory/inventory.img", 131);
|
|
HoverEffect.SetPosition(1, 1);
|
|
HoverEffect.SetZOrder(10);
|
|
HoverEffect.SetVisible(false);
|
|
Addchild(HoverEffect);
|
|
|
|
}
|
|
|
|
function SetItem(Item) {
|
|
//关闭所有详细信息显示
|
|
if (ItemInfoShowFlag) {
|
|
CloseInfo();
|
|
}
|
|
|
|
if (Item) {
|
|
this.Item = Item;
|
|
//如果原先有图标则先移除图标在添加
|
|
if (this.ItemIcon) {
|
|
Removechild(this.ItemIcon);
|
|
}
|
|
this.ItemIcon = this.Item.GetIconSprite();
|
|
Addchild(this.ItemIcon);
|
|
this.ItemInfo = this.Item.GetInfoWindow();
|
|
} else {
|
|
this.Item = null;
|
|
if (this.ItemIcon) {
|
|
Removechild(this.ItemIcon);
|
|
this.ItemIcon = null;
|
|
}
|
|
this.ItemInfo = null;
|
|
}
|
|
this.ItemIcon.SetPosition(1, 1);
|
|
}
|
|
|
|
//显示详细信息
|
|
function ShowInfo(x, y) {
|
|
if (!Item) return;
|
|
if (!this.ItemInfo) GenerateInfo();
|
|
this.ItemInfoShowFlag = true;
|
|
|
|
// 获取信息框尺寸
|
|
local infoW = 211;
|
|
local infoH = this.ItemInfo.RealCanvasHeight;
|
|
|
|
// X轴边界修正
|
|
if (x< 0) {
|
|
x = 0;
|
|
} else if (x + infoW > 1067) {
|
|
x = 1067 - infoW;
|
|
}
|
|
// Y轴边界修正
|
|
if (y< 0) {
|
|
y = 0;
|
|
} else if (y + infoH > 600) {
|
|
y = 600 - infoH;
|
|
}
|
|
|
|
//设置位置
|
|
this.ItemInfo.SetPosition(x, y);
|
|
this.ItemInfo.ResetFocus();
|
|
}
|
|
|
|
//关闭显示详细信息
|
|
function CloseInfo() {
|
|
if (this.ItemInfo) {
|
|
this.ItemInfoShowFlag = false;
|
|
this.ItemInfo.CloseWindow();
|
|
}
|
|
}
|
|
|
|
//override
|
|
//鼠标事件回调
|
|
function OnMouseProc(MousePos_X, MousePos_Y, WindowInteractiveFlag) {
|
|
if (!Visible) return;
|
|
base.OnMouseProc(MousePos_X, MousePos_Y, WindowInteractiveFlag);
|
|
if (isInRect && !IMouse.DragObj && !WindowInteractiveFlag) {
|
|
//如果有道具
|
|
if (Item) {
|
|
//设置透明度
|
|
HoverEffect.SetOpacity(0.4);
|
|
if (!ItemInfoShowFlag) {
|
|
//显示详细信息
|
|
ShowInfo(MousePos_X - 50, MousePos_Y - ((ItemInfo.RealCanvasHeight + 10) / 2));
|
|
}
|
|
}
|
|
//设置悬停槽
|
|
HoverEffect.SetVisible(true);
|
|
} else {
|
|
HoverEffect.SetVisible(false);
|
|
//关闭所有详细信息显示
|
|
if (ItemInfoShowFlag) {
|
|
CloseInfo();
|
|
}
|
|
}
|
|
}
|
|
|
|
//override
|
|
//鼠标右键单击回调
|
|
function OnMouseRbClick(MousePos_X, MousePos_Y, WindowInteractiveFlag) {
|
|
//调用原生方法
|
|
base.OnMouseRbClick(MousePos_X, MousePos_Y, WindowInteractiveFlag);
|
|
if (isInRect && !WindowInteractiveFlag) {
|
|
//发送脱下装备包
|
|
MySocket.Send(PACKET_ID.WEAR_EQUIPMENT, {
|
|
backpackId = 8,
|
|
oldPos = Pos
|
|
});
|
|
}
|
|
}
|
|
|
|
//override
|
|
//鼠标左键单击回调
|
|
function OnMouseLbDown(MousePos_X, MousePos_Y, WindowInteractiveFlag) {
|
|
//调用原生方法
|
|
base.OnMouseLbDown(MousePos_X, MousePos_Y, WindowInteractiveFlag);
|
|
//关闭所有详细信息显示
|
|
if (ItemInfoShowFlag) {
|
|
CloseInfo();
|
|
}
|
|
}
|
|
} |