182 lines
5.8 KiB
Plaintext
182 lines
5.8 KiB
Plaintext
/*
|
|
文件名:EventShop.nut
|
|
路径:Project/EventShop/EventShop.nut
|
|
创建日期:2025-01-11 13:59
|
|
文件用途:活动商店
|
|
*/
|
|
class EventShopC extends LenheartNewUI_Windows {
|
|
//调试模式
|
|
// DeBugMode = true;
|
|
|
|
//不是窗口
|
|
// NoWindow = true;
|
|
|
|
//是否可见
|
|
Visible = false;
|
|
|
|
//商品列表
|
|
GoodsList = null;
|
|
//当前商店归属NPC
|
|
NPC_Index = -1;
|
|
//活动币数量
|
|
ActivityCoin = 99999;
|
|
|
|
WindowImg = Rindro_Image("eventshop/main.img");
|
|
|
|
//配置包
|
|
function BaseConfig(Chunk) {
|
|
local Jso = Json.Decode(Chunk);
|
|
//注册NPC功能
|
|
RegisterNpc(Jso.npc);
|
|
foreach(npc_id in Jso.npc) {
|
|
RegisterNpc(npc_id);
|
|
}
|
|
}
|
|
|
|
//请求商品列表
|
|
function RequestGoodsList(Index) {
|
|
local T = {
|
|
op = 20088001,
|
|
npc = Index
|
|
}
|
|
SendPackEx(T);
|
|
}
|
|
|
|
//请求商品列表回调
|
|
function RequestGoodsListCallBack(Chunk) {
|
|
local Jso = Json.Decode(Chunk);
|
|
GoodsList = Jso.itemShops;
|
|
ActivityCoin = Jso.count;
|
|
NPC_Index = Jso.npc;
|
|
//初始化商店
|
|
InitGoodsList();
|
|
}
|
|
|
|
constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH) {
|
|
Childrens = [];
|
|
//注册控件
|
|
RegisterWidget();
|
|
|
|
LenheartNewUI_Windows.constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH);
|
|
|
|
Pack_Control.rawset(20088004, BaseConfig.bindenv(this));
|
|
Pack_Control.rawset(20088002, RequestGoodsListCallBack.bindenv(this));
|
|
|
|
RequestGoodsList(2);
|
|
}
|
|
|
|
function RegisterNpc(id) {
|
|
local EachManager = getroottable()["L_Each_Obj"];
|
|
//先清空注册
|
|
EachManager.RemoveEachForNpc(id);
|
|
|
|
EachManager.AddEachForNpc(id, function(SThis) {
|
|
//关闭按钮
|
|
local ApplyEngagementButton = LenheartNewUI_Each_BaseButton(0, 0, 100, 21, "interface2/popup_menu/popup_back.img", 3);
|
|
ApplyEngagementButton.Icon = "interface2/popup_menu/popup_icon_cn.img";
|
|
ApplyEngagementButton.IconIdx = 7;
|
|
ApplyEngagementButton.Str = "活动商店";
|
|
ApplyEngagementButton.OnClick = function(Button) {
|
|
Button.Parent.CloseAllEach();
|
|
Button.Parent.CloseWindow();
|
|
RequestGoodsList(Button.Parent.NPC_Index);
|
|
Visible = true;
|
|
ResetFocus();
|
|
}.bindenv(this);
|
|
ApplyEngagementButton.SetCallBackFunc(function(Button) {})
|
|
SThis.AddChild(ApplyEngagementButton);
|
|
}.bindenv(this));
|
|
}
|
|
|
|
function RegisterWidget() {
|
|
// //关闭按钮
|
|
// local CloseButton = LenheartNewUI_BaseButton(278, 0, 11, 12, "interface/lenheartwindowcommon.img", 276);
|
|
// CloseButton.OnClick = function() {
|
|
// this.Visible = false;
|
|
// }.bindenv(this);
|
|
// Childrens.append(CloseButton);
|
|
|
|
}
|
|
|
|
//初始化商店
|
|
function InitGoodsList() {
|
|
|
|
}
|
|
|
|
//绘制项目
|
|
function DrawItemCur(Object, XPos, Ypos) {
|
|
DrawItemBase(XPos, Ypos, Object.itemId, Object.num);
|
|
if (sq_IsIntersectRect(IMouse.GetXPos(), IMouse.GetYPos(), 1, 1, XPos, Ypos, 24, 24)) {
|
|
WindowImg.DrawPng(1, XPos, Ypos);
|
|
L_sq_DrawCode("所需活动币: " + Object.reItemNum, X + 26, Y + 288, sq_RGBA(189, 159, 126, 255), 0, 1);
|
|
if (MouseClickFlag) {
|
|
local T = {
|
|
op = 20088005,
|
|
npc = NPC_Index,
|
|
itemId = Object.itemId,
|
|
itemNum = 1
|
|
}
|
|
SendPackEx(T);
|
|
}
|
|
} else {
|
|
// if (Info.vis) {
|
|
// //关闭道具信息窗口
|
|
// L_Sq_CallFunc(0xE6B2B0, "int", FFI_THISCALL, ["int", "int", "int", "char"], 0x1ADE090, 0x113, 0xFFFFFFFF, 0x0);
|
|
// Info.vis = false;
|
|
// DrawItemCurObject = null;
|
|
// }
|
|
}
|
|
}
|
|
|
|
MouseClickFlag = false;
|
|
//鼠标左键弹起回调
|
|
function OnMouseLbUp(MousePos_X, MousePos_Y) {
|
|
MouseClickFlag = true;
|
|
LenheartNewUI_Windows.OnMouseLbUp(MousePos_X, MousePos_Y);
|
|
}
|
|
|
|
//绘制主界面
|
|
function DrawMain(obj) {
|
|
if (!GoodsList) return;
|
|
WindowImg.DrawPng(0, X + 0, Y + 0);
|
|
|
|
foreach(Pos, Object in GoodsList) {
|
|
DrawItemCur(Object, X + 24 + ((Pos % 7) * 30), Y + 64 + ((Pos / 7) * 30));
|
|
}
|
|
|
|
//绘制活动币数量
|
|
L_sq_DrawCode(ActivityCoin.tostring(), X + 188 - LenheartTextClass.GetStringLength(ActivityCoin.tostring()) / 2, Y + 288, sq_RGBA(189, 159, 126, 255), 0, 1);
|
|
if (sq_IsIntersectRect(IMouse.GetXPos(), IMouse.GetYPos(), 1, 1, X + 124, Y + 284, 21, 21)) {
|
|
L_sq_DrawWindow(X + 40, Y - 100 + 350, 224, 30, "interface/lenheartwindowcommon.img", 97, 11, 12, 11, 13);
|
|
local QuestTipsStr = "拥有的活动币数量,活动币可在游戏中获得,请留意有以内的各种玩法!";
|
|
local QuestTipsArray = L_sq_GetStringDrawArray(QuestTipsStr, 251);
|
|
foreach(Pos, va in QuestTipsArray) {
|
|
// Sout("文本内容嗯: %L", va);
|
|
L_sq_DrawCode(va, X + 40 + 7, Y - 100 + 7 + 350 + (Pos * 16), 0xFFFFFFFF, 1, 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
function Show(obj) {
|
|
DrawMain(obj);
|
|
LenheartNewUI_Windows.Show(obj);
|
|
MouseClickFlag = false;
|
|
}
|
|
|
|
//逻辑入口
|
|
function Proc(obj) {
|
|
LenheartNewUI_Windows.SyncPos(X, Y);
|
|
}
|
|
|
|
}
|
|
getroottable().rawdelete("EventShop_Obj");
|
|
|
|
function Lenheart_EventShop_Fun(obj) {
|
|
local RootTab = getroottable();
|
|
if (!RootTab.rawin("EventShop_Obj")) {
|
|
RootTab.rawset("EventShop_Obj", true);
|
|
LenheartNewUI_CreateWindow(EventShopC, "活动商店窗口", 60, 120, 260, 318, 32);
|
|
}
|
|
}
|
|
|
|
getroottable()["LenheartFuncTab"].rawset("EventShopFuncN", Lenheart_EventShop_Fun); |