/* 文件名: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; constructor(Window, Idx, Info) { Parent = Window; Img = Window.Img["widget"]; this.Idx = Idx; this.Info = Info; this.Info = { Name = "测试的成就名称", Desc = "0/100", Exp = sq_getRandom(1, 99).tostring() }; //完成按钮 local SuccessButton = Achievement_New_ItemButton(42 + 85 + 85, 420, 15, "完成"); SuccessButton.DWidth = -5; SuccessButton.Width = 50; SuccessButton.SetTextOffset(-4, 1); SuccessButton.OnClick = function() { }.bindenv(this); SuccessButton.SetCallBackFunc(function(Button) { Button.X = (X + 170).tointeger(); Button.Y = (Y + 20).tointeger(); Button.CutPosY_Start = Parent.Y + 110; Button.CutPosY_End = Parent.Y + 496; }.bindenv(this)); Parent.ItemButtonList.append(SuccessButton); } 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 Proc() { X = Parent.X + 235 + (Idx % 2 * 248); Y = Parent.Y - Parent.ItemScrollRate * Parent.ItemScrollValue + 121 + (Idx / 2 * 72); } } class AchievementNC extends LenheartNewUI_Windows { //调试模式 // DeBugMode = true; //不是窗口 // NoWindow = true; //是否可见 // Visible = false; EtcInfo = null; //图像对象 Img = null; //当前页面类型 CurrentTypePage = 0; //等级对象 Level = null; //项目集合 ItemList = null; //类型按钮集合 TypeButton = null; //类型按钮滚动条对象 TypeButtonScrollBar = null; //类型按钮滚轮值 TypeButtonScrollRate = 0; TypeButtonScrollValue = 100; //项目按钮集合 ItemButtonList = null; //项目滚动条对象 ItemScrollBar = null; //项目滚轮值 ItemScrollRate = 0; ItemScrollValue = 100; constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH) { Childrens = []; TypeButton = []; ItemButtonList = []; LenheartNewUI_Windows.constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH); //TODO Level = { lv = 15, exp = 100, maxexp = 200 } //构造Img InitImg(); //构造类型按钮 InitTypeButton(); //构造商店按钮 InitShopButton(); //构造项目 InitItem(); } function InitTypeButton() { for (local i = 0; i< 6; i++) { local Button = Achievement_New_TypeButton(171, 50, "achievement/typebutton.img", 0, 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; }.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; }.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 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(1, X + 220, Y + 109); //经验 Img["widget"].DrawPng(2, X + 223, Y + 86); setClip(X + 223, Y + 86, X + 229 + 463 - (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); } } 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(); //裁切结束 } 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() { } } 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);