300 lines
		
	
	
		
			9.4 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
			
		
		
	
	
			300 lines
		
	
	
		
			9.4 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
| /*
 | |
| 文件名:OnilneSign.nut
 | |
| 路径:Project/OnilneSign/OnilneSign.nut
 | |
| 创建日期:2024-08-10	13:27
 | |
| 文件用途:在线签到
 | |
| */
 | |
| 
 | |
| 
 | |
| class OnilneSignC_ButtonText extends LenheartNewUI_Button {
 | |
|     TextStr = null;
 | |
|     TextX = null;
 | |
|     TextY = null;
 | |
|     TextColor = null;
 | |
|     TextRColor = null;
 | |
| 
 | |
|     TextXoffset = null;
 | |
|     TextYoffset = null;
 | |
| 
 | |
|     Id = null;
 | |
| 
 | |
| 
 | |
|     constructor(X, Y, W, Str) {
 | |
|         LenheartNewUI_Button.constructor(X, Y, W);
 | |
|         this.TextStr = Str;
 | |
|         TextColor = sq_RGBA(185, 148, 96, 255);
 | |
|         TextRColor = sq_RGBA(227, 212, 154, 255);
 | |
| 
 | |
|         TextXoffset = 19;
 | |
|         TextYoffset = 3;
 | |
|     }
 | |
| 
 | |
|     function SetTextColor(RGBA) {
 | |
|         TextColor = RGBA;
 | |
|     }
 | |
| 
 | |
|     function SetTextOffset(gX, gY) {
 | |
|         TextXoffset = gX;
 | |
|         TextYoffset = gY;
 | |
|     }
 | |
| 
 | |
|     function Show(obj) {
 | |
|         LenheartNewUI_Button.Show(obj);
 | |
|         local Color = TextColor;
 | |
|         local SY = Y + TextYoffset;
 | |
|         if (State != 8) {
 | |
|             if (isLBDown) {
 | |
|                 SY = Y + TextYoffset + 1;
 | |
|             }
 | |
|             if (isInRect || State == 1) {
 | |
|                 Color = TextRColor;
 | |
|             }
 | |
|         }
 | |
|         L_sq_DrawCode(TextStr, X + TextXoffset + 19, SY + 5, Color, 0, 1);
 | |
|     }
 | |
| 
 | |
|     //鼠标左键弹起回调 overr
 | |
|     function OnMouseLbUp(MousePos_X, MousePos_Y) {
 | |
|         if (isLBDown && OnClick) {
 | |
|             local obj = sq_getMyCharacter();
 | |
|             obj.sq_PlaySound("CLICK_BUTTON1");
 | |
|             OnClick(Id);
 | |
|         }
 | |
|         isLBDown = false;
 | |
|     }
 | |
| }
 | |
| 
 | |
| 
 | |
| class OnilneSignC extends LenheartNewUI_Windows {
 | |
|     //调试模式
 | |
|     // DeBugMode = true;
 | |
| 
 | |
|     //不是窗口
 | |
|     // NoWindow = true;
 | |
| 
 | |
|     //是否可见
 | |
|     Visible = false;
 | |
| 
 | |
|     //在线时间
 | |
|     OnlineTime = 0;
 | |
|     //在线天数
 | |
|     OnlineDay = 0;
 | |
|     //是否可领取的数组
 | |
|     Reward1Flag = null;
 | |
|     //是否可领取的数组
 | |
|     Reward2Flag = null;
 | |
| 
 | |
|     Config = null;
 | |
|     Info = null;
 | |
|     PackTime = 0;
 | |
| 
 | |
|     function GetConfigCallBack(Chunk) {
 | |
|         local Jso = Json.Decode(Chunk);
 | |
|         Config = Jso;
 | |
|     }
 | |
| 
 | |
|     function GetMyInfoCallBack(Chunk) {
 | |
|         local Jso = Json.Decode(Chunk);
 | |
|         Info = Jso.info;
 | |
|         OnlineDay = Info.RewardDayCountl;
 | |
|         for (local i = 0; i< 10; i++) {
 | |
|             Reward1Flag[i] = Info.reward.slice(0 + i, 1 + i).tointeger();
 | |
|             Reward2Flag[i] = Info.reward2.slice(0 + i, 1 + i).tointeger();
 | |
|         }
 | |
|         PackTime = Clock();
 | |
|     }
 | |
| 
 | |
|     //获取信息
 | |
|     function GetInfo() {
 | |
|         local T = {
 | |
|             op = 20065001
 | |
|         }
 | |
|         SendPackEx(T);
 | |
|     }
 | |
| 
 | |
|     constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH) {
 | |
|         Childrens = [];
 | |
|         Reward1Flag = array(10, false);
 | |
|         Reward2Flag = array(10, false);
 | |
|         //注册控件
 | |
|         RegisterWidget();
 | |
| 
 | |
|         LenheartNewUI_Windows.constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH);
 | |
| 
 | |
|         Pack_Control.rawset(20065004, GetConfigCallBack.bindenv(this));
 | |
|         Pack_Control.rawset(20065002, GetMyInfoCallBack.bindenv(this));
 | |
| 
 | |
| 
 | |
|         GetInfo();
 | |
|     }
 | |
| 
 | |
|     function RegisterWidget() {
 | |
|         //关闭按钮
 | |
|         local CloseButton = LenheartNewUI_BaseButton(580, 2, 11, 12, "interface/lenheartwindowcommon.img", 276);
 | |
|         CloseButton.OnClick = function() {
 | |
|             this.Visible = false;
 | |
|         }.bindenv(this);
 | |
|         Childrens.append(CloseButton);
 | |
| 
 | |
| 
 | |
|         for (local i = 0; i< 10; i++) {
 | |
|             local PostButton = OnilneSignC_ButtonText(21 + (i * 56), 114, 5, "领取");
 | |
|             PostButton.DWidth = -5;
 | |
|             PostButton.Width = 50;
 | |
|             PostButton.SetTextOffset(-4, 1);
 | |
|             PostButton.Id = i;
 | |
|             PostButton.OnClick = function(Id) {
 | |
|                 local Jso = {
 | |
|                     op = 20065003,
 | |
|                     id = Id,
 | |
|                 }
 | |
|                 SendPackEx(Jso);
 | |
|             }.bindenv(this);
 | |
|             PostButton.SetCallBackFunc(function(Window) {
 | |
|                 if (!Config) return;
 | |
|                 local MySuccessTime = Config.config[Window.Id].time;
 | |
|                 if (OnlineTime >= MySuccessTime && Reward1Flag[Window.Id] == 0) {
 | |
|                     Window.State = 0;
 | |
|                     Window.TextStr = "领取";
 | |
|                     Window.SetTextOffset(-4, 1);
 | |
|                 } else {
 | |
|                     Window.State = 8;
 | |
|                     Window.TextStr = (MySuccessTime - OnlineTime) + "秒";
 | |
|                     if (Reward1Flag[Window.Id] == 1) {
 | |
|                         Window.TextStr = "已领取";
 | |
|                         Window.SetTextOffset(-9, 1);
 | |
|                     }
 | |
|                 }
 | |
|             }.bindenv(this))
 | |
|             AddChild(PostButton);
 | |
| 
 | |
|             local PostButton2 = OnilneSignC_ButtonText(21 + (i * 56), 114 + 80, 5, "领取");
 | |
|             PostButton2.DWidth = -5;
 | |
|             PostButton2.Width = 50;
 | |
|             PostButton2.SetTextOffset(-4, 1);
 | |
|             PostButton2.Id = i + 10;
 | |
|             PostButton2.OnClick = function(Id) {
 | |
|                 local Jso = {
 | |
|                     op = 20065003,
 | |
|                     id = Id,
 | |
|                 }
 | |
|                 SendPackEx(Jso);
 | |
|             }.bindenv(this);
 | |
|             PostButton2.SetCallBackFunc(function(Window) {
 | |
|                 if (!Config) return;
 | |
|                 local MyCumulative = Config.config[Window.Id - 10].cumulative;
 | |
|                 if (OnlineDay >= MyCumulative && Reward2Flag[Window.Id - 10] == 0) {
 | |
|                     Window.State = 0;
 | |
|                     Window.TextStr = "领取";
 | |
|                     Window.SetTextOffset(-4, 1);
 | |
|                 } else {
 | |
|                     Window.State = 8;
 | |
|                     Window.TextStr = (MyCumulative - OnlineDay) + "天";
 | |
|                     if (Reward2Flag[Window.Id - 10] == 1) {
 | |
|                         Window.TextStr = "已领取";
 | |
|                         Window.SetTextOffset(-9, 1);
 | |
|                     }
 | |
|                 }
 | |
|             }.bindenv(this))
 | |
|             AddChild(PostButton2);
 | |
|         }
 | |
|     }
 | |
| 
 | |
| 
 | |
|     function InterpolateColor(rate) {
 | |
|         if (rate > 1.0) rate = 1.0;
 | |
|         // 起始颜色 (50, 255, 50)
 | |
|         local startColor = [50, 255, 50];
 | |
|         // 目标颜色 (255, 177, 0)
 | |
|         local endColor = [255, 177, 0];
 | |
| 
 | |
|         // 计算插值
 | |
|         local red = startColor[0] + ((endColor[0] - startColor[0]).tofloat() * (rate.tofloat() / 100.0)).tointeger();
 | |
|         local green = startColor[1] + ((endColor[1] - startColor[1]).tofloat() * (rate.tofloat() / 100.0)).tointeger();
 | |
|         local blue = startColor[2] + ((endColor[2] - startColor[2]).tofloat() * (rate.tofloat() / 100.0)).tointeger();
 | |
|         local alpha = 180; // 不透明度
 | |
| 
 | |
|         return sq_RGBA(red, green, blue, alpha); // 返回 RGBA
 | |
|     }
 | |
| 
 | |
| 
 | |
| 
 | |
|     //绘制主界面
 | |
|     function DrawMain(obj) {
 | |
|         if (!Config || !Info) return;
 | |
|         //绘制窗口底
 | |
|         L_sq_DrawWindow(X + 2, Y + 6, 580, 226, "interface/lenheartwindowcommon.img", 97, 11, 12, 11, 13);
 | |
|         L_sq_DrawWindow(X + 10, Y + 25, 584, 224, "interface/windowcommon.img", 204, 4, 14, 4, 14);
 | |
|         //绘制标题栏
 | |
|         L_sq_DrawImg("onlineevent/main.img", 0, X - 1, Y);
 | |
| 
 | |
|         OnlineTime = (Info.time + (Clock() - PackTime)) / 1000;
 | |
|         local hours = OnlineTime / 3600;
 | |
|         local minutes = (OnlineTime % 3600) / 60;
 | |
|         local secs = OnlineTime % 60;
 | |
|         local Str = "已在线时间: ";
 | |
| 
 | |
|         //绘制已在线时间
 | |
|         L_sq_DrawCode("已在线时间: " + (Info.time + (Clock() - PackTime)) / 1000 + "秒", X + 26, Y + 42, sq_RGBA(255, 177, 0, 250), 1, 1);
 | |
| 
 | |
|         //绘制距离下次奖励
 | |
|         L_sq_DrawCode("距离下次奖励", X + 150, Y + 42, sq_RGBA(255, 177, 0, 250), 1, 1);
 | |
|         //绘制实际进度
 | |
|         local rate = (Info.time + (Clock() - PackTime)).tofloat() / (NextRewardTime.tofloat() * 1000.0);
 | |
|         setClip(X + 240, Y + 41, X + 240 + (332.0 * rate).tointeger(), Y + 42 + 14);
 | |
|         local RGBA = InterpolateColor((rate * 100.0).tointeger());
 | |
|         L_sq_DrawImg("onlineevent/main.img", 2, X + 240, Y + 42, 1, RGBA, 1.0, 1.0);
 | |
|         releaseClip(); //裁切结束
 | |
|         //绘制进度条底框
 | |
|         L_sq_DrawImg("onlineevent/main.img", 1, X + 240, Y + 41);
 | |
| 
 | |
|         //绘制道具奖励
 | |
|         foreach(Pos, ItemObj in Config.config) {
 | |
|             if (OnlineTime <= ItemObj.time) NextRewardTime = ItemObj.time;
 | |
|             //绘制物品
 | |
|             DrawItemEx(X + 30 + (Pos * 56) + 3, Y + 80, ItemObj.itemId, ItemObj.itemNum);
 | |
|             //绘制物品2
 | |
|             DrawItemEx(X + 30 + (Pos * 56) + 3, Y + 160, ItemObj.cumulativeId, ItemObj.cumulativeNum);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     function Show(obj) {
 | |
|         DrawMain(obj);
 | |
|         LenheartNewUI_Windows.Show(obj);
 | |
|     }
 | |
| 
 | |
|     //心跳时间
 | |
|     HeartTime = 0;
 | |
| 
 | |
|     //下次奖励时间
 | |
|     NextRewardTime = 0;
 | |
|     //逻辑入口
 | |
|     function Proc(obj) {
 | |
|         LenheartNewUI_Windows.SyncPos(X, Y);
 | |
|         if (Clock() - HeartTime >= 10000) {
 | |
|             HeartTime = Clock();
 | |
|             local T = {
 | |
|                 op = 20065005
 | |
|             }
 | |
|             SendPackEx(T);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     function OpenCallBack() {
 | |
|         Visible = true;
 | |
|         ResetFocus();
 | |
|         GetInfo();
 | |
|     }
 | |
| }
 | |
| getroottable().rawdelete("OnilneSign_Obj");
 | |
| 
 | |
| function Lenheart_OnilneSign_Fun(obj) {
 | |
|     local RootTab = getroottable();
 | |
|     if (!RootTab.rawin("OnilneSign_Obj")) {
 | |
|         RootTab.rawset("OnilneSign_Obj", true);
 | |
|         local Win = LenheartNewUI_CreateWindow(OnilneSignC, "在线奖励窗口", ((getroottable().Rindro_Scr_Width - 600) / 2).tointeger(), 160, 600, 260, 22);
 | |
|         EventList_Obj.AddEvent("在线奖励", 28, Win);
 | |
|     }
 | |
| }
 | |
| 
 | |
| getroottable()["LenheartFuncTab"].rawset("OnilneSignFuncN", Lenheart_OnilneSign_Fun); |