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