Rindro-Sqr/Project/SkinHub/SkinHub.nut

579 lines
20 KiB
Plaintext
Raw Normal View History

2024-09-29 16:52:10 +08:00
/*
文件名:SkinHub.nut
路径:Project/SkinHub/SkinHub.nut
创建日期:2024-09-27 22:44
文件用途:皮肤仓库
*/
class DamageFontObjectC {
X = 0;
Y = 0;
IDX = null;
UIdx = null;
gName = null;
gImgPath = null;
gMaxNumArr = null;
ID = null;
Parent = null;
ItemId = null;
constructor(ItemId, gName, gImgPath, gMaxNumArr, gId, Parent) {
this.gName = gName;
this.gImgPath = gImgPath;
this.gMaxNumArr = gMaxNumArr;
this.gMaxNumArr = gMaxNumArr;
this.ID = gId;
this.Parent = Parent;
this.ItemId = ItemId;
}
//绘制
function Show(obj, x, y) {
X = x;
Y = y;
//绘制底
L_sq_DrawImg("interface2/skinstorage/slots.img", 0, x, y);
L_Sq_DrawItem(X + 22, Y + 23, ID, 1, 0, 0, 0);
//绘制盖子
L_sq_DrawImg("interface2/skinstorage/slots.img", 2, x, y);
//
L_sq_DrawCode(gName, X + 84, Y + 23, sq_RGBA(178, 155, 113, 250), 0, 1);
L_sq_DrawCode("Yosin皮肤字体", X + 84, Y + 40, sq_RGBA(255, 177, 0, 250), 0, 1);
L_sq_DrawCode("无限制使用", X + 84, Y + 55, sq_RGBA(255, 85, 0, 250), 0, 1);
//绘制选中效果
if (Parent.FocusPrintIdx == ItemId) L_sq_DrawImg("interface2/skinstorage/slots.img", 4, x, y);
//绘制应用中
if (Parent.NowDamageSkinIndex == ItemId) L_sq_DrawImg("interface2/skinstorage/slots.img", 23, x + 290, y + 3);
}
}
class SkinHubC extends LenheartNewUI_Windows {
//调试模式
// DeBugMode = true;
//不是窗口
// NoWindow = true;
//是否可见
Visible = false;
//当前字体皮肤编号
NowDamageSkinIndex = null;
//拥有的字体列表
HasDamageSkinList = null;
//字体皮肤数据
DamageSkinList = null;
//数字伤害类型
RealType = null;
//当前页面
NowPage = 0;
//最大伤害数字
MaxDamageNumber = 99999999;
//显示对象
FocusPrintIdx = 561320400;
FocusPrintType = 0;
//Nut白字倍率
NutWRate = 0;
FontIdx = 0;
MapBaseXPos = 0;
MapBaseYPos = 0;
DamageFontArray = null;
//获取字体列表信息
function GetFontList() {
local T = {
op = 20076005,
}
SendPack(T);
}
//获取字体列表信息回调
function GetFontListCallBack(Chunk) {
local Jso = Json.Decode(Chunk);
NowDamageSkinIndex = Jso.damagefontCurrent;
InitDamageFont(NowDamageSkinIndex);
FocusPrintIdx = Jso.damagefontCurrent;
foreach(value in Jso.damagefont) {
DamageSkinList[value].IsHave = true;
}
}
//基础信息包回调
function GetBaseInfoCallBack(Chunk) {
DamageSkinList = {};
local Jso = Json.Decode(Chunk);
local Info = Jso.ZipS;
Info = Json.Decode(L_sq_Dezlib(Info)).info;
foreach(Idx, value in Info) {
value.IsHave <- false;
DamageSkinList.rawset(Idx.tointeger(), value);
}
}
//初始化伤害字体
function InitDamageFont(Idx) {
if (Idx == null) {
for (local i = 0; i< 7; i++) {
L_sq_IntiNumberDraw("common/etc/damagefontskin/damagefont00.img", 0 + (i * 10), i);
}
} else {
for (local i = 0; i< 7; i++) {
L_sq_IntiNumberDraw(DamageSkinList[Idx].gImgPath, 0 + (i * 10), i);
}
}
}
//初始化数字伤害类型
function InitRealType() {
RealType = [0, 5, 1, 5, 2, 5, 1, 2, 3, 5, 4, 5, 3, 5, 4, 5, 0, 5, 4, 5, 2, 5, 4];
}
//设置NUT白字
function SetNutRate() {
// local allRate = 1.0;
// for (local i = 1; i < 41; i++) {
// allRate = allRate * (sq_GetIntData(obj, 169, i) / 100).tofloat();
// }
// for (local w = 1; w < 21; w++) {
// allRate = allRate * (sq_GetIntData(obj, 174, w) / 100).tofloat();
// }
NutWRate = 1.0;
}
//设置地图原点
function SetMapBasePos(obj) {
local objectManager = obj.getObjectManager();
if (!objectManager) return;
MapBaseXPos = objectManager.getFieldXPos(0, ENUM_DRAWLAYER_NORMAL);
MapBaseYPos = objectManager.getFieldYPos(0, 0, ENUM_DRAWLAYER_NORMAL);
}
constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH) {
Childrens = [];
DamageFontArray = {};
DamageSkinList = {};
HasDamageSkinList = [];
local T = {
gIdx = 0, //伤害字体排列编号
gName = "默认伤害字体", //伤害字体名称
gImgPath = "common/etc/damagefontskin/damagefont00.img", //Img路径
gMaxNumArr = [73, 72], //普通999帧数数组
gKeyMaxNumArr = [71, 70], //暴击999帧数数组
itemId = 561320400, //道具ID
IsHave = true
}
DamageSkinList.rawset(561320400, T);
//注册控件
RegisterWidget();
LenheartNewUI_Windows.constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH);
Pack_Control.rawset(20076006, GetFontListCallBack.bindenv(this));
Pack_Control.rawset(20076010, GetBaseInfoCallBack.bindenv(this));
PushDamageFontDataFuncTab.rawset("SkinHub", PushDamageFontArray.bindenv(this));
//初始化伤害类型
InitRealType();
//初始化伤害字体
InitDamageFont(NowDamageSkinIndex);
}
function RegisterWidget() {
//关闭按钮
local CloseButton = LenheartNewUI_BaseButton(765, 2, 11, 12, "interface/lenheartwindowcommon.img", 276);
CloseButton.OnClick = function() {
this.Visible = false;
}.bindenv(this);
Childrens.append(CloseButton);
for (local i = 0; i< 5; i++) {
//激活按钮
local ActiveButton = LenheartNewUI_ButtonText(700, 140 + (i * 85), 15, "应 用");
ActiveButton.Data = i;
ActiveButton.SetFrame(null, 172);
ActiveButton.SetTextOffset(-3, 1);
ActiveButton.OnClickEx = function(Button) {
local T = {
op = 20076007,
2025-05-27 21:24:22 +08:00
itemId = HasDamageSkinList[Button.Data + abs(NowPage)],
2024-09-29 16:52:10 +08:00
type = 0
}
SendPackEx(T);
2025-05-27 21:24:22 +08:00
NowDamageSkinIndex = HasDamageSkinList[Button.Data + abs(NowPage)];
FocusPrintIdx = HasDamageSkinList[Button.Data + abs(NowPage)];
InitDamageFont(HasDamageSkinList[Button.Data + abs(NowPage)]);
2024-09-29 16:52:10 +08:00
}.bindenv(this);
ActiveButton.SetCallBackFunc(function(Button) {
if (Button.Data >= (HasDamageSkinList.len())) {
Button.Visible = false;
} else {
Button.Visible = true;
}
}.bindenv(this))
AddChild(ActiveButton);
}
//测试伤害按钮
local TestButton = LenheartNewUI_ButtonText(10, 536, 15, "测试字体");
TestButton.SetFrame(null, 172);
TestButton.SetTextOffset(-7, 1);
TestButton.OnClickEx = function(Button) {
PushDamageFontArray(0x1AB7CDC, 400, 300, 0, Clock(), FocusPrintType, 0, 0);
}.bindenv(this);
TestButton.SetCallBackFunc(function(Button) {
if (Button.isInRect) {
L_sq_DrawWindow(X + 10, Y + 500, 160, 12, "interface/lenheartwindowcommon.img", 97, 11, 12, 11, 13);
L_sq_DrawCode("按下[空格键]以测试伤害数字。", X + 18, Y + 512, sq_RGBA(178, 155, 113, 250), 0, 1);
}
}.bindenv(this))
AddChild(TestButton);
}
//绘制主界面
function DrawMain(obj) {
//绘制窗口
L_sq_DrawImg("interface2/skinstorage/skinstorage.img", 0, X, Y);
//绘制字体排列窗口
L_sq_DrawImg("interface2/skinstorage/skinstorage.img", 5, X + 421 - 9, Y + 108 - 67);
//总览
L_sq_DrawImg("interface2/skinstorage/tab/tab_summary.img", 3, X + 421 - 8, Y + 46 - 8);
//边框
L_sq_DrawImg("interface2/skinstorage/tab/tab_partyframe.img", 3, X + 487 - 8, Y + 46 - 8);
//伤害字体
L_sq_DrawImg("interface2/skinstorage/tab/tab_damagefonts.img", 2, X + 533 + 4, Y + 42 - 3);
//觉醒插图
L_sq_DrawImg("interface2/skinstorage/tab/tab_cutscene.img", 3, X + 609 - 7, Y + 52 - 14);
//表情
L_sq_DrawImg("interface2/skinstorage/tab/tab_instantemoticon.img", 3, X + 674 - 16, Y + 49 - 11);
//表情
L_sq_DrawImg("interface2/skinstorage/tab/tab_weaponlook.img", 3, X + 722 - 7, Y + 55 - 17);
L_sq_DrawCode("伤害字体类型: " + FocusPrintType, X + 84, Y + 542, sq_RGBA(178, 155, 113, 250), 0, 1);
local RealDrawPos = 0;
HasDamageSkinList = [];
foreach(Pos, v in DamageSkinList) {
//如果拥有字体
if (v.IsHave) {
HasDamageSkinList.append(v.itemId);
local Yoffset = ((RealDrawPos + NowPage) * 85);
RealDrawPos++;
if (Yoffset > 400 || Yoffset< 0) continue;
local Dobj = DamageFontObjectC(v.itemId, v.gName, v.gImgPath, v.gMaxNumArr, v.itemId, this);
Dobj.Show(obj, X + 425, Y + 114 + Yoffset);
}
}
//绘制页数
local Page = (abs(NowPage) + 1) + " / " + (abs(HasDamageSkinList.len() - 5) + 1);
L_sq_DrawCode(Page, X + 586 + LenheartTextClass.GetStringLength(Page) / 2, Y + 537, sq_RGBA(150, 255, 30, 250), 0, 1);
local chr = sq_GetCNRDObjectToSQRCharacter(obj);
local charAni = chr.sq_GetStayAni();
sq_AnimationProc(charAni);
sq_drawCurrentFrame(charAni, X + 210, Y + 364, false);
local MonsterAni = T_DrawDynamicAni_Fx(obj, "monster/goblin/animation_goblin2/down.ani", X + 360, Y + 364, "伤害字体哥布林倒地");
local NeArray = TryGetArry(1);
if (sq_GetCurrentTime(MonsterAni) >= 1000 && NeArray.len() == 0) {
local Timer = Clock();
local T = {
gIdx = "演示字体" + FontIdx,
XPos = X + 166,
YPos = Y + 230,
DamageNum = 999999999,
Type = 5,
TimeObj = Timer,
isKeyHit = false,
}
NeArray.append(T);
DamageFontArray.rawset(1, NeArray);
sq_Rewind(MonsterAni);
}
}
function TryGetArry(Type) {
if (DamageFontArray.rawin(Type)) return DamageFontArray[Type];
else return [];
}
//将伤害字体数据Push进数组
function PushDamageFontArray(ObjAddress, X, Y, Z, Value, Type, A1, A2) {
local Timer = Clock();
local gRealType;
if (Type <= 7) gRealType = RealType[Type];
else gRealType = RealType[((Type - 7) % 16) + 7];
//暴击
local KeyHit = false;
if (Type == 17) KeyHit = true;
//是扣血还是回血
if (Type == 7) {
if (Value< 0) gRealType = 4;
}
if (Type == 4) {
if (Value< 0) gRealType = 0;
}
if (Type == 1 || Type == 17) {
//记录总伤害
local oldDamageNum = Value;
//计算我的真是伤害
Value = (Value / NutWRate).tointeger();
//减去真实伤害 就是nut伤害
local newDamageNum = oldDamageNum - Value;
//如果有Nut伤害存在
if (newDamageNum > 0) {
local NeArray = TryGetArry(Type);
local Timer = Clock();
local T = {
gIdx = ObjAddress + FontIdx,
XPos = X,
YPos = Y - Z - (NeArray.len() * 16),
DamageNum = Value,
Type = 0,
TimeObj = Timer,
isKeyHit = KeyHit,
}
NeArray.append(T);
DamageFontArray.rawset(Type, NeArray);
++FontIdx;
}
}
local NeArray = TryGetArry(Type);
local T = {
gIdx = ObjAddress + FontIdx,
XPos = X + sq_getRandom(-15, 15),
YPos = Y - Z + sq_getRandom(-20, 20),
DamageNum = Value,
Type = gRealType,
TimeObj = Timer,
isKeyHit = KeyHit,
}
NeArray.append(T);
DamageFontArray.rawset(Type, NeArray);
++FontIdx;
return false;
}
function DrawFontImg(X, Y, Type, DamageNum, Time, isKeyHit) {
local rate = sq_GetUniformVelocity(60, 100, Time, 100);
rate = rate.tofloat() / 100.0;
//如果暴击
if (isKeyHit) {
rate *= 1.3;
Type = 4;
}
//白字
if (Type == 0) {
rate *= 0.7;
Y += 60;
}
local UpOffset = 0;
local Alpha = 0;
//超过0.3秒开始飘
if (Time >= 300) {
UpOffset = sq_GetUniformVelocity(0, 15, Time - 300, 500);
}
//超过0.3秒开始飘
if (Time >= 800) {
UpOffset = sq_GetAccel(15, 100, Time - 800, 500, true);
Alpha = sq_GetUniformVelocity(0, 250, Time - 800, 500);
}
if (DamageNum > MaxDamageNumber) {
if (isKeyHit) {
foreach(imgpos in DamageSkinList[FocusPrintIdx].gKeyMaxNumArr) {
L_sq_DrawImg(DamageSkinList[FocusPrintIdx].gImgPath, imgpos, X + ((30 * (MaxDamageNumber.tostring().len())) - ((20 * (MaxDamageNumber.tostring().len())) * rate)), Y + (20 - (20 * rate)) - UpOffset, 0, sq_RGBA(255, 255, 255, 255 - Alpha), rate, rate);
}
} else {
foreach(imgpos in DamageSkinList[FocusPrintIdx].gMaxNumArr) {
L_sq_DrawImg(DamageSkinList[FocusPrintIdx].gImgPath, imgpos, X + ((30 * (MaxDamageNumber.tostring().len())) - ((20 * (MaxDamageNumber.tostring().len())) * rate)), Y + (20 - (20 * rate)) - UpOffset, 0, sq_RGBA(255, 255, 255, 255 - Alpha), rate, rate);
}
}
} else {
// L_sq_DrawNumber(X + ((30 * (DamageNum.tostring().len())) - ((20 * (DamageNum.tostring().len())) * rate)), Y + (20 - (20 * rate)) - UpOffset, sq_RGBA(255, 255, 255, 255 - Alpha), rate, rate, Type, 18 * rate, 6, sq_Abs(DamageNum));
L_sq_DrawNumber(X, Y - UpOffset, sq_RGBA(255, 255, 255, 255 - Alpha), rate, rate, Type, sq_Abs(DamageNum));
}
}
//伤害字体绘制
function DrawFont(obj) {
foreach(Type, FontArrayObject in DamageFontArray) {
if (Type == 0) continue;
for (local i = 0; i< FontArrayObject.len(); i++) {
local FontObject = FontArrayObject[i];
if (FontObject) {
local Timer = FontObject.TimeObj;
if (Timer) {
local Time = Clock() - Timer;
if (Time >= 1300) {
FontObject.TimeObj = null;
FontArrayObject.remove(i);
continue;
} else {
DrawFontImg(FontObject.XPos - MapBaseXPos, FontObject.YPos - MapBaseYPos, FontObject.Type, FontObject.DamageNum, Time, FontObject.isKeyHit);
}
}
}
}
}
//白字
foreach(Type, FontArrayObject in DamageFontArray) {
if (Type != 0) break;
for (local i = 0; i< FontArrayObject.len(); i++) {
local FontObject = FontArrayObject[i];
if (FontObject) {
local Timer = FontObject.TimeObj;
if (Timer) {
local Time = Clock() - Timer;
if (Time >= 1100) {
FontObject.TimeObj = null;
FontArrayObject.remove(i);
continue;
} else {
DrawFontImg(FontObject.XPos - MapBaseXPos, FontObject.YPos - MapBaseYPos, FontObject.Type, FontObject.DamageNum, Time, FontObject.isKeyHit);
}
}
}
}
}
}
function T_DrawDynamicAni_Fx(obj, aniFileName, x, y, aniname) {
local ani = obj.getVar().GetAnimationMap(aniname, aniFileName);
ani.setImageRateFromOriginal(-1.0, 1.0);
sq_AnimationProc(ani);
sq_drawCurrentFrame(ani, x, y, true);
return ani;
}
function Show(obj) {
DrawMain(obj);
LenheartNewUI_Windows.Show(obj);
}
function TopShow(obj) {
//绘制字体
DrawFont(obj);
if (MousePosFlag == 1) {
L_sq_DrawWindow(X + 60, Y + 500, 160, 12, "interface/lenheartwindowcommon.img", 97, 11, 12, 11, 13);
L_sq_DrawCode("使用鼠标滚轮以改变字体类型。", X + 68, Y + 512, sq_RGBA(178, 155, 113, 250), 0, 1);
}
}
MousePosFlag = 0;
//override
//鼠标滚轮事件回调
function OnMouseWheel(Flag, MousePos_X, MousePos_Y) {
MousePos_X -= X;
MousePos_Y -= Y;
//鼠标在滚动字体类型区域
if (MousePosFlag == 1) {
if (Flag) {
if (FocusPrintType< 17) FocusPrintType++;
} else {
if (FocusPrintType > 0) FocusPrintType--;
}
} else if (MousePosFlag == 2) {
if (Flag) {
if (NowPage< 0) NowPage++;
} else {
if ((HasDamageSkinList.len()) > abs(NowPage - 5)) NowPage--;
}
}
//调用原生方法
LenheartNewUI_Windows.OnMouseWheel(Flag, MousePos_X, MousePos_Y);
}
//override
function OnMouseProc(Flag, MousePos_X, MousePos_Y) {
//调用原生方法
LenheartNewUI_Windows.OnMouseProc(Flag, MousePos_X, MousePos_Y);
MousePos_X -= X;
MousePos_Y -= Y;
//鼠标在滚动字体类型区域
if (MousePos_X >= 82 && MousePos_Y >= 538 && MousePos_X <= 188 && MousePos_Y <= 558) {
MousePosFlag = 1;
} else if (MousePos_X >= 420 && MousePos_Y >= 110 && MousePos_X <= 782 && MousePos_Y <= 564) {
MousePosFlag = 2;
} else {
MousePosFlag = 0;
}
}
//逻辑入口
function Proc(obj) {
LenheartNewUI_Windows.SyncPos(X, Y);
//绘制字体
if (sq_GetCurrentModuleType() == 3) DrawFont(obj);
//回到城镇清空字体数组
else if (Visible == false) {
DamageFontArray = null;
DamageFontArray = {};
MapBaseXPos = 0;
MapBaseYPos = 0;
}
//设置地图原点
SetMapBasePos(obj);
//设置NUT白字
SetNutRate();
if (KeyPressNB.isKeyPress(7, "damage") && this.Visible && sq_GetCurrentModuleType() != 3) {
PushDamageFontArray(0x1AB7CDC, 400, 300, 0, Clock(), FocusPrintType, 0, 0);
}
}
function OpenCallBack() {
this.Visible = true;
ResetFocus();
GetFontList();
}
}
function Lenheart_SkinHub_Fun(obj) {
local RootTab = getroottable();
if (!RootTab.rawin("SkinHub_Obj")) {
local Winobj = LenheartNewUI_CreateWindow(SkinHubC, "皮肤仓库窗口", ((getroottable().Rindro_Scr_Width - 788) / 2).tointeger(), 12, 788, 576, 26);
EventList_Obj.AddEvent("皮肤仓库", 670, Winobj, "interface2/hud/information_button/information_button_cn.img");
RootTab.rawset("SkinHub_Obj", Winobj);
}
}
getroottable()["LenheartFuncTab"].rawset("SkinHubFuncN", Lenheart_SkinHub_Fun);