283 lines
8.8 KiB
Plaintext
283 lines
8.8 KiB
Plaintext
/*
|
||
文件名:CumulativeReward.nut
|
||
路径:Project/CumulativeReward/CumulativeReward.nut
|
||
创建日期:2025-10-05 20:49
|
||
文件用途: 累计奖励
|
||
*/
|
||
class CumulativeRewardC extends LenheartNewUI_Windows {
|
||
//调试模式
|
||
// DeBugMode = true;
|
||
|
||
//不是窗口
|
||
NoWindow = true;
|
||
|
||
|
||
//下一奖励道具
|
||
NextRewardItem = 3037;
|
||
//当前阶段
|
||
CurrentStage = 1;
|
||
//当前阶段已过时间
|
||
CurrentStageTime = 0;
|
||
//下一阶段所需时间
|
||
NextStageTime = 0;
|
||
//总累计次数
|
||
TotalCount = null;
|
||
//当前累计次数
|
||
CurrentCount = 0;
|
||
//奖励道具信息(数组)
|
||
/*对象结构体
|
||
{
|
||
id = 3037,(编号)
|
||
count = 1,(数量)
|
||
state = 0,(0未达到要求,1达到要求未领取,2已领取)
|
||
}
|
||
*/
|
||
RewardItemInfo = null;
|
||
|
||
//领取按钮List
|
||
RewardButtonList = null;
|
||
|
||
//收包记录时间
|
||
RecvPackTime = 0;
|
||
|
||
//下方界面是否打开Flag
|
||
IsOpen = false;
|
||
|
||
|
||
Img1 = null;
|
||
|
||
//请求配置的Flag
|
||
RequestConfig = false;
|
||
|
||
//全部完成的Flag
|
||
AllFinish = false;
|
||
|
||
|
||
function CheckTimePack() {
|
||
SendPackEx({
|
||
op = 20097001,
|
||
});
|
||
}
|
||
|
||
function CheckConfigPack() {
|
||
SendPackEx({
|
||
op = 20097005,
|
||
});
|
||
}
|
||
|
||
//是否可见
|
||
// Visible = false;
|
||
constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH) {
|
||
Childrens = [];
|
||
RewardButtonList = [];
|
||
//注册控件
|
||
RegisterWidget();
|
||
|
||
LenheartNewUI_Windows.constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH);
|
||
|
||
//配置回包
|
||
RegisterPack(20097004, function(Chunk) {
|
||
local Jso = Json.Decode(Chunk);
|
||
this.X = Jso.X;
|
||
this.Y = Jso.Y;
|
||
TotalCount = Jso.TotalCount;
|
||
CurrentCount = Jso.currentCount;
|
||
RewardItemInfo = Jso.RewardItemInfo;
|
||
foreach(button in RewardButtonList) {
|
||
RemoveChild(button.ObjectId);
|
||
}
|
||
RewardButtonList = [];
|
||
foreach(pos, value in RewardItemInfo) {
|
||
local ButtonBuf = LenheartNewUI_BaseButton(12 + (pos % 4) * 52, 109 + (pos / 4) * 104, 28, 18, "interface2/event/chn_event_2018/180619_honey_time/main.img", 6);
|
||
ButtonBuf.Data = pos;
|
||
ButtonBuf.OnClickEx = function(button) {
|
||
SendPackEx({
|
||
op = 20097003,
|
||
id = button.Data
|
||
});
|
||
}.bindenv(this);
|
||
ButtonBuf.SetCallBackFunc(function(button) {
|
||
if (!IsOpen) button.Visible = false;
|
||
else button.Visible = true;
|
||
}.bindenv(this));
|
||
AddChild(ButtonBuf);
|
||
RewardButtonList.append(ButtonBuf);
|
||
if (value.start == 0 || value.start == 2) ButtonBuf.State = 8;
|
||
}
|
||
RequestConfig = false;
|
||
}.bindenv(this));
|
||
//时间回包
|
||
RegisterPack(20097002, function(Chunk) {
|
||
local Jso = Json.Decode(Chunk);
|
||
local Arr = Jso.info;
|
||
NextRewardItem = Arr[0];
|
||
CurrentStage = Arr[1];
|
||
if (CurrentStage >= 3) {
|
||
CurrentStage = 3;
|
||
AllFinish = true;
|
||
}
|
||
CurrentStageTime = Arr[2];
|
||
NextStageTime = Arr[3];
|
||
RecvPackTime = Clock();
|
||
}.bindenv(this));
|
||
|
||
|
||
CheckTimePack();
|
||
|
||
Img1 = Rindro_Image("interface2/event/chn_event_2018/180619_honey_time/main.img");
|
||
}
|
||
|
||
function RegisterWidget() {
|
||
|
||
|
||
}
|
||
|
||
//绘制主界面
|
||
function DrawMain(obj) {
|
||
//绘制进度条底槽
|
||
Img1.DrawPng(20, X + 33, Y + 20);
|
||
//计算百分比
|
||
if (RecvPackTime != 0) {
|
||
local TimePercentage = (CurrentStageTime.tofloat() + ((Clock() - RecvPackTime).tofloat())) / NextStageTime.tofloat();
|
||
|
||
if (TimePercentage > 1.0) {
|
||
TimePercentage = 1.0;
|
||
if (!RequestConfig && !AllFinish) {
|
||
CheckTimePack();
|
||
CheckConfigPack();
|
||
RequestConfig = true;
|
||
}
|
||
}
|
||
|
||
setClip(X + 36, Y + 24, X + 36 + (101.0 * TimePercentage).tointeger(), Y + 24 + 6); //开始裁切
|
||
//绘制进度条
|
||
Img1.DrawPng(21, X + 36, Y + 24);
|
||
releaseClip(); //裁切结束
|
||
}
|
||
|
||
//绘制下一奖励道具
|
||
DrawItemBase(X + 6, Y + 6, NextRewardItem, 1);
|
||
//绘制盖子
|
||
Img1.DrawPng(19, X, Y);
|
||
//绘制阶段文字
|
||
Img1.DrawExPng(25 + CurrentStage, X + 46, Y + 3, 0, sq_RGBA(255, 255, 255, 250), 0.85, 0.85);
|
||
|
||
|
||
if (IsOpen) {
|
||
if (CurrentStage != null) {
|
||
local StageText = "累计在线得好礼 (" + (CurrentStage + 1) + "/4 阶段)";
|
||
L_sq_DrawCode(StageText, X + 6, Y + 42, sq_RGBA(255, 177, 0, 255), 1, 1);
|
||
if (AllFinish) {
|
||
local Str = "今天的累计在线活动已完成!";
|
||
L_sq_DrawCode(Str, X + 6, Y + 61, sq_RGBA(150, 150, 150, 255), 1, 1);
|
||
}else{
|
||
local Second = ((NextStageTime - (CurrentStageTime + ((Clock() - RecvPackTime)))) / 1000);
|
||
local SecondStr = Second % 60;
|
||
local Minute = (Second - SecondStr) / 60;
|
||
local Str = "距离下一阶段还有 " + (Minute> 0 ? Minute.tostring() + " 分 " : "") + SecondStr.tostring() + " 秒";
|
||
L_sq_DrawCode(Str, X + 6, Y + 61, sq_RGBA(150, 150, 150, 255), 1, 1);
|
||
}
|
||
}
|
||
|
||
if (TotalCount) {
|
||
local IntroductionText = "满阶段在线" + TotalCount[TotalCount.len() - 1] + "次获得丰厚好礼!";
|
||
L_sq_DrawCode(IntroductionText, X + 6, Y + 146, sq_RGBA(255, 177, 0, 255), 1, 1);
|
||
local CurCount = "累计次数 [" + CurrentCount.tostring() + "/" + TotalCount[TotalCount.len() - 1].tostring() + "]";
|
||
L_sq_DrawCode(CurCount, X + 6, Y + 166, sq_RGBA(104, 213, 237, 255), 1, 1);
|
||
}
|
||
|
||
//绘制所有奖励道具
|
||
if (RewardItemInfo) {
|
||
foreach(pos, value in RewardItemInfo) {
|
||
DrawItemBase(X + 12 + (pos % 4) * 52, Y + 80 + (pos / 4) * 104, value.id, value.count);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
EffectFlag = false;
|
||
EffectTime = 0;
|
||
|
||
function TopShow(obj) {
|
||
if (!IsOpen) return;
|
||
if (EffectTime == 0) EffectTime = Clock();
|
||
local A = 60;
|
||
if (!EffectFlag) {
|
||
A = sq_GetUniformVelocity(60, 255, Clock() - EffectTime, 600);
|
||
if (A >= 255) {
|
||
EffectFlag = true;
|
||
EffectTime = Clock();
|
||
}
|
||
} else {
|
||
A = sq_GetUniformVelocity(255, 60, Clock() - EffectTime, 600);
|
||
if (A <= 60) {
|
||
EffectFlag = false;
|
||
EffectTime = Clock();
|
||
}
|
||
}
|
||
//绘制完成
|
||
if (RewardItemInfo) {
|
||
foreach(pos, value in RewardItemInfo) {
|
||
if (value.start == 1) {
|
||
L_sq_SetDrawImgModel(2, 0);
|
||
Img1.DrawExPng(10, X + 4 + (pos % 4) * 52, Y + 102 + (pos / 4) * 104, 0, sq_RGBA(255, 255, 255, A), 1.0, 1.0);
|
||
L_sq_ReleaseDrawImgModel();
|
||
} else if (value.start == 2) Img1.DrawPng(24, X + 12 + (pos % 4) * 52, Y + 110 + (pos / 4) * 104);
|
||
}
|
||
}
|
||
}
|
||
|
||
function Show(obj) {
|
||
LenheartNewUI_Windows.Show(obj);
|
||
DrawMain(obj);
|
||
}
|
||
|
||
//鼠标事件回调
|
||
function OnMouseProc(Flag, MousePos_X, MousePos_Y) {
|
||
if (sq_IsIntersectRect(MousePos_X, MousePos_Y, 1, 1, X, Y, Width, Height)) {
|
||
IsOpen = true;
|
||
} else {
|
||
IsOpen = false;
|
||
}
|
||
}
|
||
|
||
|
||
//心跳时间
|
||
HeartTime = 0;
|
||
|
||
//逻辑入口
|
||
function Proc(obj) {
|
||
LenheartNewUI_Windows.SyncPos(X, Y);
|
||
|
||
if (IsOpen) {
|
||
Img1.DrawPng(18, X, Y + 38);
|
||
Width = 206
|
||
Height = 266;
|
||
} else {
|
||
Width = 144
|
||
Height = 40;
|
||
}
|
||
|
||
if (Clock() - HeartTime > 30000) {
|
||
CheckTimePack();
|
||
HeartTime = Clock();
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
|
||
L_Windows_List <- [];
|
||
getroottable().rawdelete("LenheartPluginsInitFlag");
|
||
getroottable().rawdelete("EventList_Obj")
|
||
getroottable().rawdelete("CumulativeReward_Obj");
|
||
|
||
function Lenheart_CumulativeReward_Fun(obj) {
|
||
local RootTab = getroottable();
|
||
if (!RootTab.rawin("CumulativeReward_Obj")) {
|
||
RootTab.rawset("CumulativeReward_Obj", true);
|
||
LenheartNewUI_CreateWindow(CumulativeRewardC, "累计奖励窗口", ((getroottable().Rindro_Scr_Width - 405) / 2).tointeger(), 64, 405, 372, 0);
|
||
}
|
||
}
|
||
|
||
getroottable()["LenheartFuncTab"].rawset("CumulativeRewardFuncN", Lenheart_CumulativeReward_Fun); |