359 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
			
		
		
	
	
			359 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
| /*
 | |
| 文件名:CollectionBox.nut
 | |
| 路径:Project/CollectionBox/CollectionBox.nut
 | |
| 创建日期:2024-09-14	15:08
 | |
| 文件用途:收集箱
 | |
| */
 | |
| class LenheartNewUI_CollectionBox_BaseButton extends LenheartNewUI_CommonUi {
 | |
|     State = 0;
 | |
|     BaseIdx = 29;
 | |
|     DWidth = null;
 | |
|     Path = null;
 | |
|     Idx = null;
 | |
|     SetFlag = null;
 | |
|     SetIndex = null;
 | |
| 
 | |
| 
 | |
|     constructor(X, Y, W, H, Path, Idx) {
 | |
|         this.DWidth = W;
 | |
|         this.Path = Path;
 | |
|         this.Idx = Idx;
 | |
|         LenheartNewUI_CommonUi.constructor(X, Y, W, H);
 | |
| 
 | |
|     }
 | |
| 
 | |
|     function SetFrame(gPath, gIdx) {
 | |
|         if (gPath) Path = gPath;
 | |
|         Idx = gIdx;
 | |
|     }
 | |
| 
 | |
|     function Show(obj) {
 | |
|         //不可用
 | |
|         if (State == 8) {
 | |
|             L_sq_DrawImg(Path, Idx + 3, X, Y + 1);
 | |
|         } else {
 | |
|             //按下
 | |
|             if (isLBDown) {
 | |
|                 L_sq_DrawImg(Path, Idx + 2, X, Y + 1);
 | |
|             }
 | |
|             //悬停
 | |
|             else if (isInRect) {
 | |
|                 L_sq_DrawImg(Path, Idx + 1, X, Y);
 | |
|             }
 | |
|             //普通
 | |
|             else {
 | |
|                 L_sq_DrawImg(Path, Idx, X, Y);
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     //鼠标左键弹起回调
 | |
|     function OnMouseLbUp(MousePos_X, MousePos_Y) {
 | |
|         if (isLBDown && OnClick) {
 | |
|             local obj = sq_getMyCharacter();
 | |
|             obj.sq_PlaySound("CLICK_BUTTON1");
 | |
|             OnClick(this);
 | |
|         }
 | |
|         isLBDown = false;
 | |
|     }
 | |
| }
 | |
| 
 | |
| class CollectionBoxC extends LenheartNewUI_Windows {
 | |
|     //调试模式
 | |
|     // DeBugMode = true;
 | |
| 
 | |
|     //不是窗口
 | |
|     // NoWindow = true;
 | |
| 
 | |
|     //是否可见
 | |
|     Visible = false;
 | |
| 
 | |
|     //盒子按钮集合
 | |
|     BoxButton = null;
 | |
| 
 | |
|     //信息
 | |
|     Info = null;
 | |
| 
 | |
|     //当前页面
 | |
|     Page = null;
 | |
| 
 | |
|     //滚轮偏移
 | |
|     ScrollPos = 0;
 | |
| 
 | |
|     //页面滚轮偏移
 | |
|     PageScrollPos = 0;
 | |
| 
 | |
|     //悬停的宝珠
 | |
|     HoverItem = null;
 | |
| 
 | |
|     //镶嵌成功音效包
 | |
|     function AudioCallBack(Chunk) {
 | |
|         local Jso = Json.Decode(Chunk);
 | |
|         local Type = Jso.Type;
 | |
|         local obj = sq_getMyCharacter();
 | |
| 
 | |
|         switch (Type) {
 | |
|             case 1:
 | |
|                 obj.sq_PlaySound("TRADE_OK");
 | |
|                 break;
 | |
|             case 2:
 | |
|                 obj.sq_PlaySound("ICON_DROP_TO_QUICKSLOT");
 | |
|                 break;
 | |
|             case 3:
 | |
|                 obj.sq_PlaySound("GAMBLE_RESULT_GOOD");
 | |
|                 break;
 | |
|         }
 | |
| 
 | |
|     }
 | |
| 
 | |
|     //基础配置包
 | |
|     function GetInfoCallBack(Chunk) {
 | |
|         local Jso = Json.Decode(Chunk);
 | |
|         local ZlibStrBuf = Json.Decode(L_sq_Dezlib(Jso.ZipS));
 | |
|         Info = ZlibStrBuf.info;
 | |
|         foreach(Key, Aobj in Info) {
 | |
|             if (!Page) Page = Key;
 | |
|             local StrBuf1 = L_sq_GetStringDrawArray(Aobj.attS, 300);
 | |
|             Aobj.AttsS <- StrBuf1[0] + "...";
 | |
|             Aobj.attS <- StrBuf1;
 | |
|         }
 | |
| 
 | |
|         InitBoxButton();
 | |
|     }
 | |
| 
 | |
|     //获取收集信息
 | |
|     function GetCollectInfo() {
 | |
|         local T = {
 | |
|             op = 20077003
 | |
|         };
 | |
|         SendPackEx(T);
 | |
|     }
 | |
| 
 | |
|     constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH) {
 | |
|         Childrens = [];
 | |
|         BoxButton = [];
 | |
|         //注册控件
 | |
|         RegisterWidget();
 | |
| 
 | |
|         LenheartNewUI_Windows.constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH);
 | |
| 
 | |
|         Pack_Control.rawset(20077028, GetInfoCallBack.bindenv(this));
 | |
|         Pack_Control.rawset(20077010, AudioCallBack.bindenv(this));
 | |
| 
 | |
|         GetCollectInfo();
 | |
| 
 | |
|     }
 | |
| 
 | |
|     //初始化按钮
 | |
|     function InitBoxButton() {
 | |
|         if (BoxButton.len() > 0) {
 | |
|             for (local i = 0; i< Childrens.len(); i++) {
 | |
|                 local Cobj = Childrens[i];
 | |
|                 if (Cobj instanceof LenheartNewUI_CollectionBox_BaseButton) {
 | |
|                     Childrens.remove(i);
 | |
|                     i--;
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         local RealPos = 0;
 | |
|         foreach(Pos, InfoObj in Info) {
 | |
|             //关闭按钮
 | |
|             local ButtonBuf = LenheartNewUI_CollectionBox_BaseButton(8, 95 + (RealPos * 72), 102, 70, InfoObj.img, 1);
 | |
|             ButtonBuf.SetFlag = Pos;
 | |
|             ButtonBuf.SetIndex = RealPos;
 | |
|             ButtonBuf.OnClick = function(ButtonObj) {
 | |
|                 Page = ButtonObj.SetFlag;
 | |
|             }.bindenv(this);
 | |
|             ButtonBuf.SetCallBackFunc(function(ButtonObj) {
 | |
|                 ButtonObj.Localtion_Y = 95 + ((ButtonObj.SetIndex - ScrollPos) * 72);
 | |
|                 if (ButtonObj.Localtion_Y< 95 || ButtonObj.Localtion_Y > 311) ButtonObj.Localtion_X = -9000;
 | |
|                 else ButtonObj.Localtion_X = 8;
 | |
|             }.bindenv(this));
 | |
|             Childrens.append(ButtonBuf);
 | |
|             RealPos++;
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     function RegisterWidget() {
 | |
|         //关闭按钮
 | |
|         local CloseButton = LenheartNewUI_BaseButton(356, 2, 11, 12, "interface/lenheartwindowcommon.img", 276);
 | |
|         CloseButton.OnClick = function() {
 | |
|             this.Visible = false;
 | |
|         }.bindenv(this);
 | |
|         Childrens.append(CloseButton);
 | |
| 
 | |
| 
 | |
|     }
 | |
| 
 | |
|     //绘制主界面
 | |
|     function DrawMain(obj) {
 | |
|         if (!Info) return;
 | |
|         //窗口
 | |
|         L_sq_DrawImg("interface2/collectbox/collectboxbtn.img", 0, X, Y);
 | |
|         //背景
 | |
|         L_sq_DrawImg(Info[Page].img, 0, X + 7, Y + 26);
 | |
|         //绘制窗口名称
 | |
|         L_sq_DrawCode("我的收集箱", X + 160, Y + 8, sq_RGBA(255, 177, 0, 250), 0, 1);
 | |
|         //绘制收集箱名称
 | |
|         L_sq_DrawCode(Info[Page].name, X + 208 - LenheartTextClass.GetStringLength(Info[Page].name) / 2, Y + 40, sq_RGBA(255, 177, 0, 250), 0, 1);
 | |
|         //绘制收集箱信息缩略
 | |
|         L_sq_DrawCode(Info[Page].AttsS, X + 228 - LenheartTextClass.GetStringLength(Info[Page].AttsS) / 2, Y + 40 + 20, sq_RGBA(255, 242, 0, 250), 0, 1);
 | |
| 
 | |
| 
 | |
|         HoverItem = null;
 | |
|         setClip(X + 95, Y + 95, X + 348, Y + 375); //开始裁切
 | |
|         //绘制宝珠
 | |
|         foreach(pos, value in Info[Page].itemIds) {
 | |
|             //绘制格子
 | |
|             L_sq_DrawImg(Info[Page].img, 5, X + value.x, Y + value.y + PageScrollPos);
 | |
|             //绘制宝珠
 | |
|             DrawItemEx(X + value.x + Info[Page].Xp, Y + value.y + Info[Page].Yp + PageScrollPos, value.id, 1);
 | |
|             //判断是否拥有
 | |
|             if (!value.isTure) {
 | |
|                 //遮挡
 | |
|                 L_sq_DrawImg("interface/windowcommon.img", 157, X + value.x + Info[Page].Xp, Y + value.y + Info[Page].Yp + PageScrollPos);
 | |
|                 L_sq_DrawImg("interface/windowcommon.img", 157, X + value.x + Info[Page].Xp, Y + value.y + Info[Page].Yp + PageScrollPos);
 | |
|                 L_sq_DrawImg("interface/windowcommon.img", 157, X + value.x + Info[Page].Xp, Y + value.y + Info[Page].Yp + PageScrollPos);
 | |
|             }
 | |
| 
 | |
|             if (sq_IsIntersectRect(IMouse.GetXPos(), IMouse.GetYPos(), 1, 1, X + value.x + Info[Page].Xp, Y + value.y + Info[Page].Yp + PageScrollPos, 29, 29)) {
 | |
|                 HoverItem = value;
 | |
|             }
 | |
|         }
 | |
|         releaseClip(); //裁切结束
 | |
|     }
 | |
| 
 | |
| 
 | |
|     function TopShow(obj) {
 | |
|         if (!Info) return;
 | |
|         if (sq_IsIntersectRect(IMouse.GetXPos(), IMouse.GetYPos(), 1, 1, X + 86, Y + 53, 272, 15)) {
 | |
|             local StrArr = Info[Page].attS;
 | |
|             local Str = Info[Page].AttsS;
 | |
|             L_sq_DrawWindow(IMouse.GetXPos() - 140 + LenheartTextClass.GetStringLength(Str) / 2, IMouse.GetYPos() - 36, 0 + LenheartTextClass.GetStringLength(Str), 0 + (14 * StrArr.len()), "interface/lenheartwindowcommon.img", 97, 11, 12, 11, 13);
 | |
| 
 | |
|             local Xpos = LenheartTextClass.GetStringLength(Str) / 2;
 | |
|             foreach(Pos, realStr in StrArr) {
 | |
|                 L_sq_DrawCode(realStr, IMouse.GetXPos() - 126 + Xpos, IMouse.GetYPos() - 24 + (Pos * 14), 0xFFFFFFFF, 1, 1);
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| 
 | |
| 
 | |
|     //override
 | |
|     function DrawItemInfo() {
 | |
|         if (MousePosFlag != 2) return;
 | |
|         if (ItemInfoDrawS) {
 | |
|             if (!ItemObject) {
 | |
|                 local ItemId = ItemInfoDrawS.ItemId;
 | |
|                 if (Rindro_ItemInfoObject.rawin(ItemId)) {
 | |
|                     ItemObject = ItemInfoClass(Rindro_ItemInfoObject[ItemId]);
 | |
|                 }
 | |
|             }
 | |
|             ItemObject.Show(ItemInfoDrawS.X, ItemInfoDrawS.Y - ItemObject.PageLength);
 | |
|         } else {
 | |
|             ItemObject = null;
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     function Show(obj) {
 | |
|         DrawMain(obj);
 | |
|         LenheartNewUI_Windows.Show(obj);
 | |
|     }
 | |
| 
 | |
|     //逻辑入口
 | |
|     function Proc(obj) {
 | |
|         LenheartNewUI_Windows.SyncPos(X, Y);
 | |
| 
 | |
| 
 | |
|     }
 | |
| 
 | |
|     //鼠标位置Flag
 | |
|     MousePosFlag = 0;
 | |
| 
 | |
|     //override
 | |
|     function OnMouseProc(Flag, MousePos_X, MousePos_Y) {
 | |
|         //调用原生方法
 | |
|         LenheartNewUI_Windows.OnMouseProc(Flag, MousePos_X, MousePos_Y);
 | |
| 
 | |
|         MousePos_X -= X;
 | |
|         MousePos_Y -= Y;
 | |
|         //鼠标在栏目窗口内
 | |
|         if (MousePos_X >= 8 && MousePos_Y >= 95 && MousePos_X <= 110 && MousePos_Y <= 375) {
 | |
|             MousePosFlag = 1;
 | |
|         }
 | |
|         //鼠标在宝珠窗口内
 | |
|         else if (MousePos_X > 95 && MousePos_Y >= 95 && MousePos_X <= 348 && MousePos_Y <= 375) {
 | |
|             MousePosFlag = 2;
 | |
|         } else MousePosFlag = 0;
 | |
|     }
 | |
| 
 | |
|     //override
 | |
|     //鼠标滚轮事件回调
 | |
|     function OnMouseWheel(Flag, MousePos_X, MousePos_Y) {
 | |
|         MousePos_X -= X;
 | |
|         MousePos_Y -= Y;
 | |
| 
 | |
|         //左侧栏目的滚动逻辑
 | |
|         if (MousePosFlag == 1) {
 | |
|             if (Flag) {
 | |
|                 if (ScrollPos > 0) ScrollPos -= 1;
 | |
|             }
 | |
|             if (!Flag) {
 | |
|                 if (ScrollPos<(Info.len() - 4)) ScrollPos += 1;
 | |
|             }
 | |
|         }
 | |
|         //左侧栏目的滚动逻辑
 | |
|         if (MousePosFlag == 2) {
 | |
|             if (Flag) {
 | |
|                 if (PageScrollPos< 0) PageScrollPos += 47;
 | |
|             }
 | |
|             if (!Flag) {
 | |
|                 if (PageScrollPos > (0 - Info[Page].gl)) PageScrollPos -= 47;
 | |
|             }
 | |
|         }
 | |
| 
 | |
| 
 | |
|         //调用原生方法
 | |
|         LenheartNewUI_Windows.OnMouseWheel(Flag, MousePos_X, MousePos_Y);
 | |
|     }
 | |
| 
 | |
| 
 | |
|     //override
 | |
|     //鼠标左键弹起回调
 | |
|     function OnMouseLbUp(MousePos_X, MousePos_Y) {
 | |
|         //调用原生方法
 | |
|         LenheartNewUI_Windows.OnMouseLbUp(MousePos_X, MousePos_Y);
 | |
| 
 | |
|         if (HoverItem) {
 | |
|             local RealOp = 20077005;
 | |
|             if (HoverItem.isTure) RealOp = 20077009;
 | |
|             local T = {
 | |
|                 op = RealOp,
 | |
|                 boxId = Info[Page].id,
 | |
|                 itemId = HoverItem.id
 | |
|             }
 | |
|             SendPackEx(T);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     function OpenCallBack() {
 | |
|         GetCollectInfo();
 | |
|         this.Visible = true;
 | |
|         ResetFocus();
 | |
|     }
 | |
| 
 | |
| }
 | |
| getroottable().rawdelete("CollectionBox_Obj");
 | |
| 
 | |
| function Lenheart_CollectionBox_Fun(obj) {
 | |
|     local RootTab = getroottable();
 | |
|     if (!RootTab.rawin("CollectionBox_Obj")) {
 | |
|         RootTab.rawset("CollectionBox_Obj", true);
 | |
|         local Winobj = LenheartNewUI_CreateWindow(CollectionBoxC, "收集箱窗口", ((getroottable().Rindro_Scr_Width - 376) / 2).tointeger(), 64, 376, 384, 28);
 | |
| 
 | |
|         EventList_Obj.AddEvent("收集箱", 73, Winobj, "interface2/hud/information_button/information_button_cn.img");
 | |
|     }
 | |
| }
 | |
| 
 | |
| getroottable()["LenheartFuncTab"].rawset("CollectionBoxFuncN", Lenheart_CollectionBox_Fun); |