208 lines
5.9 KiB
Plaintext
208 lines
5.9 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;
|
|
|
|
|
|
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;
|
|
|
|
//
|
|
|
|
//基础配置包
|
|
function GetInfoCallBack(Chunk) {
|
|
Info = Json.Decode(Chunk).info;
|
|
foreach(Key, Aobj in Info) {
|
|
if (!Page) Page = Key;
|
|
local StrBuf1 = L_sq_GetStringDrawArray(Aobj.attribute.Atts, 300);
|
|
Aobj.attribute.AttsS <- StrBuf1[0] + "...";
|
|
Aobj.attribute.Atts <- StrBuf1;
|
|
}
|
|
|
|
InitBoxButton();
|
|
}
|
|
|
|
//获取收集信息
|
|
function GetCollectInfo() {
|
|
local T = {
|
|
op = 20077003
|
|
};
|
|
SendPackEx(T);
|
|
}
|
|
//收集箱收集信息
|
|
function GetCollectInfoCallBack(Chunk) {
|
|
|
|
// Info = Json.Decode(Chunk).info;
|
|
}
|
|
|
|
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(20077004, GetCollectInfoCallBack.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.OnClick = function(ButtonObj) {
|
|
Page = ButtonObj.SetFlag;
|
|
}.bindenv(this);
|
|
ButtonBuf.SetCallBackFunc(function(ButtonObj) {
|
|
|
|
});
|
|
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(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].attribute.AttsS, X + 228 - LenheartTextClass.GetStringLength(Info[Page].attribute.AttsS) / 2, Y + 40 + 20, sq_RGBA(255, 242, 0, 250), 0, 1);
|
|
}
|
|
|
|
|
|
function TopShow(obj) {
|
|
if (sq_IsIntersectRect(IMouse.GetXPos(), IMouse.GetYPos(), 1, 1, X + 86, Y + 53, 272, 15)) {
|
|
local StrArr = Info[Page].attribute.Atts;
|
|
local Str = Info[Page].attribute.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);
|
|
}
|
|
}
|
|
}
|
|
|
|
function Show(obj) {
|
|
DrawMain(obj);
|
|
LenheartNewUI_Windows.Show(obj);
|
|
}
|
|
|
|
//逻辑入口
|
|
function Proc(obj) {
|
|
LenheartNewUI_Windows.SyncPos(X, Y);
|
|
}
|
|
|
|
}
|
|
getroottable().rawdelete("CollectionBox_Obj");
|
|
|
|
function Lenheart_CollectionBox_Fun(obj) {
|
|
local RootTab = getroottable();
|
|
if (!RootTab.rawin("CollectionBox_Obj")) {
|
|
RootTab.rawset("CollectionBox_Obj", true);
|
|
LenheartNewUI_CreateWindow(CollectionBoxC, "收集箱", ((getroottable().Rindro_Scr_Width - 376) / 2).tointeger(), 64, 376, 384, 28);
|
|
}
|
|
}
|
|
|
|
getroottable()["LenheartFuncTab"].rawset("CollectionBoxFuncN", Lenheart_CollectionBox_Fun); |