99 lines
2.3 KiB
Plaintext
99 lines
2.3 KiB
Plaintext
/*
|
|
文件名:ItemCollect.nut
|
|
路径:User/UI/Window/5_Inventory/ItemCollect.nut
|
|
创建日期:2025-01-06 13:50
|
|
文件用途: 物品栏
|
|
*/
|
|
|
|
|
|
|
|
// 物品栏
|
|
class itemCollection extends Yosin_CommonUi {
|
|
|
|
// 行
|
|
column = null;
|
|
// 列
|
|
row = null;
|
|
|
|
// 悬浮时显示的框
|
|
rect = null;
|
|
|
|
columnNum = null;
|
|
rowNum = null;
|
|
|
|
Canvas = null;
|
|
|
|
constructor(x, y, w, h, columnNum, rowNum) {
|
|
base.constructor(x, y, w, h);
|
|
this.columnNum = columnNum;
|
|
this.rowNum = rowNum;
|
|
|
|
// 创建画布
|
|
Canvas = CL_CanvasObject();
|
|
// 重设大小并清空
|
|
Canvas.ResizeAndClear(w, h);
|
|
// 开始绘制
|
|
Canvas.BeginDraw();
|
|
|
|
local itemX = 0;
|
|
local itemY = 0;
|
|
for (local i = 0; i< columnNum; i++) {
|
|
local cells = [];
|
|
for (local i = 0; i< rowNum; i++) {
|
|
local bg = CL_SpriteFrameObject("sprite/interface/newstyle/windows/inventory/inventory.img", 49);
|
|
Canvas.DrawSpriteFrame(bg, itemX, itemY);
|
|
|
|
itemX += 30;
|
|
|
|
}
|
|
itemX = 0;
|
|
itemY += 30;
|
|
}
|
|
|
|
// 结束绘制
|
|
Canvas.EndDraw();
|
|
// 添加画布
|
|
Addchild(Canvas);
|
|
|
|
|
|
rect = CL_SpriteObject("sprite/interface/newstyle/windows/inventory/inventory.img", 131);
|
|
rect.SetVisible(false);
|
|
Addchild(rect);
|
|
|
|
}
|
|
|
|
|
|
//override
|
|
//鼠标事件回调
|
|
function OnMouseProc(MousePos_X, MousePos_Y) {
|
|
base.OnMouseProc(MousePos_X, MousePos_Y);
|
|
|
|
if (isInRect) {
|
|
local WorldPosition = this.GetWorldPosition();
|
|
local xx = MousePos_X - WorldPosition.x -5;
|
|
local yy = MousePos_Y - WorldPosition.y -5;
|
|
local column = (yy / 30).tointeger();
|
|
local row = (xx / 30).tointeger();
|
|
|
|
|
|
local inRadius = column< columnNum && row< rowNum;
|
|
local change = column != this.column || row != this.row;
|
|
// 移动到另一个槽
|
|
if (change && inRadius) {
|
|
|
|
this.column = column;
|
|
this.row = row;
|
|
|
|
rect.SetVisible(true);
|
|
rect.SetPosition(row * 30, column * 30);
|
|
|
|
}
|
|
|
|
} else {
|
|
this.column = null;
|
|
this.row = null;
|
|
rect.SetVisible(false);
|
|
}
|
|
}
|
|
|
|
} |