| 
									
										
										
										
											2024-12-24 15:58:20 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 文件名:3_Top_tool.nut | 
					
						
							|  |  |  | 路径:User/UI/Window/3_Top_tool.nut | 
					
						
							|  |  |  | 创建日期:2024-12-21	23:43 | 
					
						
							|  |  |  | 文件用途: 顶部工具条 | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class _Top_tool extends Yosin_Window { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     timeTextActor = null; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-27 15:27:02 +08:00
										 |  |  |     //是否可见 | 
					
						
							|  |  |  |     // Visible = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //是否为顶层窗口 | 
					
						
							|  |  |  |     // IsTop = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //窗口位置 | 
					
						
							|  |  |  |     WindowPos = null; | 
					
						
							|  |  |  |     WindowMoveFlag = false; | 
					
						
							|  |  |  |     BaseCursorWPos = null; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-24 15:58:20 +08:00
										 |  |  |     constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH) { | 
					
						
							|  |  |  |         base.constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         //注册绘制 | 
					
						
							|  |  |  |         RegisterDraw(); | 
					
						
							|  |  |  |         //注册控件 | 
					
						
							|  |  |  |         RegisterWidget(); | 
					
						
							| 
									
										
										
										
											2024-12-27 15:27:02 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         WindowPos = Sq_GetWindowRect(); | 
					
						
							| 
									
										
										
										
											2024-12-24 15:58:20 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function RegisterWidget() { | 
					
						
							|  |  |  |         local background = Yosin_EmeStretch(0, 0, 650, 20, "sprite/interface/lenheartwindowcommon.img", 612); | 
					
						
							|  |  |  |         AddUIChild(background); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         local timeBackGround = Yosin_EmeStretch(14, 2, 90, 14, "sprite/interface/lenheartwindowcommon.img", 615); | 
					
						
							|  |  |  |         AddUIChild(timeBackGround); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // 时间 | 
					
						
							|  |  |  |         timeTextActor = FontAssetManager.GenerateNormal(getTimeString(), true, { | 
					
						
							|  |  |  |             color = sq_RGBA(200, 195, 169, 255) | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |         timeTextActor.SetPosition(20, 4); | 
					
						
							|  |  |  |         Addchild(timeTextActor); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // 三角 | 
					
						
							|  |  |  |         local jiao = CL_SpriteObject("sprite/interface/lenheartwindowcommon.img", 622); | 
					
						
							|  |  |  |         jiao.SetPosition(85, 7.5); | 
					
						
							|  |  |  |         Addchild(jiao); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // 最小化 | 
					
						
							|  |  |  |         local minButton = _Top_tool_Button(576, 1, 22, 16 "sprite/interface/lenheartwindowcommon.img", 618); | 
					
						
							| 
									
										
										
										
											2024-12-27 15:27:02 +08:00
										 |  |  |         minButton.OnClick = function(Button) { | 
					
						
							|  |  |  |             Sq_ShowWindow(6); | 
					
						
							|  |  |  |         }.bindenv(this); | 
					
						
							| 
									
										
										
										
											2024-12-24 15:58:20 +08:00
										 |  |  |         AddUIChild(minButton); | 
					
						
							|  |  |  |         // 最大化 | 
					
						
							|  |  |  |         local maxButton = _Top_tool_Button(598, 1, 22, 16 "sprite/interface/lenheartwindowcommon.img", 628); | 
					
						
							| 
									
										
										
										
											2024-12-27 15:27:02 +08:00
										 |  |  |         maxButton.OnClick = function(Button) { | 
					
						
							|  |  |  |             Sq_ShowWindow(3); | 
					
						
							|  |  |  |         }.bindenv(this); | 
					
						
							| 
									
										
										
										
											2024-12-24 15:58:20 +08:00
										 |  |  |         AddUIChild(maxButton); | 
					
						
							|  |  |  |         // 关闭 | 
					
						
							|  |  |  |         local closeButton = _Top_tool_Button(620, 1, 22, 16 "sprite/interface/lenheartwindowcommon.img", 624); | 
					
						
							| 
									
										
										
										
											2024-12-27 15:27:02 +08:00
										 |  |  |         closeButton.OnClick = function(Button) { | 
					
						
							|  |  |  |             Sq_CloseWindow(); | 
					
						
							|  |  |  |         }.bindenv(this); | 
					
						
							| 
									
										
										
										
											2024-12-24 15:58:20 +08:00
										 |  |  |         AddUIChild(closeButton); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function RegisterDraw() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function getTimeString() { | 
					
						
							|  |  |  |         local date = date(time()); | 
					
						
							|  |  |  |         local timeStr = ""; | 
					
						
							|  |  |  |         if (date.hour >= 12) { | 
					
						
							|  |  |  |             timeStr = "PM " + (date.hour - 12).tostring() + ":" + date.min.tostring(); | 
					
						
							| 
									
										
										
										
											2024-12-27 15:27:02 +08:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2024-12-24 15:58:20 +08:00
										 |  |  |             timeStr = "AM " + date.hour.tostring() + ":" + date.min.tostring(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return timeStr; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //逻辑入口 | 
					
						
							|  |  |  |     function Proc(Dt) { | 
					
						
							|  |  |  |         SyncPos(X, Y); | 
					
						
							|  |  |  |         base.Proc(Dt); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-27 15:27:02 +08:00
										 |  |  |         if (time() % 60 == 0) { | 
					
						
							| 
									
										
										
										
											2024-12-24 15:58:20 +08:00
										 |  |  |             timeTextActor.SetText(getTimeString()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-27 15:27:02 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         //如果事件在窗口内 | 
					
						
							|  |  |  |         if (Math.IsIntersectRect(Yosin_Cursor.X, Yosin_Cursor.Y, 1, 1, X, Y, Width, Height)) { | 
					
						
							|  |  |  |             if (!Visible) ResetFocus(); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             Visible = false; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-12-24 15:58:20 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-27 15:27:02 +08:00
										 |  |  |     //override | 
					
						
							|  |  |  |     //鼠标事件回调 | 
					
						
							|  |  |  |     function OnMouseProc(MousePos_X, MousePos_Y) { | 
					
						
							|  |  |  |         base.OnMouseProc(MousePos_X, MousePos_Y); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         //设定拖动逻辑 | 
					
						
							|  |  |  |         if (WindowMoveFlag) { | 
					
						
							|  |  |  |             local pos = Sq_GetCursorPos(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             local WX = pos.x - M_Xpos; | 
					
						
							|  |  |  |             local WY = pos.y - M_Ypos; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             M_Xpos = pos.x; | 
					
						
							|  |  |  |             M_Ypos = pos.y; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             WindowPos.left += WX; | 
					
						
							|  |  |  |             WindowPos.top += WY; | 
					
						
							|  |  |  |             Sq_SetCursorPos(WindowPos.left + BaseCursorWPos.x, WindowPos.top + BaseCursorWPos.y); | 
					
						
							|  |  |  |             Sq_SetWindowPos(WindowPos.left, WindowPos.top); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //override | 
					
						
							|  |  |  |     //鼠标左键单击回调 | 
					
						
							|  |  |  |     function OnMouseLbDown(MousePos_X, MousePos_Y) { | 
					
						
							|  |  |  |         base.OnMouseLbDown(MousePos_X, MousePos_Y); | 
					
						
							|  |  |  |         //如果点击事件在窗口内 | 
					
						
							|  |  |  |         if (Math.IsIntersectRect(Yosin_Cursor.X, Yosin_Cursor.Y, 1, 1, X, Y, Width, Height)) { | 
					
						
							|  |  |  |             WindowMoveFlag = true; | 
					
						
							|  |  |  |             local pos = Sq_GetCursorPos(); | 
					
						
							|  |  |  |             M_Xpos = pos.x; //原始鼠标位置数据 | 
					
						
							|  |  |  |             M_Ypos = pos.y; | 
					
						
							|  |  |  |             BaseCursorWPos = { | 
					
						
							|  |  |  |                 x = MousePos_X, | 
					
						
							|  |  |  |                 y = MousePos_Y | 
					
						
							|  |  |  |             }; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //override | 
					
						
							|  |  |  |     //鼠标左键弹起回调 | 
					
						
							|  |  |  |     function OnMouseLbUp(MousePos_X, MousePos_Y) { | 
					
						
							|  |  |  |         //调用原生方法 | 
					
						
							|  |  |  |         base.OnMouseLbUp(MousePos_X, MousePos_Y); | 
					
						
							|  |  |  |         if (WindowMoveFlag) { | 
					
						
							|  |  |  |             WindowMoveFlag = false; | 
					
						
							|  |  |  |             M_Xpos = null; | 
					
						
							|  |  |  |             M_Ypos = null; | 
					
						
							|  |  |  |             BaseCursorWPos = null; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-12-24 15:58:20 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class _Top_tool_Button extends Yosin_BaseButton { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     border = null; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     constructor(X, Y, W, H, Path, Idx) { | 
					
						
							|  |  |  |         base.constructor(X, Y, W, H, Path, Idx); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         border = CL_SpriteObject("sprite/interface/lenheartwindowcommon.img", 623); | 
					
						
							|  |  |  |         Addchild(border); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //逻辑入口 | 
					
						
							|  |  |  |     function Proc(obj) { | 
					
						
							|  |  |  |         base.Proc(obj); | 
					
						
							|  |  |  |         border.SetVisible(isLBDown); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-27 15:27:02 +08:00
										 |  |  | } |