/* 文件名:ItemCollect.nut 路径:User/UI/Window/5_Inventory/ItemCollect.nut 创建日期:2025-01-06 13:50 文件用途: 物品栏 */ // 物品栏 class itemCollection extends Yosin_CommonUi{ // 行 column = null; // 列 row = null; items = null; // 悬浮时显示的框 rect = null; columnNum = null; rowNum = null; constructor(x, y, w, h, columnNum,rowNum ) { base.constructor(x, y, w, h); this.columnNum = columnNum; this.rowNum = rowNum; items = []; local background = Yosin_NineBoxStretch(-3, -3, w + 6, h + 6, "sprite/interface/lenheartwindowcommon.img", 97); AddUIChild(background); local itemX = 4; local itemY = 3; for (local i = 0; i < columnNum; i++) { local cells = []; for (local i = 0; i < rowNum; i++) { local bg = CL_SpriteObject("sprite/interface/newstyle/windows/inventory/inventory.img", 49); bg.SetPosition(itemX, itemY); Addchild(bg); itemX += 30; cells.push(bg); } items.push(cells); itemX = 3; itemY += 30; } 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; local yy = MousePos_Y - WorldPosition.y; 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); } } }