/* 文件名:ServerAuction.nut 路径:Plugins/ServerAuction/ServerAuction.nut 创建日期:2023-05-12 10:27 文件用途: */ //HudPro按钮类 class ServerAuctionPro 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 ServerAuctionWindow 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 ServerAuctionC extends BasicsDrawTool { WindowObj = null; //窗口对象 MainState = false; //主状态 X = 235; Y = 109; WindowName = "暂无拍卖会"; AuctionPack = null; Cost = null; NowPrice = null; TimeObj = null; TimeMax = 15000; TimeNow = 10000; ReqFrame = false; //查询拍卖回包 function Raid_Auction_Item_Pack_CallBack(Chunk) { // Sout("收到包内容为 \n %L", Chunk); local Buffer = Json_STL("Raid_Auction_Item_Pack_CallBack"); Buffer.Parse(Chunk, 0, false); local RootTab = getroottable(); if (RootTab.rawin("ServerAuctionCObj")) { RootTab["ServerAuctionCObj"].Cost = Buffer.Get("cost"); RootTab["ServerAuctionCObj"].WindowName = Buffer.Get("preset_name"); RootTab["ServerAuctionCObj"].TimeMax = Buffer.Get("auction_await_max"); RootTab["ServerAuctionCObj"].TimeNow = Buffer.Get("auction_await_now"); RootTab["ServerAuctionCObj"].ReqFrame = false; RootTab["ServerAuctionCObj"].AuctionTimeReset(); RootTab["ServerAuctionCObj"].AuctionPack = null; RootTab["ServerAuctionCObj"].AuctionPack = []; for (local i = 0; i< 5; i++) { local Gid = Buffer.Get("auctionpack->" + i + "->id"); if (Gid == false) break; local Gcount = Buffer.Get("auctionpack->" + i + "->count"); local Gname = Buffer.Get("auctionpack->" + i + "->name"); local Grarity = Buffer.Get("auctionpack->" + i + "->rarity"); local Gprice = Buffer.Get("auctionpack->" + i + "->price"); // local Gnow = i == 0 ? true : false; local Gnow = Buffer.Get("auctionpack->" + i + "->now"); local Gover = Buffer.Get("auctionpack->" + i + "->over"); local Gplayer = Buffer.Get("auctionpack->" + i + "->playername"); local Gcost_id = Buffer.Get("auctionpack->" + i + "->cost_id"); local Gcost_name = Buffer.Get("auctionpack->" + i + "->cost_name"); local T = { id = Gid, count = Gcount, name = Gname, rarity = Grarity, price = Gprice, now = Gnow, over = Gover, player = Gplayer, cost_id = Gcost_id, cost_name = Gcost_name, } RootTab["ServerAuctionCObj"].AuctionPack.append(T); } } } constructor() { //注册装备信息回调 Pack_Control.rawset(25701002, Raid_Auction_Item_Pack_CallBack); } //绘制主界面 function DrawMain(obj) { //主界面背景 T_DrawStayAni(obj, "common/server_auction/qfjp.ani", X, Y, 4, "Server_AuctionSystemMain"); //绘制窗口名字 L_sq_DrawCode("【" + WindowName + "】", X + 155 - (WindowName.len() * 2), Y + 7, sq_RGBA(255, 255, 184, 250), 0, 1); } //绘制竞拍项目 function DrawItem(obj) { if (!AuctionPack) return; foreach(Pos, Item in AuctionPack) { if (Item.now == true) { T_DrawStayAni(obj, "common/server_auction/qfjp.ani", X + 38 + (Pos * 50), Y + 40, 3, "Server_AuctionSystemSlotLight"); T_DrawStayAni(obj, "common/server_auction/qfjp.ani", X + 38 + (Pos * 50), Y + 40, 7, "Server_AuctionSystemSlotLight + 1"); //绘制竞拍物品名字 L_sq_DrawCode("【" + Item.name + "】", X + 155, Y + 207, sq_RGBA(255, 255, 184, 250), 0, 1); //绘制竞拍者名字 L_sq_DrawCode("【" + Item.player + "】", X + 155, Y + 229, sq_RGBA(255, 255, 184, 250), 0, 1); //绘制当前价格 L_sq_DrawCode(Item.price.tostring(), X + 155, Y + 251, sq_RGBA(255, 255, 184, 250), 0, 1); //绘制货币 L_Sq_DrawItem(X + 40, Y + 284, Item.cost_id, 1, 0, 0, 0); //绘制货币名字 L_sq_DrawCode("【" + Item.cost_name + "】", X + 79, Y + 299, sq_RGBA(255, 255, 184, 250), 0, 1); NowPrice = Item.price; } L_Sq_DrawItem(X + 51 + (Pos * 50), Y + 53, Item.id, Item.count, 0, 0, 0); if (Item.over == true) { T_DrawStayAni(obj, "common/server_auction/qfjp.ani", X + 48 + (Pos * 50), Y + 50, 5, "Server_AuctionSystemSlotOver"); } } } function AuctionTimeReset() { if (TimeObj) TimeObj.Delete(); TimeObj = null; TimeObj = TimeSTL("AuctionTimeObj", TimeNow); TimeObj.Reset(); TimeObj.Start(); } //绘制进度条 function DrawTimeP(obj) { if (TimeObj == null) return; local Time = TimeObj.Get(); local NTime = ((TimeNow - Time).tofloat() / 1000.0).tostring(); local HRate = (Time.tofloat() + (TimeMax.tofloat() - TimeNow.tofloat())) / TimeMax.tofloat(); setClip(X + 29, Y + 119, X + 29 + 272 - (272.0 * HRate).tointeger(), Y + 119 + 12); //开始裁切 T_DrawStayAni(obj, "common/server_auction/qfjp.ani", X + 29, Y + 119, 6, "Server_AuctionSystemTimeP"); releaseClip(); //裁切结束 L_sq_DrawCode("剩余时间: " + NTime + "s", X + 128, Y + 119, sq_RGBA(21, 187, 255, 250), 0, 1); /* //时间走到以后需要重新请求数据包 if (HRate == 0 && ReqFrame == false) { local T = { op = 25701001 } local str = Json.Encode(T); L_sq_SendPackType(130); L_sq_SendPackWChar(str); L_sq_SendPack(); ReqFrame = true; } */ } function GetNum(count) { local a = 1; if (count == 0) return a; local b = 10; for (local i = 0; i< count - 1; i++) { b *= b; } return a * b; } //绘制按钮 function DrawAuctionButton(obj) { for (local i = 0; i< 3; i++) { local Button = ServerAuctionPro(obj, "Server_AuctionButton" + i, X + 28 + (i * 98), Y + 266 + 68, "common/server_auction/qfjp.ani", 77, 24, 0); Button.SetRectEnble(true, "Server_AuctionButtonr" + i, X + 28 + (i * 98), Y + 266 + 68, "common/server_auction/qfjp.ani", 1); Button.SetCustomClickEnble(true, "Server_AuctionButtonc" + i, X + 28 + (i * 98), Y + 266 + 68, "common/server_auction/qfjp.ani", 2); Button.Show(); L_sq_DrawCode("+" + GetNum(i), X + 60 + (i * 98), Y + 272 + 68, sq_RGBA(21, 187, 255, 250), 0, 1); if (Button.isLBActive()) { local T = { op = 25701005, price = NowPrice + GetNum(i), cost = this.Cost, addcost = GetNum(i), } local str = Json.Encode(T); L_sq_SendPackType(130); L_sq_SendPackWChar(str); L_sq_SendPack(); } } } //开启界面回调 function OpenClassCallBack() { L_NewWindows("Lenheart", 170, 0x65535); local W = sq_GetPopupWindowMainCotrol(170); W.SetVisible(false); W.SetEnable(false); local T = { op = 25701001 } local str = Json.Encode(T); L_sq_SendPackType(130); L_sq_SendPackWChar(str); L_sq_SendPack(); } //绘制入口 function Draw(obj) { if (MainState) { if (WindowObj) { DrawMain(obj); //绘制主界面 DrawItem(obj); //绘制竞拍项目 DrawTimeP(obj); //绘制进度条 DrawAuctionButton(obj); //绘制按钮 WindowObj.Show(obj); X = WindowObj.X; Y = WindowObj.Y; } else { WindowObj = ServerAuctionWindow(X, Y, 329, 382, 28); //坐标 大小 标题栏高度 // WindowObj.DeBugMode = true; } } else { if (WindowObj && WindowObj.YMouseSw == false) { IMouse.ReleaseMouseClick(); WindowObj.YMouseSw = true; WindowObj = null; } } } //逻辑入口 function Proc(obj) { if (KeyPressNB.isKeyPress(48, "SeverAuctionCloseKey")) { MainState = false; } } } function ServerAuction(obj) { local RootTab = getroottable(); if (!RootTab.rawin("ServerAuctionCObj")) { local Cobj = ServerAuctionC(); RootTab.rawset("ServerAuctionCObj", Cobj); EventIcon("全服拍卖", 118, 118, Cobj); } else { RootTab["ServerAuctionCObj"].Proc(obj); RootTab["ServerAuctionCObj"].Draw(obj); } }