/* 文件名:WorldTower.nut 路径:Plugins/WorldTower/WorldTower.nut 创建日期:2023-06-20 06:33 文件用途: */ //HudPro按钮类 class WorldTowerPro extends BasicsDrawTool // obj -- 按钮名称 -- X坐标 -- Y坐标 -- Ani调用路径 -- 宽度 -- 高度 { obj = null; //Obj对象 State = 0; //按钮状态 ClickEnble = false; //点击效果 ButtonDynamic = false; //动态按钮效果 BaseFrame = null; CustomClickEnble = false; //自定义点击效果 CustomClickAnifile = null; //自定义点击效果Ani路径 CustomButtonName = null; //自定义点击效果名称 CustomClickFrame = null; //自定义点击效果Ani编号 CustomClickx = null; //自定义点击效果X坐标 CustomClicky = null; //自定义点击效果Y坐标 RectEnble = false; //悬停效果 RectButtonName = null; //悬停名称 RectBaseAnifile = null; //悬停Ani路径 RectFrame = null; //非动态按钮的悬停调用Ani编号 Rectx = null; //悬停X坐标 Recty = null; //悬停Y坐标 ButtonName = null; //按钮名称 x = null; //X坐标 y = null; //Y坐标 BaseAnifile = null; //调用Ani路径 width = null; //可点击宽度 length = null; //可点击高度 Mobj = null; //鼠标对象 //构造函数 constructor(gObj, gButtonName, gX, gY, gAnifile, gWidth, gLength, gBaseFrame) { obj = gObj; ButtonName = gButtonName; x = gX; y = gY; BaseAnifile = gAnifile; width = gWidth; length = gLength; BaseFrame = gBaseFrame; if (getroottable().rawin("MouseObject")) Mobj = getroottable()["MouseObject"]; } //绘制按钮 function Show() { if (ClickEnble) //是否开启点击效果 { if (isLBDown() && State == 0) //按下左键并且按钮处于弹起状态 { State = 1; //按键进入按下状态 ++y; } if (!isLBDown() && State == 1) //按下左键并且按钮处于弹起状态 { State = 0; //按键进入弹起状态 --y; } } if (CustomClickEnble) //是否开启自定义点击效果 { if (isLBDown()) //按下左键并且按钮处于弹起状态 { if (!ButtonDynamic) T_DrawStayAni(obj, CustomClickAnifile, CustomClickx, CustomClicky, CustomClickFrame, CustomButtonName); else T_DrawDynamicAni(obj, CustomClickAnifile, CustomClickx, CustomClicky, CustomButtonName); } } if (RectEnble) //开启悬停效果时 { if ((isInRect() && !isLBDown()) || (isInRect() && !CustomClickEnble)) //如果鼠标悬停的时候 并且没有点击的时候 { //IMouse.SetMouseTask(44); if (!ButtonDynamic) T_DrawStayAni(obj, RectBaseAnifile, Rectx, Recty, RectFrame, RectButtonName); else T_DrawDynamicAni(obj, RectBaseAnifile, Rectx, Recty, RectButtonName); } } if (!isInRect()) //如果鼠标没有悬停的时候 { //IMouse.SetMouseTask(0); if (!ButtonDynamic) T_DrawStayAni(obj, BaseAnifile, x, y, BaseFrame, ButtonName); else T_DrawDynamicAni(obj, BaseAnifile, x, y, ButtonName); } } //设置自定义点击效果 function SetCustomClickEnble(bool, gButtonName, gX, gY, gAnifile, gFrame) { CustomClickEnble = bool; //自定义点击效果 CustomClickAnifile = gAnifile; //自定义点击效果Ani路径 CustomButtonName = gButtonName; //自定义点击效果名称 CustomClickFrame = gFrame; //自定义点击效果Ani编号 CustomClickx = gX; //自定义点击效果X坐标 CustomClicky = gY; //自定义点击效果Y坐标 } //设置悬停效果 function SetRectEnble(bool, gButtonName, gX, gY, gAnifile, gFrame) { RectEnble = bool; //悬停效果 RectButtonName = gButtonName; //悬停名称 RectBaseAnifile = gAnifile; //悬停Ani路径 RectFrame = gFrame; //非动态按钮的悬停调用Ani编号 Rectx = gX; //悬停X坐标 Recty = gY; //悬停Y坐标 } //设置动态按钮 function SetClickEnble(bool) { ButtonDynamic = bool; } //设置点击效果 function SetClickEnble(bool) { ClickEnble = bool; } //悬停状态 function isInRect() { if (sq_IsIntersectRect(IMouse.GetXPos(), IMouse.GetYPos(), 5, 5, x, y, width, length)) return true; else return false; } //左键按下状态 function isLBDown() { if (isInRect() && Mobj.Lb == 1) return true; else return false; } //左键弹起状态 function isLBUp() { if (isInRect() && Mobj.Lb == 0) return true; else return false; } //左键单击状态 function isLBActive() { if (isInRect() && Mobj.LbEvent) return true; else return false; } } class WorldTowerWindow extends BasicsDrawTool { //宽度 Width = null; //高度 Height = null; //标题高度 TitleH = null; //X坐标 X = null; B_X = null; //Y坐标 Y = null; B_Y = null; YMouseSw = true; DeBugMode = false; Mobj = null; M_Xpos = null; M_Ypos = null; constructor(gX, gY, gWidth, gHeight, gTitleH) { //宽度 Width = gWidth; //高度 Height = gHeight; //标题高度 TitleH = gTitleH; //X坐标 X = gX; //Y坐标 Y = gY; if (getroottable().rawin("MouseObject")) Mobj = getroottable()["MouseObject"]; } //设定鼠标逻辑 function LockMouse() { if (sq_IsIntersectRect(IMouse.GetXPos(), IMouse.GetYPos(), 1, 1, X, Y, Width, Height)) { IMouse.LockMouseClick(); YMouseSw = false; } else { if (YMouseSw == false && sq_IsIntersectRect(IMouse.GetXPos(), IMouse.GetYPos(), 1, 1, 0, 0, 800, 600)) { IMouse.ReleaseMouseClick(); YMouseSw = true; } } } //设定窗口拖动逻辑 function MoveWindow() { if (sq_IsIntersectRect(IMouse.GetXPos(), IMouse.GetYPos(), 1, 1, X, Y, Width, TitleH)) { if (Mobj.Lb == 1) { if (!M_Xpos) M_Xpos = IMouse.GetXPos(); //原始鼠标位置数据 if (!M_Ypos) M_Ypos = IMouse.GetYPos(); if (!B_X) B_X = X; //原始窗口位置 if (!B_Y) B_Y = Y; X = B_X - (M_Xpos - IMouse.GetXPos()); Y = B_Y - (M_Ypos - IMouse.GetYPos()); } else if (Mobj.Lb == 0) { M_Xpos = null; M_Ypos = null; B_X = null; B_Y = null; } } } function Show(obj) { if (DeBugMode) sq_DrawBox(X, Y, Width, Height, 0xffffffff); //设定鼠标逻辑 LockMouse(); //设定窗口拖动逻辑 MoveWindow(); } } class WorldTowerC extends BasicsDrawTool { WindowObj = null; //窗口对象 MainState = false; //主状态 X = 6; Y = 30; constructor() { } //绘制功能按钮 function DrawTabButton(obj) { local Btn = WorldTowerPro(obj, "WorldTowerMain1", X + 21, Y + 29, "common/worldtower/new/btn.ani", 29, 23, 150); Btn.SetRectEnble(true, "WorldTowerMain2", X + 21, Y + 29, "common/worldtower/new/btn.ani", 151); Btn.SetCustomClickEnble(true, "WorldTowerMain3", X + 21, Y + 30, "common/worldtower/new/btn.ani", 152); Btn.Show(); } //绘制主界面 function DrawMain(obj) { //窗口 T_DrawStayAni(obj, "common/worldtower/new/resource.ani", X, Y, 0, "WorldTowerSystemMaina"); setClip(X + 2, Y + 65, X + 727, Y + 378); T_DrawDynamicAni(obj, "common/worldtower/new/title_bg_001.ani", X + 3, Y + 24, "WorldTowerSystemMainb"); releaseClip(); //裁切结束 DrawTabButton(obj); } //开启界面回调 function OpenClassCallBack() { L_NewWindows("Lenheart", 170, 0x65535); local W = sq_GetPopupWindowMainCotrol(170); W.SetVisible(false); W.SetEnable(false); } //绘制入口 function Draw(obj) { if (MainState) { if (WindowObj) { DrawMain(obj); WindowObj.Show(obj); X = WindowObj.X; Y = WindowObj.Y; } else { WindowObj = WorldTowerWindow(X, Y, 788, 468, 28); //坐标 大小 标题栏高度 //WindowObj.DeBugMode = true; } } else { if (WindowObj && WindowObj.YMouseSw == false) { IMouse.ReleaseMouseClick(); WindowObj.YMouseSw = true; WindowObj = null; } } } //逻辑入口 function Proc(obj) { if (KeyPressNB.isKeyPress(48, "WorldTowerCloseKey")) { MainState = false; } } } function WorldTower(obj) { local RootTab = getroottable(); if (!RootTab.rawin("WorldTowerCObj")) { local Cobj = WorldTowerC(); RootTab.rawset("WorldTowerCObj", Cobj); EventIcon("世界之塔", 52, 52, Cobj); } else { RootTab["WorldTowerCObj"].Proc(obj); RootTab["WorldTowerCObj"].Draw(obj); } }