445 lines
		
	
	
		
			14 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
			
		
		
	
	
			445 lines
		
	
	
		
			14 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
| /*
 | |
| 文件名:TownMove.nut
 | |
| 路径:Plugins/TownMove/TownMove.nut
 | |
| 创建日期:2023-05-17	18:02
 | |
| 文件用途:
 | |
| */
 | |
| 
 | |
| //HudPro按钮类
 | |
| class TownMovePro 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(gButtonName, gX, gY, gAnifile, gWidth, gLength, gBaseFrame) {
 | |
|         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) L_sq_DrawImg(CustomClickAnifile, CustomClickFrame, CustomClickx, CustomClicky);
 | |
|                 else T_DrawDynamicAni(obj, CustomClickAnifile, CustomClickx, CustomClicky, CustomButtonName);
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         if (RectEnble) //开启悬停效果时
 | |
|         {
 | |
|             if ((isInRect() && !isLBDown()) || (isInRect() && !CustomClickEnble)) //如果鼠标悬停的时候  并且没有点击的时候
 | |
|             {
 | |
|                 //IMouse.SetMouseTask(44);
 | |
|                 if (!ButtonDynamic) L_sq_DrawImg(RectBaseAnifile, RectFrame, Rectx, Recty);
 | |
|                 else T_DrawDynamicAni(obj, RectBaseAnifile, Rectx, Recty, RectButtonName);
 | |
|             }
 | |
|         }
 | |
|         if (!isInRect()) //如果鼠标没有悬停的时候
 | |
|         {
 | |
|             //IMouse.SetMouseTask(0);
 | |
|             if (!ButtonDynamic) L_sq_DrawImg(BaseAnifile, BaseFrame, x, y);
 | |
|             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 TownMoveWindow 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 TownMoveC extends BasicsDrawTool {
 | |
| 
 | |
|     //基准时间
 | |
|     BaseTime = null;
 | |
|     //闪光模式
 | |
|     FlashMode = false;
 | |
|     //按钮信息
 | |
|     ButtonInfo = null;
 | |
|     //移动信息
 | |
|     MoveInfo = null;
 | |
|     //页数
 | |
|     Page = 0;
 | |
|     //当前显示
 | |
|     PageInfo = null;
 | |
| 
 | |
|     WindowObj = null; //窗口对象
 | |
|     MainState = false; //主状态
 | |
|     X = 253;
 | |
|     Y = 55;
 | |
| 
 | |
| 
 | |
|     function GetTownMoveInfo() {
 | |
|         local T = {
 | |
|             op = 31013
 | |
|         }
 | |
|         local str = Json.Encode(T);
 | |
|         L_sq_SendPackType(130);
 | |
|         L_sq_SendPackWChar(str);
 | |
|         L_sq_SendPack();
 | |
| 
 | |
|         local T = {
 | |
|             op = 31011
 | |
|         }
 | |
|         local str = Json.Encode(T);
 | |
|         L_sq_SendPackType(130);
 | |
|         L_sq_SendPackWChar(str);
 | |
|         L_sq_SendPack();
 | |
| 
 | |
|     }
 | |
| 
 | |
|     function GetTownMoveInfoCallBack(Chunk) {
 | |
|         // Sout("收到包内容为 \n %L", Chunk);
 | |
|         local Buffer = Json_STL("TownMoveJsonObj");
 | |
|         Buffer.Parse(Chunk, 0, false);
 | |
| 
 | |
|         ButtonInfo = {};
 | |
|         ButtonInfo.x <- Buffer.Get("ButtonXpos");
 | |
|         ButtonInfo.y <- Buffer.Get("ButtonYpos");
 | |
|         ButtonInfo.sx <- Buffer.Get("ButtonSizeX");
 | |
|         ButtonInfo.sy <- Buffer.Get("ButtonSizeY");
 | |
| 
 | |
|         MoveInfo = [];
 | |
|         for (local i = 0; i< 50; i++) {
 | |
|             local TownIndex = Buffer.Get("MoveInfo->" + i + "->TownIndex");
 | |
|             if (TownIndex == false) break;
 | |
|             local AreaIndex = Buffer.Get("MoveInfo->" + i + "->AreaIndex");
 | |
|             local Xpos = Buffer.Get("MoveInfo->" + i + "->Xpos");
 | |
|             local Ypos = Buffer.Get("MoveInfo->" + i + "->Ypos");
 | |
|             local ImgPath = Buffer.Get("MoveInfo->" + i + "->ImgPath");
 | |
|             local ImgFrame = Buffer.Get("MoveInfo->" + i + "->ImgFrame");
 | |
|             local Title = Buffer.Get("MoveInfo->" + i + "->Title");
 | |
|             local T = {};
 | |
|             T.TownIndex <- TownIndex;
 | |
|             T.AreaIndex <- AreaIndex;
 | |
|             T.Xpos <- Xpos;
 | |
|             T.Ypos <- Ypos;
 | |
|             T.ImgPath <- ImgPath;
 | |
|             T.ImgFrame <- ImgFrame;
 | |
|             T.Title <- Title;
 | |
|             MoveInfo.append(T);
 | |
|         }
 | |
| 
 | |
|         PageInfo = ScrollControl(MoveInfo, 7, 1);
 | |
|     }
 | |
| 
 | |
|     constructor() {
 | |
|         //注册装备信息回调
 | |
|         Pack_Control.rawset(31012, GetTownMoveInfoCallBack.bindenv(this));
 | |
| 
 | |
|         GetTownMoveInfo();
 | |
| 
 | |
|         BaseTime = Clock();
 | |
|     }
 | |
| 
 | |
|     //绘制按钮
 | |
|     function DrawButton(obj) {
 | |
|         //如果有信息绘制按钮
 | |
|         if (ButtonInfo && !MainState) {
 | |
|             //绘制镶嵌按钮
 | |
|             local Button = TownMovePro("传送功能打开按钮", ButtonInfo.x, ButtonInfo.y, "interface2/hud/hud.img", ButtonInfo.sx, ButtonInfo.sy, 221);
 | |
|             Button.SetRectEnble(true, "传送功能打开按钮", ButtonInfo.x, ButtonInfo.y, "interface2/hud/hud.img", 222);
 | |
|             Button.SetCustomClickEnble(true, "传送功能打开按钮", ButtonInfo.x, ButtonInfo.y, "interface2/hud/hud.img", 223);
 | |
|             Button.Show();
 | |
|             if (Button.isLBActive()) {
 | |
|                 MainState = !MainState;
 | |
|                 OpenClassCallBack();
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| 
 | |
| 
 | |
| 
 | |
|     //绘制主界面
 | |
|     function DrawMain(obj) {
 | |
|         //绘制主界面
 | |
|         L_sq_DrawImg("interface2/ui/warpportal/warpportal_cn.img", 0, X, Y);
 | |
| 
 | |
|         if (PageInfo) {
 | |
|             if (IMouse.IsWheelUp()) {
 | |
|                 PageInfo.M();
 | |
|             }
 | |
|             if (IMouse.IsWheelDown()) {
 | |
|                 PageInfo.A();
 | |
|             }
 | |
| 
 | |
|             foreach(Pos, Value in PageInfo.FocusList[0]) {
 | |
|                 //绘制传送按钮
 | |
|                 local Button = TownMovePro("传送功能传送按钮" + Pos, X + 25, Y + 78 + (Pos * 52), "interface2/ui/warpportal/warpportal.img", 244, 45, Value.ImgFrame);
 | |
|                 Button.SetRectEnble(true, "传送功能传送按钮" + Pos, X + 25, Y + 78 + (Pos * 52), "interface2/ui/warpportal/warpportal.img", Value.ImgFrame + 1);
 | |
|                 Button.SetCustomClickEnble(true, "传送功能传送按钮" + Pos, X + 25, Y + 78 + (Pos * 52), "interface2/ui/warpportal/warpportal.img", Value.ImgFrame + 2);
 | |
|                 Button.Show();
 | |
|                 if (Button.isInRect()) {
 | |
|                     local NowTime = Clock() - BaseTime;
 | |
|                     if (NowTime >= 1000) {
 | |
|                         FlashMode = !FlashMode;
 | |
|                         BaseTime = Clock();
 | |
|                     }
 | |
|                     local A;
 | |
|                     if (!FlashMode) {
 | |
|                         A = sq_GetUniformVelocity(10, 250, NowTime, 1000);
 | |
|                     } else {
 | |
|                         A = sq_GetUniformVelocity(250, 10, NowTime, 1000);
 | |
|                     }
 | |
|                     //绘制特殊光效
 | |
|                     L_sq_DrawImg("interface2/ui/warpportal/warpportal.img", 1, X + 25, Y + 78 + (Pos * 52), 0, sq_RGBA(255, 255, 255, A), 1.0, 1.0);
 | |
|                 }
 | |
| 
 | |
|                 L_sq_DrawCode(Value.Title, X + 25 + 10, Y + 78 + (Pos * 52) + 14, sq_RGBA(243, 223, 197, 250), 2, 1);
 | |
|                 if (Button.isLBActive()) {
 | |
|                     L_sq_MoveTown(Value.TownIndex, Value.AreaIndex, Value.Xpos, Value.Ypos);
 | |
|                     MainState = !MainState;
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         if (PageInfo) {
 | |
| 
 | |
|             L_sq_DrawCode((PageInfo.Controller.Value + 1).tostring(), X + 124, Y + 438, sq_RGBA(150, 255, 30, 250), 0, 1);
 | |
|             L_sq_DrawCode("   /  " + (PageInfo.Controller.MaxValue + 1).tostring(), X + 124, Y + 438, sq_RGBA(150, 255, 30, 250), 0, 1);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     //开启界面回调
 | |
|     function OpenClassCallBack() {
 | |
| 
 | |
|         L_NewWindows("Lenheart", 170, 0x65535);
 | |
|         local W = sq_GetPopupWindowMainCotrol(170);
 | |
|         W.SetVisible(false);
 | |
|         W.SetEnable(false);
 | |
| 
 | |
|     }
 | |
| 
 | |
|     //绘制入口
 | |
|     function Draw(obj) {
 | |
|         DrawButton(obj);
 | |
| 
 | |
|         if (MainState) {
 | |
|             if (WindowObj) {
 | |
|                 DrawMain(obj);
 | |
|                 WindowObj.Show(obj);
 | |
|                 X = WindowObj.X;
 | |
|                 Y = WindowObj.Y;
 | |
|             } else {
 | |
|                 WindowObj = LenheartWindow(X, Y, 294, 459, 24); //坐标 大小 标题栏高度
 | |
|                 // WindowObj.DeBugMode = true;
 | |
|             }
 | |
|         } else {
 | |
|             if (WindowObj && WindowObj.YMouseSw == false) {
 | |
|                 IMouse.ReleaseMouseClick();
 | |
|                 WindowObj.YMouseSw = true;
 | |
|                 WindowObj = null;
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     //逻辑入口
 | |
|     function Proc(obj) {
 | |
|         if (KeyPressNB.isKeyPress(48, "TownMoveCloseKey")) {
 | |
|             MainState = false;
 | |
|         }
 | |
|     }
 | |
| }
 | |
| 
 | |
| function TownMove(obj) {
 | |
|     local RootTab = getroottable();
 | |
|     if (!RootTab.rawin("TownMoveCObj")) {
 | |
|         local Cobj = TownMoveC();
 | |
|         RootTab.rawset("TownMoveCObj", Cobj);
 | |
|     } else {
 | |
|         RootTab["TownMoveCObj"].Proc(obj);
 | |
|         RootTab["TownMoveCObj"].Draw(obj);
 | |
|     }
 | |
| }
 | |
| 
 | |
| // if (getroottable().rawin("LenheartFuncTab")) {
 | |
| //     getroottable()["LenheartFuncTab"].rawset("TownMoveFunc", TownMove);
 | |
| // } else {
 | |
| //     local T = {};
 | |
| //     T.rawset("TownMoveFunc", TownMove);
 | |
| //     getroottable().rawset("LenheartFuncTab", T);
 | |
| // } |