Rindro-Sqr/Project/Achievement_New/Achievement_New.nut

760 lines
24 KiB
Plaintext

/*
文件名:Achievement.nut
路径:Project/Achievement/Achievement.nut
创建日期:2025-02-23 08:37
文件用途:成就系统
*/
//类型按钮
class Achievement_New_TypeButton extends LenheartNewUI_BaseButton {
function _typeof() {
return "Achievement_TypeButton";
}
State = 0;
BaseIdx = 29;
DWidth = null;
Path = null;
Idx = null;
Pos = 0;
isSelect = false;
//裁切位置
CutPosY_Start = null;
CutPosY_End = null;
constructor(W, H, Path, Idx, Pos, CYS, CYE) {
this.DWidth = W;
this.Path = Path;
this.Idx = Idx;
this.Pos = Pos;
this.CutPosY_Start = CYS;
this.CutPosY_End = CYE;
LenheartNewUI_CommonUi.constructor(0, 0, W, H);
}
function Show(obj) {
local MouseY = IMouse.GetYPos();
//按下
if (isLBDown) {
L_sq_DrawImg(Path, Idx, X, Y);
L_sq_DrawImg("achievement/buttoneffect.img", 0, X - 4, Y - 3);
}
//悬停
else if (isInRect && !isSelect) {
L_sq_DrawImg(Path, Idx, X, Y);
L_sq_DrawImg("achievement/buttoneffect.img", 1, X + 2, Y + 2);
}
//普通
else {
L_sq_DrawImg(Path, Idx, X, Y);
}
if (isSelect) {
L_sq_DrawImg("achievement/buttoneffect.img", 0, X - 4, Y - 3);
}
}
//鼠标事件回调
function OnMouseProc(Flag, MousePos_X, MousePos_Y) {
if (MousePos_Y< CutPosY_Start || MousePos_Y > (CutPosY_End)) {
isInRect = false;
return;
}
if (sq_IsIntersectRect(MousePos_X, MousePos_Y, 1, 1, X, Y, Width, Height)) isInRect = true;
else isInRect = false;
}
//鼠标左键按下回调
function OnMouseLbDown(MousePos_X, MousePos_Y) {
if (MousePos_Y< CutPosY_Start || MousePos_Y > (CutPosY_End)) return;
if (sq_IsIntersectRect(MousePos_X, MousePos_Y, 1, 1, X, Y, Width, Height)) {
isLBDown = true;
if (!OnClickSound) {
R_Utils.PlaySound("CLICK_BUTTON1");
} else {
R_Utils.PlaySound(OnClickSound);
}
}
}
}
//项目类完成按钮
class Achievement_New_ItemButton extends LenheartNewUI_ButtonText {
//裁切位置
CutPosY_Start = null;
CutPosY_End = null;
//鼠标事件回调
function OnMouseProc(Flag, MousePos_X, MousePos_Y) {
if (MousePos_Y< CutPosY_Start || MousePos_Y > (CutPosY_End)) {
isInRect = false;
return;
}
if (sq_IsIntersectRect(MousePos_X, MousePos_Y, 1, 1, X, Y, Width, Height)) isInRect = true;
else isInRect = false;
}
//鼠标左键按下回调
function OnMouseLbDown(MousePos_X, MousePos_Y) {
if (MousePos_Y< CutPosY_Start || MousePos_Y > (CutPosY_End)) return;
if (sq_IsIntersectRect(MousePos_X, MousePos_Y, 1, 1, X, Y, Width, Height)) {
isLBDown = true;
if (!OnClickSound) {
R_Utils.PlaySound("CLICK_BUTTON1");
} else {
R_Utils.PlaySound(OnClickSound);
}
}
}
}
//项目类
class AchievementNC_Item {
//Img
Img = null;
//编号
Idx = null;
//父对象
Parent = null;
//坐标
X = 0;
Y = 0;
Info = null;
SuccessButton = null;
constructor(Window, Idx, Info) {
Parent = Window;
Img = Window.Img["widget"];
this.Idx = Idx;
this.Info = Info;
//完成按钮
SuccessButton = Achievement_New_ItemButton(42 + 85 + 85, 420, 15, "完成");
SuccessButton.DWidth = -5;
SuccessButton.Width = 50;
SuccessButton.SetTextOffset(-4, 1);
SuccessButton.OnClick = function() {
Parent.SendPackEx({
op = 20093005,
cjid = Parent.CurrentTypePage,
id = this.Info.Id
});
}.bindenv(this);
SuccessButton.SetCallBackFunc(function(Button) {
Button.X = (X + 174).tointeger();
Button.Y = (Y + 30).tointeger();
Button.CutPosY_Start = Parent.Y + 110;
Button.CutPosY_End = Parent.Y + 496;
}.bindenv(this));
Parent.ItemButtonList.append(SuccessButton);
SetInfo(Info ? Info : {
Name = "测试的成就名称",
Desc = "0/100",
Explain = "默认描述",
Exp = sq_getRandom(1, 99).tostring(),
IsSuccess = 0
});
}
function SetInfo(Info) {
this.Info = Info;
if (this.Info.IsSuccess< 2) SuccessButton.State = 8;
}
function Show() {
//绘制底槽
Img.DrawPng(6, X, Y);
Img.DrawPng(6, X, Y);
//绘制旗帜
Img.DrawPng(7, X + 9, Y + 9);
//绘制经验值
L_sq_DrawCode(Info.Exp, X - LenheartTextClass.GetStringLength(Info.Exp) / 2 + 30, Y + 39, sq_RGBA(230, 200, 155, 255), 0, 1);
//绘制成就名称
L_sq_DrawCode(Info.Name, X + 60, Y + 12, sq_RGBA(230, 200, 155, 255), 0, 1);
//绘制成就描述
L_sq_DrawCode(Info.Desc, X + 60, Y + 30, sq_RGBA(174, 174, 174, 255), 0, 1);
}
function TopShow() {
if (IMouse.GetXPos() > X && IMouse.GetXPos()< X + 236 && IMouse.GetYPos() > Y && IMouse.GetYPos()< Y + 66) {
if (IMouse.GetYPos() >= Parent.Y + 110 && IMouse.GetYPos() <= Parent.Y + 496) {
L_sq_DrawWindow(X - 8, Y - 4 - 66, 236, 50, "interface/lenheartwindowcommon.img", 97, 11, 12, 11, 13);
//绘制成就描述
L_sq_DrawCode_Ex(Info.Explain, X, Y - 4 - 66 + 8, sq_RGBA(174, 174, 174, 255), 0, 1);
}
}
}
//高级绘制文字(带换行)
function L_sq_DrawCode_Ex(str, x, y, rgba, mb, jc) {
local strarr = [];
if (str.find("\\n") == null) L_sq_DrawCode(str, x, y, rgba, mb, jc);
else {
local Bpos = 0;
while (true) {
local Npos = str.find("\\n", Bpos);
if (!Npos) {
local strbuff = str.slice(Bpos, str.len());
strarr.append(strbuff);
break;
}
local strbuff = str.slice(Bpos, Npos);
strarr.append(strbuff);
Bpos = Npos + 2;
}
for (local z = 0; z< strarr.len(); z++) {
L_sq_DrawCode(strarr[z], x, y + (z * 14), rgba, mb, jc);
}
}
}
function Proc() {
X = (Parent.X + 235 + (Idx % 2 * 248)).tointeger();
Y = (Parent.Y - Parent.ItemScrollRate * Parent.ItemScrollValue + 121 + (Idx / 2 * 72)).tointeger();
}
}
//商品类
class AchievementNC_MerchandiseItem {
//Img
Img = null;
//UI
UI = Rindro_Image("interface/lenheartwindowcommon.img");
//编号
Idx = null;
//父对象
Parent = null;
//坐标
X = 0;
Y = 0;
Info = null;
BuyButton = null;
constructor(Window, Idx, Info) {
Parent = Window;
Img = Window.Img["widget"];
this.Idx = Idx;
this.Info = Info;
//购买按钮
BuyButton = Achievement_New_ItemButton(42 + 85 + 85, 420, 15, "购买");
BuyButton.DWidth = -5;
BuyButton.Width = 50;
BuyButton.SetTextOffset(-4, 1);
BuyButton.OnClick = function() {
Parent.SendPackEx({
op = 20093025,
itemPos = Idx
});
}.bindenv(this);
BuyButton.SetCallBackFunc(function(Button) {
Button.X = (X + 174).tointeger();
Button.Y = (Y + 30).tointeger();
Button.CutPosY_Start = Parent.Y + 110;
Button.CutPosY_End = Parent.Y + 496;
}.bindenv(this));
Parent.ItemButtonList.append(BuyButton);
SetInfo(Info ? Info : {
Id = 3037,
Name = "测试物品",
CurrentLimit = 0,
Limit = 0,
NeedItemId = 3037,
NeedItemCount = 1,
NeedItemId2 = 3038,
NeedItemCount2 = 1,
});
}
function SetInfo(Info) {
this.Info = Info;
}
function GetItemNeedStr(ItemId, ItemCount) {
if (ItemId == 0) return "金币 x" + ItemCount;
else if (ItemId != -1) {
local Name = Parent.GetItemNameById(ItemId);
return Name + " x" + ItemCount;
} else {
return "";
}
}
function Show() {
//绘制底槽
Img.DrawPng(6, X, Y);
Img.DrawPng(6, X, Y);
//绘制物品槽
Img.DrawPng(5, X + 12, Y + 18);
Parent.DrawItemBase(X + 12 + 3, Y + 18 + 3, Info.Id, 1);
//绘制物品名称
L_sq_DrawCode(format("%s (%d/%d)", Info.Name, Info.CurrentLimit, Info.Limit), X + 60, Y + 12, sq_RGBA(230, 200, 155, 255), 0, 1);
//绘制所需物品名称
local Str1 = GetItemNeedStr(Info.NeedItemId, Info.NeedItemCount);
if (Str1.len() > 0) L_sq_DrawCode("-> " + Str1, X + 60, Y + 30, sq_RGBA(174, 174, 174, 255), 0, 1);
local Str2 = GetItemNeedStr(Info.NeedItemId2, Info.NeedItemCount2);
if (Str2.len() > 0) L_sq_DrawCode("-> " + Str2, X + 60, Y + 46, sq_RGBA(174, 174, 174, 255), 0, 1);
}
function TopShow() {}
//高级绘制文字(带换行)
function L_sq_DrawCode_Ex(str, x, y, rgba, mb, jc) {
local strarr = [];
if (str.find("\\n") == null) L_sq_DrawCode(str, x, y, rgba, mb, jc);
else {
local Bpos = 0;
while (true) {
local Npos = str.find("\\n", Bpos);
if (!Npos) {
local strbuff = str.slice(Bpos, str.len());
strarr.append(strbuff);
break;
}
local strbuff = str.slice(Bpos, Npos);
strarr.append(strbuff);
Bpos = Npos + 2;
}
for (local z = 0; z< strarr.len(); z++) {
L_sq_DrawCode(strarr[z], x, y + (z * 14), rgba, mb, jc);
}
}
}
function Proc() {
X = (Parent.X + 235 + (Idx % 2 * 248)).tointeger();
Y = (Parent.Y - Parent.ItemScrollRate * Parent.ItemScrollValue + 121 + (Idx / 2 * 72)).tointeger();
}
}
class AchievementNC extends LenheartNewUI_Windows {
//调试模式
// DeBugMode = true;
//不是窗口
// NoWindow = true;
//是否可见
// Visible = false;
//脚本数据
ScriptInfo = null;
//图像对象
Img = null;
//当前页面类型
CurrentTypePage = 0;
//等级对象
Level = null;
//项目集合
ItemList = null;
//类型按钮集合
TypeButton = null;
//类型按钮滚动条对象
TypeButtonScrollBar = null;
//类型按钮滚轮值
TypeButtonScrollRate = 0;
TypeButtonScrollValue = 100;
//项目按钮集合
ItemButtonList = null;
//项目滚动条对象
ItemScrollBar = null;
//项目滚轮值
ItemScrollRate = 0;
ItemScrollValue = 400;
//查询成就状态
function QueryTheAchievementStatus() {
SendPackEx({
op = 20093001,
cjid = CurrentTypePage
});
}
//查询商店信息
function QueryShopInfo() {
SendPackEx({
op = 20093021
});
}
constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH) {
Childrens = [];
TypeButton = [];
ItemButtonList = [];
LenheartNewUI_Windows.constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH);
//给一个等级的默认值
Level = {
lv = 1,
exp = 0,
maxexp = 100
}
//读取pvf数据
InitScriptData();
//构造Img
InitImg();
//构造类型按钮
InitTypeButton();
//构造商店按钮
InitShopButton();
//构造组件按钮
InitWidgetButton();
//构造项目
InitItem();
//查询成就回包
RegisterPack(20093002, function(Chunk) {
//清空右侧项目集合
ItemList = [];
ItemButtonList = [];
local Jso = Json.Decode(Chunk);
Level.lv = Jso.lv.lv + 1;
Level.exp = Jso.lv.exp;
Level.maxexp = Jso.lv.maxexp;
foreach(Pos, obj in Jso.achievement) {
local PvfData = ScriptInfo[CurrentTypePage][obj.id];
local Item = AchievementNC_Item(this, Pos, {
Id = obj.id,
Name = PvfData.name,
Explain = PvfData.explain,
Desc = obj.currentNum + "/" + obj.maxNum,
Exp = obj.exp.tostring(),
IsSuccess = obj.achievement
});
ItemList.append(Item);
}
ItemScrollValue = ((ItemList.len() - 10) / 2 * 71).tointeger();
}.bindenv(this));
//查询商店回包
RegisterPack(20093022, function(Chunk) {
//清空右侧项目集合
ItemList = [];
ItemButtonList = [];
local Jso = Json.Decode(Chunk);
foreach(Pos, obj in Jso.info) {
local ItemName = GetItemNameById(obj.itemId);
local Item = AchievementNC_MerchandiseItem(this, Pos, {
Id = obj.itemId,
Name = ItemName,
Limit = obj.limit,
CurrentLimit = obj.currentNum,
NeedItemId = obj.reItemId,
NeedItemCount = obj.reItemNum,
NeedItemId2 = obj.reItemId2,
NeedItemCount2 = obj.reItemNum2,
});
ItemList.append(Item);
}
}.bindenv(this));
}
function InitScriptData() {
ScriptInfo = {};
Rindro_Script.GetFileData("etc/rindro/achievement/achievement.etc", function(DataTable, Data) {
while (!Data.Eof()) {
local Buffer = Data.Get();
if (Buffer == "[item]") {
Data.Get();
local Type = Data.Get();
Data.Get();
local Id = Data.Get();
Data.Get();
local namebuf = Data.Get();
namebuf = Sq_ConvertWideChar(namebuf, "big5")
Data.Get();
local explainbuf = Data.Get();
explainbuf = Sq_ConvertWideChar(explainbuf, "big5")
Data.Get();
if (!ScriptInfo.rawin(Type)) ScriptInfo[Type] <- {};
ScriptInfo[Type][Id] <- {
name = namebuf,
explain = explainbuf
}
}
}
}.bindenv(this));
}
function InitTypeButton() {
for (local i = 0; i< 6; i++) {
local Button = Achievement_New_TypeButton(171, 50, "achievement/typebutton.img", i, i, Y + 108, Y + 424)
Button.SetCallBackFunc(function(Button) {
Button.X = X + 28;
Button.Y = Y + 110 + 60 * Button.Pos - (TypeButtonScrollRate * TypeButtonScrollValue).tointeger();
}.bindenv(this));
Button.OnClickEx = function(Button) {
//将其他的选中状态取消选中自己
foreach(Btn in TypeButton) {
Btn.isSelect = false;
}
Button.isSelect = true;
//设定当前页面类型
CurrentTypePage = Button.Pos;
//还原右侧滚动条
ItemScrollBar.Reset();
//查询
QueryTheAchievementStatus();
}.bindenv(this);
TypeButton.append(Button);
}
TypeButtonScrollBar = Yosin_ScrollBar(204, 109, 317, 180);
TypeButtonScrollBar.SetParent(this);
TypeButtonScrollBar.SetStep(20 / 100.0);
TypeButtonScrollBar.SetOnChange(function(Rate) {
TypeButtonScrollRate = Rate;
}.bindenv(this));
}
function InitShopButton() {
//商店按钮
local ShopButton = LenheartNewUI_BaseButton(34, 435, 160, 61, "achievement/shopbutton.img", 0);
ShopButton.OnClick = function() {
CurrentTypePage = -99;
foreach(Btn in TypeButton) {
Btn.isSelect = false;
}
QueryShopInfo();
}.bindenv(this);
Childrens.append(ShopButton);
ItemScrollBar = Yosin_ScrollBar(723, 114, 382, 180);
ItemScrollBar.SetParent(this);
ItemScrollBar.SetStep(20 / 100.0);
ItemScrollBar.SetOnChange(function(Rate) {
ItemScrollRate = Rate;
}.bindenv(this));
}
function InitWidgetButton() {
//关闭按钮
local CloseButton = LenheartNewUI_BaseButton(734, 0, 11, 12, "interface/lenheartwindowcommon.img", 276);
CloseButton.OnClick = function() {
this.Visible = false;
}.bindenv(this);
Childrens.append(CloseButton);
}
function InitImg() {
Img = {};
Img["background"] <- Rindro_Image("achievement/background.img");
Img["logo"] <- Rindro_Image("achievement/logo.img");
Img["buttoneffect"] <- Rindro_Image("achievement/buttoneffect.img");
Img["typebutton"] <- Rindro_Image("achievement/typebutton.img");
Img["widget"] <- Rindro_Image("achievement/widget.img");
Img["lv"] <- Rindro_Image("achievement/lv.img");
}
function InitItem() {
ItemList = [];
for (local i = 0; i< 15; i++) {
local Item = AchievementNC_Item(this, i, null);
ItemList.append(Item);
}
}
//绘制主界面
function DrawMain(obj) {
//绘制底层窗口
Img["background"].DrawPng(CurrentTypePage > 0 ? CurrentTypePage : 0, X, Y);
//绘制logo
Img["logo"].DrawPng(0, X + 25, Y + 40);
//绘制常规页面
if (CurrentTypePage != -99) {
//上背景框
Img["widget"].DrawPng(0, X + 220, Y + 45);
//经验
Img["widget"].DrawPng(2, X + 223, Y + 86);
setClip(X + 223, Y + 86, X + 229 + (Level.exp.tofloat() / Level.maxexp.tofloat() * 463).tointeger(), Y + 90 + 6);
Img["widget"].DrawPng(3, X + 229, Y + 90);
releaseClip(); //裁切结束
//旗帜
Img["widget"].DrawPng(4, X + 226, Y + 55);
//奖励底槽
Img["widget"].DrawPng(5, X + 697, Y + 65);
DrawItemBase(X + 697 + 3, Y + 65 + 3, 3037, 1);
//绘制等级
Img["lv"].DrawPng(10, X + 252, Y + 63);
DrawNum(format("%02d", Level.lv), X + 274, Y + 63);
}
//下背景框
Img["widget"].DrawPng(1, X + 220, Y + 109);
}
function Show(obj) {
DrawMain(obj);
LenheartNewUI_BaseWindow.Show(obj);
//左侧裁切
setClip(X + 15, Y + 108, X + 214, Y + 424);
foreach(Window in TypeButton) {
if (Window.CallBackFunc) Window.CallBackFunc(Window);
if (Window.Visible) {
Window.Show(obj);
Window.TopShow(obj);
}
}
releaseClip(); //裁切结束
//右侧裁切
setClip(X + 221, Y + 110, X + 733, Y + 496);
//绘制项目
foreach(Item in ItemList) {
Item.Show();
}
//项目的按钮层
foreach(Window in ItemButtonList) {
if (Window.CallBackFunc) Window.CallBackFunc(Window);
if (Window.Visible) {
Window.Show(obj);
Window.TopShow(obj);
}
}
releaseClip(); //裁切结束
//用来显示悬停之类的顶层信息
foreach(Item in ItemList) {
Item.TopShow();
}
}
RegisFlag = false;
//逻辑入口
function Proc(obj) {
LenheartNewUI_Windows.SyncPos(X, Y);
//项目Proc
foreach(Item in ItemList) {
Item.Proc();
}
local RootTab = getroottable();
if (RootTab.rawin("L_PlayerEach_Obj") && RegisFlag == false) {
RegisFlag = true;
RootTab["L_PlayerEach_Obj"].AddEachForCommon("查看收集信息", 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 = 58;
ApplyEngagementButton.Str = "查看收集信息";
ApplyEngagementButton.OnClick = function(Button) {
if (L_Sq_GetPlayerEachName().len() <= 0 || L_Sq_GetPlayerEachName() == L_Sq_GetObjectName(sq_GetMyMasterCharacter())) {
} else {
}
Button.Parent.CloseAllEach();
}.bindenv(this);
ApplyEngagementButton.SetCallBackFunc(function(Button) {})
SThis.AddChild(ApplyEngagementButton);
}.bindenv(this));
}
}
//鼠标事件回调
function OnMouseProc(Flag, MousePos_X, MousePos_Y) {
LenheartNewUI_BaseWindow.OnMouseProc(Flag, MousePos_X, MousePos_Y);
foreach(Window in TypeButton) {
Window.OnMouseProc(Flag, MousePos_X, MousePos_Y);
}
foreach(Window in ItemButtonList) {
Window.OnMouseProc(Flag, MousePos_X, MousePos_Y);
}
}
//鼠标左键按下回调
function OnMouseLbDown(MousePos_X, MousePos_Y) {
LenheartNewUI_BaseWindow.OnMouseLbDown(MousePos_X, MousePos_Y);
foreach(Window in TypeButton) {
Window.OnMouseLbDown(MousePos_X, MousePos_Y);
}
foreach(Window in ItemButtonList) {
Window.OnMouseLbDown(MousePos_X, MousePos_Y);
}
}
//鼠标左键弹起回调
function OnMouseLbUp(MousePos_X, MousePos_Y) {
LenheartNewUI_BaseWindow.OnMouseLbUp(MousePos_X, MousePos_Y);
foreach(Window in TypeButton) {
Window.OnMouseLbUp(MousePos_X, MousePos_Y);
}
foreach(Window in ItemButtonList) {
Window.OnMouseLbUp(MousePos_X, MousePos_Y);
}
}
//鼠标滚轮时间回调
function OnMouseWheel(Flag, MousePos_X, MousePos_Y) {
LenheartNewUI_BaseWindow.OnMouseWheel(Flag, MousePos_X, MousePos_Y);
//左侧的滚动条判定
if (MousePos_X > (X + 15) && MousePos_X<(X + 214) && MousePos_Y > (Y + 108) && MousePos_Y<(Y + 424)) {
if (Flag) TypeButtonScrollBar.DoStep(-1);
if (!Flag) TypeButtonScrollBar.DoStep(1);
}
//右侧的滚动条判定
if (MousePos_X > (X + 221) && MousePos_X<(X + 733) && MousePos_Y > (Y + 110) && MousePos_Y<(Y + 496)) {
if (Flag) ItemScrollBar.DoStep(-1);
if (!Flag) ItemScrollBar.DoStep(1);
}
}
function DrawNum(Str, dx, dy) {
for (local i = 0; i< Str.len(); i++) {
local DrawNum = Str.slice(i, i + 1);
Img["lv"].DrawPng(DrawNum.tointeger(), dx + (i * 8), dy);
}
}
function OpenCallBack() {
Visible = true;
//查询
QueryTheAchievementStatus();
}
}
L_Windows_List <- [];
getroottable().rawdelete("LenheartPluginsInitFlag");
getroottable().rawdelete("EventList_Obj")
getroottable().rawdelete("AchievementN_Obj");
function Lenheart_Achievement_Fun(obj) {
local RootTab = getroottable();
if (!RootTab.rawin("AchievementN_Obj")) {
RootTab.rawset("AchievementN_Obj", true);
local Win = LenheartNewUI_CreateWindow(AchievementNC, "成就系统窗口", ((getroottable().Rindro_Scr_Width - 753) / 2).tointeger(), 35, 753, 518, 20);
EventList_Obj.AddEvent("成就系统", 118, Win);
}
}
getroottable()["LenheartFuncTab"].rawset("AchievementFuncN", Lenheart_Achievement_Fun);