DOF/sqr/User/UI/Window/1_Select_Character.nut

579 lines
18 KiB
Plaintext

/*
文件名:1_Select_Character.nut
路径:User/UI/Window/1_Select_Character.nut
创建日期:2024-12-13 15:45
文件用途:选择角色界面窗口
*/
class _Select_Character_SettingBackground_Object_Window extends Yosin_CommonUi {
//编号
Idx = 0;
//蓝色悬停框
RectMask = null;
//黄色选中框
SelectMask = null;
//选中状态
SelectFlag = false;
constructor(x, y, width, height, gIdx) {
base.constructor(x, y, width, height);
//编号
Idx = gIdx;
//注册绘制
RegisterDraw();
}
function RegisterDraw() {
//背景
local Background = CL_SpriteObject("sprite/interface2/selectcharacter_ver2/background/small/background_small_event.img", Idx);
Background.SetScale(0.7, 0.7);
Addchild(Background);
RectMask = CL_SpriteObject("sprite/interface2/selectcharacter_ver2/setup/setup.img", 18);
RectMask.SetVisible(false);
Addchild(RectMask);
SelectMask = CL_SpriteObject("sprite/interface2/selectcharacter_ver2/setup/setup.img", 19);
SelectMask.SetPosition(-2, -2);
SelectMask.SetVisible(false);
Addchild(SelectMask);
}
//override
function Proc(Dt) {
base.Proc(Dt);
if (isInRect && !SelectFlag) {
RectMask.SetVisible(true);
} else {
RectMask.SetVisible(false);
}
}
//鼠标左键单击回调
function OnMouseLbClick(MousePos_X, MousePos_Y, WindowInteractiveFlag) {
base.OnMouseLbClick(MousePos_X, MousePos_Y, WindowInteractiveFlag);
if (isInRect) {
//必须是在框的范围内
if (MousePos_Y > Parent.Y && MousePos_Y<(Parent.Y + Parent.Height)) {
//遍历父对象中的所有按钮 还原其他按钮
foreach(Button in Parent.SettingBackgroundButtonList) {
Button.SelectMask.SetVisible(false);
Button.SelectFlag = false;
}
//设置自身选中状态
SelectMask.SetVisible(true);
SelectFlag = true;
Parent.Parent.ChangeBackground(Idx);
}
}
}
}
class _Select_Character_SettingBackground_Window extends Yosin_Window {
//是否为独立窗口
IsIndependent = false;
//是否为图层窗口
IsLayer = true;
//是否可见
Visible = false;
//选择背景按钮集合
SettingBackgroundButtonList = null;
//背景对象
Background = null;
ScrollObject = null;
constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH) {
base.constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH);
SettingBackgroundButtonList = [];
SetClipRect(5, 9, gWidth, gHeight - 9);
SetZOrder(1000);
}
function Init() {
//注册绘制
RegisterDraw();
}
function RegisterDraw() {
//背景
Background = CL_SpriteObject("sprite/interface2/selectcharacter_ver2/setup/setup.img", 17);
Background.SetPosition(X, Y);
// Background.SetZOrder(-10);
Background.SetVisible(false);
//因为裁切原因 所以要添加到父对象中
Parent.Addchild(Background);
for (local i = 0; i< 24; i++) {
local Buf = _Select_Character_SettingBackground_Object_Window(5 + (101 * (i % 2)), 9 + (61 * (i / 2)), 91, 51, i);
SettingBackgroundButtonList.push(Buf);
//如果是父对象默认构造的默认是勾选状态
if (i == Parent.Info.loginImg) {
Buf.SelectMask.SetVisible(true);
Buf.SelectFlag = true;
}
AddUIChild(Buf);
}
ScrollObject = Yosin_ScrollBar(Width - 13, 5, Height - 8, 20);
ScrollObject.SetChangeCallBack(function(Value) {
foreach(Pos, Button in SettingBackgroundButtonList) {
Button.SyncPos(5 + (101 * (Pos % 2)), 9 + (61 * (Pos / 2)) - Value * (61 * 12));
}
}.bindenv(this));
AddUIChild(ScrollObject);
}
//override
//设置是否可见 通过重载设置可见同步Background的可见性
function SetVisible(Flag) {
base.SetVisible(Flag);
if (Flag) {
if (Background) Background.SetVisible(true);
} else {
if (Background) Background.SetVisible(false);
}
}
}
//角色
class _Select_Character_Chr extends Yosin_CommonUi {
//是否为独立窗口
IsIndependent = false;
Info = null;
Idx = null;
//悬停框
RectMask = null;
//选中框
SelectMask = null;
//选中状态
SelectFlag = false;
//鼠标相对位置
M_Xpos = null;
M_Ypos = null;
//移动Flag
MoveFlag = false;
//鼠标移动位置
M_Move_Xpos = 0;
M_Move_Ypos = 0;
constructor(gX, gY, gWidth, gHeight) {
base.constructor(gX, gY, gWidth, gHeight);
RegisterDraw();
// OpenDeBug();
}
function Init(Info, Idx) {
this.Info = Info;
this.Idx = Idx;
RegisterCharac();
}
function RegisterDraw() {
//魔法阵
local Magic = CL_SpriteObject("sprite/interface2/selectcharacter_ver2/selectcharacter.img", 10);
Magic.SetPosition(3, 136);
Addchild(Magic);
//悬停框
RectMask = CL_SpriteObject("sprite/interface2/selectcharacter_ver2/selectcharacter.img", 1);
RectMask.SetMode(0);
RectMask.SetPosition(3, 0);
RectMask.SetVisible(false);
Addchild(RectMask);
//选中框
SelectMask = CL_SpriteObject("sprite/interface2/selectcharacter_ver2/selectcharacter.img", 1);
SelectMask.SetMode(0);
SelectMask.SetPosition(3, 0);
SelectMask.SetVisible(false);
Addchild(SelectMask);
}
function RegisterCharac() {
if (!Info) return;
local Charc = GameObject.CreateCharacter(Info.job, Info.equip);
Charc.SetAnimation("RestAni");
Charc.SetPosition(64, 156, 0);
Charc.SetName(Info.lv + " 级 " + Info.name);
Charc.AdditionalItemsManager.Name.MoveBy(0, 170);
Addchild(Charc);
}
function SetIdxPosition(Idx) {
this.Idx = Idx;
SetPosition(184 + (Idx * 142), ((Idx % 2) ? 13 : 0) + 93)
SelectMask.SetVisible(false);
SelectFlag = false;
}
//override
//鼠标事件回调
function OnMouseProc(MousePos_X, MousePos_Y, WindowInteractiveFlag) {
base.OnMouseProc(MousePos_X, MousePos_Y, WindowInteractiveFlag);
if (isInRect) {
RectMask.SetVisible(true);
} else {
RectMask.SetVisible(false);
}
//设定拖动逻辑
if (MoveFlag) {
M_Move_Xpos = B_X - (M_Xpos - MousePos_X);
M_Move_Ypos = B_Y - (M_Ypos - MousePos_Y);
//左键拖动
SetPosition(M_Move_Xpos, M_Move_Ypos);
}
}
//override
//鼠标左键单击回调
function OnMouseLbClick(MousePos_X, MousePos_Y, WindowInteractiveFlag) {
base.OnMouseLbClick(MousePos_X, MousePos_Y, WindowInteractiveFlag);
if (isInRect) {
//遍历父对象中的所有按钮 还原其他按钮
foreach(Button in Parent.UpCharacterList) {
Button.SelectMask.SetVisible(false);
Button.SelectFlag = false;
}
//设置自身选中状态
SelectMask.SetVisible(true);
SelectFlag = true;
Parent.CurrentSelectCharacterIdx = Idx;
}
}
//override
//鼠标左键按下回调
function OnMouseLbDown(MousePos_X, MousePos_Y, WindowInteractiveFlag) {
base.OnMouseLbDown(MousePos_X, MousePos_Y, WindowInteractiveFlag);
if (isInRect) {
MoveFlag = true;
M_Xpos = MousePos_X; //原始鼠标位置数据
M_Ypos = MousePos_Y;
B_X = X; //原始窗口位置
B_Y = Y;
//遍历父对象中的所有按钮 修改他们的层级
foreach(Button in Parent.UpCharacterList) {
Button.SetZOrder(99999);
}
SetZOrder(100000);
}
}
//override
//鼠标左键弹起回调
function OnMouseLbUp(MousePos_X, MousePos_Y, WindowInteractiveFlag) {
base.OnMouseLbUp(MousePos_X, MousePos_Y, WindowInteractiveFlag);
if (MoveFlag) {
MoveFlag = false;
M_Xpos = null;
M_Ypos = null;
B_X = null;
B_Y = null;
//有移动才走替换位置逻辑
if (M_Move_Xpos != 0 || M_Move_Ypos != 0) {
//遍历父对象中的所有按钮 还原其他按钮
foreach(Button in Parent.UpCharacterList) {
if (Button.isInRect) {
//记录自身原本位置
local OldIdx = this.Idx;
//设置自身到达位置
SetIdxPosition(Button.Idx);
//设置对方的位置
Button.SetIdxPosition(OldIdx);
//发送替换位置包
SendReplaceCharacterPos(OldIdx, Button.Idx);
}
}
M_Move_Xpos = M_Move_Ypos = 0;
}
}
}
function SendReplaceCharacterPos(OldIdx, NewIdx) {
MySocket.Send(PACKET_ID.CHANGE_CHARACTER_POSITION, {
oldidx = OldIdx,
newidx = NewIdx
})
}
}
class _Select_Character_Window extends Yosin_Window {
//调试模式
// DeBugMode = true;
//不是窗口
// NoWindow = true;
//是否可见
// Visible = false;
//背景音乐
BackGroundMusic = null
//设置背景图片窗口
SettingBackgroundWindow = null;
//背景图片
BackGround = null;
//角色遮罩栏
CharacterMaskBox = null;
//上排角色对象
UpCharacterList = null;
//当前选中角色Idx
CurrentSelectCharacterIdx = 0;
//信息
Info = null;
constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH) {
base.constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH);
//定义五个空数组
UpCharacterList = array(5, null);
}
function Init(gInfo) {
//接收参数信息
Info = gInfo;
//注册绘制
RegisterDraw();
//注册控件
// for (local i = 0; i< 50; i++) {
// RegisterWidget();
// }
RegisterWidget();
//注册窗口
RegisterWindow();
// OpenDeBug();
}
function MusicLogic() {
if (BackGroundMusic == null) return;
if (!BackGroundMusic.IsPlaying()) BackGroundMusic.Play();
}
function AddUpCharacter(CharacInfo, Index = 5) {
//先定义为最大值 如果没有查到空位则不会执行逻辑
if (Index == 5) {
//遍历获取第一个空位 Info为空也为空
foreach(pos, value in UpCharacterList) {
if (value == null) {
Index = pos;
break;
}
//如果是信息为空的 要先删除原来的再添加
if (value.Info == null) {
Index = pos;
RemoveUIChild(UpCharacterList[pos]);
break;
}
}
if (Index >= 5) return;
}
local Buf = _Select_Character_Chr(184 + (Index * 142), ((Index % 2) ? 13 : 0) + 93, 132, 208);
//如果有信息则构造角色
if (CharacInfo) {
//通过信息构造角色
Buf.Init(CharacInfo, Index);
AddUIChild(Buf);
UpCharacterList[Index] = Buf;
} else {
Buf.Init(null, Index);
AddUIChild(Buf);
UpCharacterList[Index] = Buf;
}
}
function RegisterWindow() {
SettingBackgroundWindow = _Select_Character_SettingBackground_Window("选择角色_设置背景图片窗口", 850, 28, 212, 129, 0);
AddUIChild(SettingBackgroundWindow);
//先添加为子对象 因为子对象需要用到父对象
SettingBackgroundWindow.Init();
//角色对象
for (local i = 0; i< 5; i++) {
//角色框背景
local CharBg = CL_SpriteObject("sprite/interface2/selectcharacter_ver2/selectcharacter.img", 4);
CharBg.SetMode(0);
CharBg.SetPosition(184 + (i * 142) + 3, ((i % 2) ? 13 : 0) + 93);
CharBg.SetZOrder(-10);
Addchild(CharBg);
//如果没有足够的信息则传递null
AddUpCharacter((Info.charac.len() > i) ? Info.charac[i] : null, i);
}
}
function RegisterWidget() {
//背景设置按钮
local SettingButton = Yosin_BaseButton(984, 6, 77, 24 "sprite/interface2/ui/community/guild_2019/guildsetting/guildsetting.img", 29);
//点击事件回调
SettingButton.OnClick = function(Button) {
SettingBackgroundWindow.SetVisible(!SettingBackgroundWindow.Visible)
}.bindenv(this);
AddUIChild(SettingButton);
//背景设置按钮文本
local BgSettingTextActor = FontAssetManager.GenerateNormal("背景设置", true, {
color = sq_RGBA(221, 197, 147, 255)
});
BgSettingTextActor.SetPosition(23, 3);
BgSettingTextActor.SetUpdateFunc(function(Text, Dt) {
if (Text.Parent.State == 1 || Text.Parent.State == 2) {
Text.SetFillColor(sq_RGBA(255, 255, 184, 255));
} else if (Text.Parent.State == 0) {
Text.SetFillColor(sq_RGBA(221, 197, 147, 255));
}
})
SettingButton.Addchild(BgSettingTextActor);
//创建角色按钮
local CreateButton = Yosin_SplicingButton(316, 560, 59, 24 "sprite/interface/lenheartwindowcommon.img", 172, true, false);
//创建角色按钮文本
local CreateTextActor = FontAssetManager.GenerateNormal("创建角色", false, {
color = sq_RGBA(186, 147, 97, 255)
});
CreateButton.OnClick = function(Button) {
local Window = Sq_CreateWindow(_CreateCharacter, "创建角色界面窗口", 0, 0, 1067, 600, 0);
Window.ResetFocus();
}.bindenv(this);
AddUIChild(CreateButton);
CreateTextActor.SetPosition(6, 5);
CreateTextActor.SetZOrder(100000);
CreateTextActor.SetUpdateFunc(function(Text, Dt) {
if (Text.Parent.State == 1 || Text.Parent.State == 2) {
Text.SetFillColor(sq_RGBA(18, 71, 130, 255));
} else if (Text.Parent.State == 0) {
Text.SetFillColor(sq_RGBA(186, 147, 97, 255));
}
})
CreateButton.Addchild(CreateTextActor);
//删除角色按钮
local DeleteButton = Yosin_SplicingButton(384, 560, 59, 24 "sprite/interface/lenheartwindowcommon.img", 172, true, false);
//删除角色按钮文本
local DeleteTextActor = FontAssetManager.GenerateNormal(" 删除", false, {
color = sq_RGBA(186, 147, 97, 255)
});
AddUIChild(DeleteButton);
DeleteTextActor.SetPosition(6, 5);
DeleteTextActor.SetZOrder(100000);
DeleteTextActor.SetUpdateFunc(function(Text, Dt) {
if (Text.Parent.State == 1 || Text.Parent.State == 2) {
Text.SetFillColor(sq_RGBA(18, 71, 130, 255));
} else if (Text.Parent.State == 0) {
Text.SetFillColor(sq_RGBA(186, 147, 97, 255));
}
})
DeleteButton.Addchild(DeleteTextActor);
//结束游戏按钮
local CloseButton = Yosin_SplicingButton(702, 560, 59, 24 "sprite/interface/lenheartwindowcommon.img", 172, true, false);
//结束游戏按钮文本
local CloseTextActor = FontAssetManager.GenerateNormal("结束游戏", false, {
color = sq_RGBA(186, 147, 97, 255)
});
AddUIChild(CloseButton);
CloseTextActor.SetPosition(6, 5);
CloseTextActor.SetZOrder(100000);
CloseTextActor.SetUpdateFunc(function(Text, Dt) {
if (Text.Parent.State == 1 || Text.Parent.State == 2) {
Text.SetFillColor(sq_RGBA(18, 71, 130, 255));
} else if (Text.Parent.State == 0) {
Text.SetFillColor(sq_RGBA(186, 147, 97, 255));
}
})
CloseButton.Addchild(CloseTextActor);
//开始游戏按钮
local StartButton = Yosin_BaseButton(475, 546, 118, 47 "sprite/interface2/selectcharacter/selectcharacter.img", 7);
//点击事件回调
StartButton.OnClick = function(Button) {
//停止背景音乐
if (BackGroundMusic) {
BackGroundMusic.Pause();
}
SetVisible(false);
//发送进入游戏请求
MySocket.Send(PACKET_ID.SELECT_CHARACTER, {
cid = UpCharacterList[CurrentSelectCharacterIdx].Info.cid
});
}.bindenv(this);
AddUIChild(StartButton);
}
//切换背景
function ChangeBackground(Idx) {
if (BackGround) {
BackGround.RemoveSelf();
BackGround = null;
}
BackGround = CL_SpriteObject("sprite/interface2/selectcharacter_ver2/background/large/background_large_event.img", Idx);
BackGround.SetZOrder(-100);
Addchild(BackGround);
}
function RegisterDraw() {
//大背景 根据玩家的设定背景决定
ChangeBackground(Info.loginImg);
//角色遮罩栏
CharacterMaskBox = Yosin_NineBoxStretch(1074, 680, "sprite/interface/lenheartwindowcommon.img", 0);
CharacterMaskBox.SetPosition(-4, 320);
Addchild(CharacterMaskBox);
for (local i = 0; i< 7; i++) {
//魔法阵
local Magic = CL_SpriteObject("sprite/interface2/selectcharacter_ver2/selectcharacter.img", 10);
Magic.SetPosition(54 + (i * 142), 146);
CharacterMaskBox.Addchild(Magic);
//锁框
local LockBox = CL_SpriteObject("sprite/interface2/selectcharacter_ver2/selectcharacter.img", 16);
LockBox.SetPosition(54 + (i * 142), 10);
CharacterMaskBox.Addchild(LockBox);
}
}
//逻辑入口
function Proc(Dt) {
if (Visible) MusicLogic();
SyncPos(X, Y);
base.Proc(Dt);
}
}