674 lines
22 KiB
TypeScript
674 lines
22 KiB
TypeScript
import { HeadBorderUtil } from "./appearance/HeadBorderUtil";
|
||
import GameModel from "./core/GameModel";
|
||
import GameUtil from "./core/GameUtil";
|
||
import ItemUtil from "./core/ItemUtil";
|
||
import CustomRich from "./customRich";
|
||
import FGUtil from "./gear_2.3.4/fgui/FGUtil";
|
||
import SKDataUtil from "./gear_2.3.4/util/SKDataUtil";
|
||
import SKUIUtil from "./gear_2.3.4/util/SKUIUtil";
|
||
|
||
export default class ChatPanel extends cc.Component {
|
||
/**
|
||
* 單例實例
|
||
*/
|
||
public static Instance: ChatPanel = null;
|
||
|
||
/**
|
||
* 面板
|
||
*/
|
||
MainPanel: fgui.GComponent = null;
|
||
/**
|
||
* 是否透明
|
||
*/
|
||
isOpacity: boolean = false;
|
||
/**
|
||
* 聊天可以發送的道具列表
|
||
*/
|
||
goodsList: any = [];
|
||
/**
|
||
* 聊天可以發送的寵物列表
|
||
*/
|
||
petsList: any = [];
|
||
/**
|
||
* 聊天內容對象
|
||
*/
|
||
chatContentObj: any = {
|
||
cur: [],
|
||
my: [],
|
||
team: [],
|
||
bang: [],
|
||
world: [],
|
||
sys: [],
|
||
};
|
||
|
||
/**
|
||
* 當前聊天頻道
|
||
*/
|
||
curChatType: number = 4;
|
||
/**
|
||
* 當天聊天頻道內容
|
||
*/
|
||
curChatContetnList: any = [];
|
||
/**
|
||
* 發送的id列表
|
||
*/
|
||
mSendIds: any = [];
|
||
|
||
onLoad() {
|
||
if (ChatPanel.Instance === null) {
|
||
ChatPanel.Instance = this;
|
||
} else {
|
||
this.destroy();
|
||
return;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 打開聊天面板
|
||
*/
|
||
openChatPanel(type: number = 4) {
|
||
if (!SKUIUtil.isFGUIValid(this.MainPanel)) {
|
||
this.MainPanel = FGUtil.create("main_ui", "chat_panel");
|
||
FGUtil.root().addChild(this.MainPanel);
|
||
console.log(FGUtil.root())
|
||
console.log(FGUtil.root().node)
|
||
this.MainPanel.makeFullScreen();
|
||
this.isOpacity = false;
|
||
var trans: fgui.Transition = this.MainPanel.getTransition("enter");
|
||
trans.play();
|
||
}
|
||
|
||
FGUtil.getButton(this.MainPanel, "alert/close").onClick(this.closeChatPanel, this)
|
||
|
||
FGUtil.getButton(this.MainPanel, "alert/n3").onClick(this.chooseCur, this)
|
||
FGUtil.getButton(this.MainPanel, "alert/n4").onClick(this.chooseMy, this)
|
||
FGUtil.getButton(this.MainPanel, "alert/n5").onClick(this.chooseTeam, this)
|
||
FGUtil.getButton(this.MainPanel, "alert/n6").onClick(this.chooseBang, this)
|
||
FGUtil.getButton(this.MainPanel, "alert/n7").onClick(this.chooseWorld, this)
|
||
FGUtil.getButton(this.MainPanel, "alert/n8").onClick(this.chooseSys, this)
|
||
|
||
FGUtil.getButton(this.MainPanel, "alert/team1").onClick(this.addTeamMsg, this)
|
||
FGUtil.getButton(this.MainPanel, "alert/bang1").onClick(this.addBangMsg, this)
|
||
FGUtil.getButton(this.MainPanel, "alert/world1").onClick(this.addWorldMsg, this)
|
||
FGUtil.getButton(this.MainPanel, "alert/sys1").onClick(this.addSysMsg, this)
|
||
|
||
FGUtil.getButton(this.MainPanel, "alert/send").onClick(this.sendMsg, this);
|
||
|
||
FGUtil.getComponent(this.MainPanel, "alert/opacityBtn").onClick(this.changeOpacity, this);
|
||
FGUtil.getButton(this.MainPanel, "alert/emo_btn").onClick(this.showPropView, this);
|
||
FGUtil.getComponent(this.MainPanel, "propBg").onClick(this.hidePropView, this);
|
||
FGUtil.getTextInput(this.MainPanel, "alert/input").onClick(this.hidePropView, this);
|
||
FGUtil.getTextInput(this.MainPanel, "alert/input").on("text-changed", this.showClear, this);
|
||
FGUtil.getButton(this.MainPanel, "alert/clear").onClick(this.clearEdit, this);
|
||
|
||
var contentList = FGUtil.getList(this.MainPanel, "alert/list");
|
||
contentList.itemRenderer = this.initPlayerChatItem.bind(this);
|
||
contentList.itemProvider = this.getListItemResource.bind(this);
|
||
contentList.setVirtual();
|
||
|
||
if (type == 2)
|
||
this.chooseTeam();
|
||
if (type == 3)
|
||
this.chooseBang();
|
||
if (type == 4)
|
||
this.chooseWorld();
|
||
if (type == 5)
|
||
this.chooseSys();
|
||
|
||
this.initPropPanel();
|
||
}
|
||
|
||
showClear() {
|
||
if (!SKUIUtil.isFGUIValid(this.MainPanel)) return;
|
||
let input = FGUtil.getTextInput(this.MainPanel, "alert/input");
|
||
let tempStr = "";
|
||
if (input)
|
||
tempStr = input.text;
|
||
if (tempStr == "")
|
||
FGUtil.getControl(this.MainPanel, "alert/clear/showClear").selectedIndex = 0;
|
||
else
|
||
FGUtil.getControl(this.MainPanel, "alert/clear/showClear").selectedIndex = 1;
|
||
}
|
||
clearEdit() {
|
||
if (!SKUIUtil.isFGUIValid(this.MainPanel)) return;
|
||
let input = FGUtil.getTextInput(this.MainPanel, "alert/input");
|
||
let tempStr = "";
|
||
if (input)
|
||
tempStr = input.text;
|
||
if (tempStr == "")
|
||
input.requestFocus();
|
||
else {
|
||
input.text = "";
|
||
this.mSendIds = [];
|
||
FGUtil.getControl(this.MainPanel, "alert/clear/showClear").selectedIndex = 0;
|
||
}
|
||
}
|
||
initPropPanel() {
|
||
this.initEmoData();
|
||
this.initGoodsData();
|
||
this.initPetData();
|
||
}
|
||
|
||
|
||
addMsg(info) {
|
||
console.log(info)
|
||
|
||
if (GameModel.player.mapid == 4004 && info.scale == 3) {
|
||
if (GameModel.player.teamid != info.teamid)
|
||
return;
|
||
}
|
||
|
||
// 0世界,1隊伍,2幫派,3系統,5系統撤回,6快訊
|
||
|
||
if (info.scale == 0) {
|
||
this.chatContentObj.world.push(info);
|
||
this.refreshChatList();
|
||
return;
|
||
}
|
||
|
||
if (info.scale == 1) {
|
||
this.chatContentObj.team.push(info);
|
||
this.refreshChatList();
|
||
return;
|
||
}
|
||
|
||
if (info.scale == 2) {
|
||
this.chatContentObj.bang.push(info);
|
||
this.refreshChatList();
|
||
return;
|
||
}
|
||
|
||
if (info.scale == 3) {
|
||
this.chatContentObj.sys.push(info);
|
||
this.refreshChatList();
|
||
return;
|
||
}
|
||
}
|
||
|
||
sendMsg() {
|
||
if (!SKUIUtil.isFGUIValid(this.MainPanel)) return;
|
||
var msg = FGUtil.getComponent(this.MainPanel, "alert/input").text;
|
||
// console.log(msg);
|
||
|
||
// 屏蔽玩家輸入的顏色
|
||
let colorPrefix = /\[color=#([0-9]|[a-f]){6}\]/g;
|
||
let colorSuffix = /\[\/color\]/g;
|
||
msg = msg.replace(colorPrefix, "");
|
||
msg = msg.replace(colorSuffix, "");
|
||
|
||
// console.log(msg)
|
||
|
||
// 道具替換
|
||
let patt1 = /\[[^(@)]*?\]/;
|
||
let pos1 = msg.search(patt1);
|
||
while (pos1 != -1) {
|
||
let matchstr = msg.match(patt1);
|
||
msg = msg.replace(matchstr[0], this.mSendIds.shift());
|
||
pos1 = msg.search(patt1);
|
||
}
|
||
|
||
// 表情替換
|
||
let patt = /(?<!color=)#(?:[0-9]{1,3}|1000)(?!([0-9]|[a-f]))/;
|
||
let pos = msg.search(patt);
|
||
while (pos != -1) {
|
||
let matchstr = msg.match(patt);
|
||
msg = msg.replace(matchstr[0], '[' + matchstr[0].substr(1) + ']');
|
||
pos = msg.search(patt);
|
||
}
|
||
|
||
// console.log(msg)
|
||
|
||
let input = FGUtil.getTextInput(this.MainPanel, "alert/input");
|
||
input.text = "";
|
||
this.mSendIds = [];
|
||
FGUtil.getControl(this.MainPanel, "alert/clear/showClear").selectedIndex = 0;
|
||
|
||
var scale = -1;
|
||
if (this.curChatType == 4)
|
||
scale = 0;
|
||
GameModel.send("c2s_game_chat", {
|
||
scale: scale,
|
||
msg: msg,
|
||
})
|
||
}
|
||
|
||
chooseCur() {
|
||
this.curChatType = 0;
|
||
this.refreshChatList();
|
||
}
|
||
|
||
chooseMy() {
|
||
this.curChatType = 1;
|
||
this.refreshChatList();
|
||
}
|
||
|
||
chooseTeam() {
|
||
this.curChatType = 2;
|
||
this.refreshChatList();
|
||
}
|
||
|
||
chooseBang() {
|
||
this.curChatType = 3;
|
||
if (GameModel.player.bangid == 0)
|
||
FGUtil.getControl(this.MainPanel, "alert/nobang").selectedIndex = 1;
|
||
else
|
||
FGUtil.getControl(this.MainPanel, "alert/nobang").selectedIndex = 0;
|
||
|
||
this.refreshChatList();
|
||
}
|
||
|
||
chooseWorld() {
|
||
this.curChatType = 4;
|
||
console.log(this.chatContentObj)
|
||
this.refreshChatList();
|
||
}
|
||
|
||
chooseSys() {
|
||
this.curChatType = 5;
|
||
this.refreshChatList();
|
||
}
|
||
|
||
getListItemResource(idx: number) {
|
||
// 自己
|
||
if (this.curChatContetnList[idx].roleid == GameModel.player.roleid)
|
||
return "ui://main_ui/player_chat_item_right";
|
||
// 他人
|
||
else
|
||
return "ui://main_ui/player_chat_item_left";
|
||
}
|
||
|
||
initPlayerChatItem(idx, obj: fairygui.GObject) {
|
||
let item = obj.asCom;
|
||
let info = this.curChatContetnList[idx];
|
||
|
||
let coms = item.node.getComponents("customRich");
|
||
|
||
let MsgLg: CustomRich = null;
|
||
if (coms.length == 0)
|
||
MsgLg = item.node.addComponent("customRich");
|
||
else
|
||
MsgLg = coms[0];
|
||
|
||
// 初始化Msg
|
||
MsgLg.initInfo(info.msg, FGUtil.getRichTextField(item, "title/title"));
|
||
|
||
// 頭像
|
||
FGUtil.getLoader(item, "head").texture = GameModel.getRoleHead(info.resid);
|
||
// 名字
|
||
FGUtil.getTextField(item, "name").text = info.name;
|
||
// 顯示頭像框
|
||
this.setHeadBorder(FGUtil.getComponent(item, "head_border"), info.portrait ? info.portrait : 555100);
|
||
// 顯示聊天框
|
||
FGUtil.getLoader(item, "chat_border").url = `ui://main_ui/chat_bell`;
|
||
}
|
||
|
||
refreshChatList() {
|
||
if (!SKUIUtil.isFGUIValid(this.MainPanel)) return;
|
||
FGUtil.getControl(this.MainPanel, "alert/page").selectedIndex = this.curChatType;
|
||
if (this.curChatType == -1) return;
|
||
if (this.curChatType == 0) return;
|
||
if (this.curChatType == 1) return;
|
||
var contentList = FGUtil.getList(this.MainPanel, "alert/list");
|
||
if (this.curChatType == 2) {
|
||
this.curChatContetnList = this.chatContentObj.team;
|
||
contentList.numItems = this.curChatContetnList.length;
|
||
if (contentList.scrollPane.percY == 1)
|
||
contentList.scrollToView(this.curChatContetnList.length - 1);
|
||
return;
|
||
};
|
||
if (this.curChatType == 3) {
|
||
this.curChatContetnList = this.chatContentObj.bang;
|
||
contentList.numItems = this.curChatContetnList.length;
|
||
if (contentList.scrollPane.percY == 1)
|
||
contentList.scrollToView(this.curChatContetnList.length - 1);
|
||
return;
|
||
};
|
||
if (this.curChatType == 4) {
|
||
this.curChatContetnList = this.chatContentObj.world;
|
||
contentList.numItems = this.curChatContetnList.length;
|
||
if (contentList.scrollPane.percY == 1)
|
||
contentList.scrollToView(this.curChatContetnList.length - 1);
|
||
return;
|
||
};
|
||
if (this.curChatType == 5) {
|
||
this.curChatContetnList = this.chatContentObj.sys;
|
||
contentList.numItems = this.curChatContetnList.length;
|
||
if (contentList.scrollPane.percY == 1)
|
||
contentList.scrollToView(this.curChatContetnList.length - 1);
|
||
return;
|
||
};
|
||
}
|
||
|
||
addTeamMsg() {
|
||
var data = {
|
||
bangname: "",
|
||
chargesum: 0,
|
||
level: 105,
|
||
msg: "加入隊伍把(1/5)[img]ui://main_ui/join_team_btn@joinTeam#1688[/img]",
|
||
name: "南夢越",
|
||
onlyid: 11787,
|
||
portrait: 0,
|
||
chatBorder: "bell",
|
||
relive: 1,
|
||
resid: 1111,
|
||
roleid: 462,
|
||
scale: 0,
|
||
teamid: 0,
|
||
voice: -1,
|
||
}
|
||
this.chatContentObj.team.push(data);
|
||
this.refreshChatList();
|
||
}
|
||
addBangMsg() {
|
||
var data = {
|
||
bangname: "測試幫派",
|
||
chargesum: 0,
|
||
level: 105,
|
||
msg: "幫派聊天信息內容",
|
||
name: "南夢越",
|
||
onlyid: 11787,
|
||
portrait: 0,
|
||
relive: 1,
|
||
resid: 1111,
|
||
roleid: 462,
|
||
scale: 0,
|
||
teamid: 0,
|
||
voice: -1,
|
||
}
|
||
this.chatContentObj.bang.push(data);
|
||
this.refreshChatList();
|
||
}
|
||
addWorldMsg() {
|
||
var R = Math.floor(Math.random() * 5)
|
||
var str = "世界聊天[11]信息內容[3]"
|
||
for (let i = 0; i < R; i++) {
|
||
str += str
|
||
}
|
||
var hb = 555100 + R;
|
||
var roleid = Math.random() < 0.5 ? 11787 : GameModel.player.roleid
|
||
var data = {
|
||
bangname: "",
|
||
chargesum: 0,
|
||
level: 105,
|
||
msg: str,
|
||
name: "南夢越",
|
||
onlyid: roleid,
|
||
portrait: hb,
|
||
chatBorder: "bell",
|
||
relive: 1,
|
||
resid: 1111,
|
||
roleid: 462,
|
||
scale: 0,
|
||
teamid: 0,
|
||
voice: -1
|
||
}
|
||
this.chatContentObj.world.push(data);
|
||
this.refreshChatList();
|
||
}
|
||
addSysMsg() {
|
||
var data = {
|
||
bangname: "",
|
||
chargesum: 0,
|
||
level: 105,
|
||
msg: "系統聊天信息內容",
|
||
name: "",
|
||
onlyid: 11787,
|
||
portrait: 0,
|
||
relive: 1,
|
||
resid: 1111,
|
||
roleid: 462,
|
||
scale: 0,
|
||
teamid: 0,
|
||
voice: -1,
|
||
}
|
||
this.chatContentObj.sys.push(data);
|
||
this.refreshChatList();
|
||
}
|
||
|
||
changeOpacity() {
|
||
if (this.isOpacity) {
|
||
// 變成不透明
|
||
var trans: fgui.Transition = FGUtil.getComponent(this.MainPanel, "alert").getTransition("show");
|
||
var trans2: fgui.Transition = FGUtil.getComponent(this.MainPanel, "alert/opacityBtn").getTransition("hide");
|
||
trans.play();
|
||
trans2.play();
|
||
this.isOpacity = false;
|
||
} else {
|
||
var trans: fgui.Transition = FGUtil.getComponent(this.MainPanel, "alert").getTransition("hide");
|
||
var trans2: fgui.Transition = FGUtil.getComponent(this.MainPanel, "alert/opacityBtn").getTransition("show");
|
||
trans.play();
|
||
trans2.play();
|
||
this.isOpacity = true;
|
||
}
|
||
}
|
||
showPropView() {
|
||
if (FGUtil.getComponent(this.MainPanel, "propBg").visible) return;
|
||
var trans: fgui.Transition = this.MainPanel.getTransition("show");
|
||
trans.play();
|
||
FGUtil.getComponent(this.MainPanel, "propBg").visible = true;
|
||
}
|
||
|
||
hidePropView() {
|
||
if (!FGUtil.getComponent(this.MainPanel, "propBg").visible) return;
|
||
var trans: fgui.Transition = this.MainPanel.getTransition("hide");
|
||
trans.play();
|
||
this.scheduleOnce(() => {
|
||
FGUtil.getTextInput(this.MainPanel, "alert/input").requestFocus();
|
||
}, 0.27)
|
||
FGUtil.getComponent(this.MainPanel, "propBg").visible = false;
|
||
}
|
||
/**
|
||
* 關閉聊天面板
|
||
*/
|
||
closeChatPanel() {
|
||
var trans: fgui.Transition = this.MainPanel.getTransition("close");
|
||
trans.play();
|
||
this.scheduleOnce(() => {
|
||
FGUtil.dispose(this.MainPanel);
|
||
this.MainPanel = null;
|
||
}, 0.25)
|
||
}
|
||
|
||
/**
|
||
* 設置頭像框
|
||
* @param headBorderId
|
||
*/
|
||
setHeadBorder(borderCom: fgui.GComponent, headBorderId: number) {
|
||
var data = HeadBorderUtil.getBorderData(headBorderId);
|
||
FGUtil.getLoader(borderCom, "border").url = `ui://main_ui/${data.border}`;
|
||
|
||
var LT = FGUtil.getComponent(borderCom, "LT")
|
||
LT.asLoader.url = `ui://main_ui/${data.addLT}`;
|
||
LT.x = data.LTPos.x;
|
||
LT.y = data.LTPos.y;
|
||
var LB = FGUtil.getComponent(borderCom, "LB")
|
||
LB.asLoader.url = `ui://main_ui/${data.addLB}`;
|
||
LB.x = data.LBPos.x;
|
||
LB.y = data.LBPos.y;
|
||
var RT = FGUtil.getComponent(borderCom, "RT")
|
||
RT.asLoader.url = `ui://main_ui/${data.addRT}`;
|
||
RT.x = data.RTPos.x;
|
||
RT.y = data.RTPos.y;
|
||
var RB = FGUtil.getComponent(borderCom, "RB")
|
||
RB.asLoader.url = `ui://main_ui/${data.addRB}`;
|
||
RB.x = data.RBPos.x;
|
||
RB.y = data.RBPos.y;
|
||
|
||
}
|
||
// 初始化表情
|
||
initEmoData() {
|
||
var emoList = FGUtil.getList(this.MainPanel, "prop/emoList");
|
||
emoList.itemRenderer = this.initEmoItem.bind(this);
|
||
emoList.setVirtual();
|
||
emoList.numItems = 165;
|
||
}
|
||
initEmoItem(idx, obj: fairygui.GObject) {
|
||
let item = obj.asCom;
|
||
var iconName = ("000" + idx.toString()).substr(-3) + "0000";
|
||
FGUtil.getLoader(item, "icon").url = `ui://main_ui/${iconName}`;
|
||
item.node["emoId"] = idx;
|
||
item.onClick(this.tapEmo, this);
|
||
}
|
||
tapEmo(e: Event) {
|
||
var id = 0;
|
||
if (SKDataUtil.hasProperty(e.target, "emoId"))
|
||
id = e.target["emoId"];
|
||
if (!SKUIUtil.isFGUIValid(this.MainPanel)) return;
|
||
let input = FGUtil.getTextInput(this.MainPanel, "alert/input");
|
||
let tempStr = input.text;
|
||
tempStr += `#${id}`;
|
||
input.text = tempStr;
|
||
}
|
||
// 初始化道具
|
||
initGoodsData() {
|
||
let list = [];
|
||
if (GameModel.equipData) {
|
||
let equipData = GameModel.equipData;
|
||
for (const equip of equipData.list) {
|
||
if (equipData.info[equip]) {
|
||
let info = {
|
||
itemid: equip,
|
||
info: GameModel.equipData.info[equip],
|
||
type: 1
|
||
};
|
||
list.push(info);
|
||
}
|
||
}
|
||
for (let key in equipData.use) {
|
||
if (equipData.info[equipData.use[key]]) {
|
||
let info = {
|
||
itemid: equipData.use[key],
|
||
info: GameModel.equipData.info[equipData.use[key]],
|
||
type: 1
|
||
};
|
||
list.push(info);
|
||
}
|
||
}
|
||
}
|
||
let itemList = GameModel.player.itemList;
|
||
for (let itemId in itemList) {
|
||
let count = SKDataUtil.valueForKey(GameModel.player.itemList, itemId);
|
||
if (count != null && count > 0) {
|
||
let info = {
|
||
itemid: itemId,
|
||
count: count,
|
||
type: 0
|
||
};
|
||
list.push(info);
|
||
}
|
||
}
|
||
this.goodsList = list;
|
||
var goodsList = FGUtil.getList(this.MainPanel, "prop/goodList");
|
||
goodsList.itemRenderer = this.initGoodsItem.bind(this);
|
||
goodsList.setVirtual();
|
||
goodsList.numItems = list.length;
|
||
}
|
||
initGoodsItem(idx, obj: fairygui.GObject) {
|
||
let item = obj.asCom;
|
||
let info = this.goodsList[idx];
|
||
|
||
FGUtil.getControl(item, "type").selectedIndex = info.type;
|
||
FGUtil.getControl(item, "mask").selectedIndex = 0;
|
||
FGUtil.getControl(item, "grade").selectedIndex = 0;
|
||
FGUtil.getTextField(item, "title").text = "";
|
||
if (info.type == 0) {
|
||
// 如果是道具
|
||
let data = ItemUtil.getItemData(info.itemid);
|
||
// 未找到該道具信息
|
||
if (data == null) {
|
||
FGUtil.getLoader(item, "icon").texture = ItemUtil.getItemIcon("1000");
|
||
return;
|
||
}
|
||
FGUtil.getLoader(item, "icon").url = `ui://main_ui/${data.icon}`;
|
||
FGUtil.getTextField(item, "title").text = SKDataUtil.transform(info.count);
|
||
item.node["info"] = data;
|
||
item.node["type"] = 0;
|
||
} else if (info.type == 1) {
|
||
// 如果是裝備
|
||
var data = info.info;
|
||
FGUtil.getLoader(item, "icon").url = `ui://main_ui/${data.Shape}`;
|
||
if (ItemUtil.isBaldric(data.EIndex)) {
|
||
FGUtil.getControl(item, "grade").selectedIndex = data.Grade;
|
||
FGUtil.getTextField(item, "title").text = data.Grade.toString();
|
||
if (data.flag == 1 || data.BaseAttr == "[]") {
|
||
FGUtil.getControl(item, "grade").selectedIndex = 0;
|
||
FGUtil.getControl(item, "mask").selectedIndex = 1;
|
||
FGUtil.getTextField(item, "title").text = "";
|
||
}
|
||
}
|
||
else {
|
||
FGUtil.getControl(item, "grade").selectedIndex = 0;
|
||
FGUtil.getTextField(item, "title").text = data.Grade.toString();
|
||
}
|
||
item.node["info"] = data;
|
||
item.node["type"] = 1;
|
||
}
|
||
item.onClick(this.tapGoods, this);
|
||
}
|
||
tapGoods(e: Event) {
|
||
if (!SKDataUtil.hasProperty(e.target, "info") || !SKDataUtil.hasProperty(e.target, "type"))
|
||
return;
|
||
if (!SKUIUtil.isFGUIValid(this.MainPanel)) return;
|
||
let info = e.target["info"];
|
||
let type = e.target["type"];
|
||
|
||
let link = "";
|
||
let input = FGUtil.getTextInput(this.MainPanel, "alert/input");
|
||
let tempStr = input.text;
|
||
if (type == 1) {
|
||
// 裝備
|
||
link = '[' + info.EName + '@' + info.EquipID + '@' + 1 + ']';
|
||
tempStr += `[${info.EName}]`;
|
||
} else {
|
||
// 道具
|
||
link = '[' + info.name + '@' + info.id + '@' + 2 + ']';
|
||
tempStr += `[${info.name}]`;
|
||
}
|
||
this.mSendIds.push(link);
|
||
input.text = tempStr;
|
||
}
|
||
|
||
// 初始化寵物
|
||
initPetData() {
|
||
let petInfo = GameModel.player.petInfo;
|
||
this.petsList = [];
|
||
for (let index = 0; index < petInfo.list.length; index++) {
|
||
let pinfo = petInfo.list[index];
|
||
if (!pinfo || !pinfo.petid) {
|
||
cc.warn(`$警告:召喚獸面板加載列表數據錯誤${index}`);
|
||
continue;
|
||
}
|
||
this.petsList.push(pinfo)
|
||
}
|
||
var petsList = FGUtil.getList(this.MainPanel, "prop/petList");
|
||
petsList.itemRenderer = this.initPetsItem.bind(this);
|
||
petsList.setVirtual();
|
||
petsList.numItems = this.petsList.length;
|
||
}
|
||
initPetsItem(idx, obj: fairygui.GObject) {
|
||
let item = obj.asCom;
|
||
let info = this.petsList[idx];
|
||
|
||
FGUtil.getLoader(item, "item/icon").url = `ui://main_ui/${info.resid || info.resId}`;
|
||
FGUtil.getTextField(item, "name_label").text = info.name;
|
||
FGUtil.getTextField(item, "level_label").text = info.relive + "轉" + info.level + "級";
|
||
FGUtil.getTextField(item, "level_label").color = GameUtil.getReliveColor(info.relive, 1);
|
||
|
||
item.node["info"] = this.petsList[idx];
|
||
item.onClick(this.tapPet, this);
|
||
}
|
||
tapPet(e: Event) {
|
||
if (!SKDataUtil.hasProperty(e.target, "info"))
|
||
return;
|
||
if (!SKUIUtil.isFGUIValid(this.MainPanel)) return;
|
||
let info = e.target["info"];
|
||
|
||
let link = "";
|
||
let input = FGUtil.getTextInput(this.MainPanel, "alert/input");
|
||
let tempStr = input.text;
|
||
link = '[' + info.name + '@' + info.petid + '@' + 3 + ']';
|
||
tempStr += `[${info.name}]`;
|
||
this.mSendIds.push(link);
|
||
input.text = tempStr;
|
||
}
|
||
} |