Sqr/UI/HOOK_UI/CreatChr.nut

343 lines
12 KiB
Plaintext

class UnderBaseDraw
{
//绘制函数
function T_DrawDynamicAni(AniFileName, Xpos, Ypos, AniName)
{
if(CreatChrTable.rawin(AniName) == false) CreatChrTable.rawset(AniName, sq_CreateAnimation("", AniFileName));
else
{
sq_AnimationProc(CreatChrTable[AniName]);
sq_drawCurrentFrame(CreatChrTable[AniName], Xpos, Ypos, true);
}
}
function T_DrawStayAni(AniFileName, Xpos, Ypos, Index, AniName)
{
if(CreatChrTable.rawin(AniName) == false) CreatChrTable.rawset(AniName, sq_CreateAnimation("", AniFileName));
else
{
sq_DrawSpecificFrame(CreatChrTable[AniName], Xpos, Ypos, false, Index, false, 1.0);
}
}
function T_DrawStayAniAlpha(AniFileName, Xpos, Ypos, Index, AniName, Alpha)
{
if(CreatChrTable.rawin(AniName) == false) CreatChrTable.rawset(AniName, sq_CreateAnimation("", AniFileName));
else
{
CreatChrTable[AniName].setRGBA(255, 255, 255, Alpha);
sq_DrawSpecificFrame(CreatChrTable[AniName], Xpos, Ypos, false, Index, false, 1.0);
}
}
}
class UnderButton extends UnderBaseDraw
{
State = 0; //按钮状态
ClickEnble = false; //点击效果
ButtonDynamic = false; //动态按钮效果
CustomClickEnble = false; //自定义点击效果
CustomClickAnifile = null; //自定义点击效果Ani路径
CustomButtonName = null; //自定义点击效果名称
CustomClickFrame = null; //自定义点击效果Ani编号
CustomClickx = null; //自定义点击效果X坐标
CustomClicky = null; //自定义点击效果Y坐标
RectEnble = false; //悬停效果
RectButtonName = null; //悬停名称
RectBaseAnifile = null; //悬停Ani路径
RectFrame = null; //非动态按钮的悬停调用Ani编号
Rectx = null; //悬停X坐标
Recty = null; //悬停Y坐标
ButtonName = null; //按钮名称
x = null; //X坐标
y = null; //Y坐标
BaseAnifile = null; //调用Ani路径
width = null; //可点击宽度
length = null; //可点击高度
//构造函数
constructor(gButtonName, gX, gY, gAnifile, gWidth, gLength)
{
ButtonName = gButtonName;
x = gX;
y = gY;
BaseAnifile = gAnifile;
width = gWidth;
length = gLength;
}
//绘制按钮
function Show()
{
if(ClickEnble) //是否开启点击效果
{
if(isLBDown() && State == 0) //按下左键并且按钮处于弹起状态
{
State = 1; //按键进入按下状态
//++y;
}
if(!isLBDown() && State == 1) //按下左键并且按钮处于弹起状态
{
State = 0; //按键进入弹起状态
//--y;
}
}
if(CustomClickEnble) //是否开启自定义点击效果
{
if(isLBDown()) //按下左键并且按钮处于弹起状态
{
if(!ButtonDynamic) T_DrawStayAni(CustomClickAnifile, CustomClickx, CustomClicky, CustomClickFrame, CustomButtonName);
else T_DrawDynamicAni(CustomClickAnifile, CustomClickx, CustomClicky, CustomButtonName);
}
}
if(RectEnble) //开启悬停效果时
{
if((isInRect() && !isLBDown()) || (isInRect() && !CustomClickEnble)) //如果鼠标悬停的时候 并且没有点击的时候
{
//IMouse.SetMouseTask(44);
if(!ButtonDynamic) T_DrawStayAni(RectBaseAnifile, Rectx, Recty, RectFrame, RectButtonName);
else T_DrawDynamicAni(RectBaseAnifile, Rectx, Recty, RectButtonName);
}
}
if(!isInRect()) //如果鼠标没有悬停的时候
{
//IMouse.SetMouseTask(0);
if(!ButtonDynamic) T_DrawStayAni(BaseAnifile, x, y, 0, ButtonName);
else T_DrawDynamicAni(BaseAnifile, x, y, ButtonName);
}
}
//设置自定义点击效果
function SetCustomClickEnble(bool, gButtonName, gX, gY, gAnifile, gFrame)
{
CustomClickEnble = bool; //自定义点击效果
CustomClickAnifile = gAnifile; //自定义点击效果Ani路径
CustomButtonName = gButtonName; //自定义点击效果名称
CustomClickFrame = gFrame; //自定义点击效果Ani编号
CustomClickx = gX; //自定义点击效果X坐标
CustomClicky = gY; //自定义点击效果Y坐标
}
//设置悬停效果
function SetRectEnble(bool, gButtonName, gX, gY, gAnifile, gFrame)
{
RectEnble = bool; //悬停效果
RectButtonName = gButtonName; //悬停名称
RectBaseAnifile = gAnifile; //悬停Ani路径
RectFrame = gFrame; //非动态按钮的悬停调用Ani编号
Rectx = gX; //悬停X坐标
Recty = gY; //悬停Y坐标
}
//设置动态按钮
function SetClickEnble(bool)
{
ButtonDynamic = bool;
}
//设置点击效果
function SetClickEnble(bool)
{
ClickEnble = bool;
}
//悬停状态
function isInRect()
{
if(sq_IsIntersectRect(IMouse.GetXPos(), IMouse.GetYPos(), 5, 5, x, y, width, length)) return true;
else return false;
}
//左键按下状态
function isLBDown()
{
if(isInRect() && IMouse.GetLButton() == 1) return true;
else return false;
}
//左键弹起状态
function isLBUp()
{
if(isInRect() && IMouse.GetLButton() == 0) return true;
else return false;
}
//左键双击状态
function IsLBDoubleClick()
{
if(isInRect() && IMouse.GetLButton() == 64) return true;
else return false;
}
//左键单击状态
function isLBActive()
{
if(isInRect() && IMouse.isButtonUpEvent()) return true;
else return false;
}
}
class CreatChrC extends UnderBaseDraw
{
Job = 0; //当前职业
ChrJobDrawState = 0; //职业绘制状态
DrawChrAniEffTimer = null; //职业绘制Timer
ChrJobDrawAlpha = []; //职业绘制Alpha数组
SelectSwitch = false; //选择职业开关
NowChrSelectPos = 0; //当前角色职业选择位置
constructor()
{
ChrJobDrawAlpha.resize(16); //初始化职业绘制Alpha数组
for(local i = 0; i < 16; ++i)
{
ChrJobDrawAlpha[i] = 0;
}
DrawChrAniEffTimer = TimeSTL("DrawChrAniEffTimer", 3000); //初始化职业绘制Timer
}
//同步角色职业选择位置
function SyncChrSelectPos()
{
NowChrSelectPos = L_sq_RA(0x1A5E258, "0xA8+0xC0+");
}
//绘制角色信息
function DrawChrJobInfo()
{
T_DrawStayAni("common/creatchr/chrbackground/background.ani", 0, 0, NowChrSelectPos, "BMain0");
T_DrawDynamicAni("common/creatchr/chrjobani/" + NowChrSelectPos + ".ani", -160, 0, "DrawChrJobInfo" + NowChrSelectPos);
T_DrawDynamicAni("common/creatchr/base/0.ani", 0, 0, "BackGround0");
T_DrawDynamicAni("common/creatchr/base/" + (NowChrSelectPos % 2 + 1) + ".ani", 0, 0, "BackGround1" + (NowChrSelectPos % 2 + 1));
//T_DrawDynamicAni( "common/creatchr/base/1.ani", 0, 0,"BackGround1");
//T_DrawDynamicAni( "common/creatchr/base/2.ani", -267, 0,"BackGround2");
T_DrawDynamicAni("common/creatchr/base/3.ani", -267, 0, "BackGround3");
}
function DrawSelectButton()
{
for(local i = 0; i < 16; ++i)
{
if(i == NowChrSelectPos) continue;
local SelectButton = UnderButton("SelectChrJob" + i, 40 + (i % 4 * 70), 40 + (i / 4 * 70), "common/creatchr/jobbutton/0.ani", 66, 66);
SelectButton.SetRectEnble(true, "SelectChrJob" + i, 40 + (i % 4 * 70), 40 + (i / 4 * 70), "common/creatchr/jobbutton/0.ani", 1);
SelectButton.SetCustomClickEnble(true, "SelectChrJob" + i, 40 + (i % 4 * 70), 40 + (i / 4 * 70), "common/creatchr/jobbutton/0.ani", 1);
SelectButton.Show();
if(SelectButton.isLBActive())
{
L_sq_WA(0x1A5E258, "0xA8+0xC0+", i);
}
}
//角色职业按钮动画完毕以后才显示当前选中
if(ChrJobDrawAlpha[15] == 250) T_DrawStayAni("common/creatchr/jobbutton/0.ani", 40 + (NowChrSelectPos % 4 * 70), 40 + (NowChrSelectPos / 4 * 70), 2, "DrawChrJobInfoSelectPos");
}
function DrawJobButton()
{
DrawChrJobInfo();
for(local i = 0; i < 16; ++i)
{
T_DrawStayAniAlpha("common/creatchr/jobbutton/0.ani", 40 + (i % 4 * 70), 40 + (i / 4 * 70), 3 + (i * 2), "JobAni" + i, ChrJobDrawAlpha[i]);
}
local MainButton = UnderButton("MainButton", 50, 530, "common/training/main/maintab.ani", 38, 35);
MainButton.SetRectEnble(true, "MainButton", 50, 530, "common/training/main/maintab.ani", 0);
MainButton.SetCustomClickEnble(true, "MainButton", 50, 530 + 1, "common/training/main/maintab.ani", 0);
MainButton.Show();
if(MainButton.isLBActive())
{
DrawChrAniEffTimer.Reset();
DrawChrAniEffTimer.Start();
if(ChrJobDrawState == 0) ++ChrJobDrawState;
else ChrJobDrawState = ChrJobDrawState * -1;
}
//绘制阶段
if(ChrJobDrawState == 1)
{
//最后一个角色头像的Alpha值等于250之前
if(ChrJobDrawAlpha[15] < 250)
{
if(DrawChrAniEffTimer.Get() >= 15)
{
DrawChrAniEffTimer.Reset();
DrawChrAniEffTimer.Start();
for(local i = 0; i < 16; ++i)
{
local AddAlpha = (20 - i) * 1;
if(ChrJobDrawAlpha[i] + AddAlpha < 250) ChrJobDrawAlpha[i] += AddAlpha;
else ChrJobDrawAlpha[i] = 250;
}
}
}
else
{
SelectSwitch = true;
}
}
if(ChrJobDrawState == -1)
{
//第一个角色的Alpha值等于0之前
if(ChrJobDrawAlpha[0] > 0)
{
if(DrawChrAniEffTimer.Get() >= 15)
{
DrawChrAniEffTimer.Reset();
DrawChrAniEffTimer.Start();
for(local i = 0; i < 16; ++i)
{
local AddAlpha = (4 + i) * 1;
if(ChrJobDrawAlpha[i] - AddAlpha > 0) ChrJobDrawAlpha[i] -= AddAlpha;
else ChrJobDrawAlpha[i] = 0;
}
}
}
else
{
SelectSwitch = false;
}
}
//绘制选择角色职业按钮
if((SelectSwitch == true && ChrJobDrawAlpha[0] >= 35) || ChrJobDrawState == 1) DrawSelectButton();
}
function Run()
{
SyncChrSelectPos();
DrawJobButton();
}
}
CreatChrTable <- {}
function CreatChr()
{
/*
if(sq_IsKeyDown(7, ENUM_SUBKEY_TYPE_ALL))
{
if(CreatChrTable.rawin("CreatChrCObject") == true) CreatChrTable.rawdelete("CreatChrCObject");
}
*/
if(CreatChrTable.rawin("CreatChrCObject") == false) CreatChrTable.rawset("CreatChrCObject", CreatChrC());
else CreatChrTable["CreatChrCObject"].Run();
//CreatChrC.T_DrawDynamicAni("BackGround0", "common/creatchr/base/0.ani", -267, 0);
/*
if(CreatChrTable.rawin("BackGround0") == false) CreatChrTable.rawset("BackGround0", sq_CreateAnimation("", "common/creatchr/base/0.ani"));
if(CreatChrTable.rawin("BackGround1") == false) CreatChrTable.rawset("BackGround1", sq_CreateAnimation("", "common/creatchr/base/0.ani"));
if(CreatChrTable.rawin("BackGround2") == false) CreatChrTable.rawset("BackGround2", sq_CreateAnimation("", "common/creatchr/base/0.ani"));
if(CreatChrTable.rawin("BackGround3") == false) CreatChrTable.rawset("BackGround3", sq_CreateAnimation("", "common/creatchr/base/0.ani"));
sq_AnimationProc(CreatChrTable["Test"]);
sq_drawCurrentFrame(CreatChrTable["Test"], -267, 0, true);
//T_DrawDynamicAni(obj, "common/dps/maintop.ani", 0, 0, "maintop"); //绘制Dps上边栏
//print(666);
//local mouseX = IMouse.GetXPos();
//local mouseY = IMouse.GetYPos();
//print(mouseX);
//print(mouseY);
*/
}