185 lines
6.0 KiB
TypeScript
185 lines
6.0 KiB
TypeScript
import GameModel from "../core/GameModel";
|
|
import SkillUtil from "../game/skill/core/SkillUtil";
|
|
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";
|
|
|
|
const { ccclass, property } = cc._decorator;
|
|
export default class BtlInfo extends cc.Component {
|
|
|
|
/**
|
|
* 戰鬥指令單例實例
|
|
*/
|
|
public static Instance: BtlInfo = null;
|
|
|
|
/**
|
|
* 戰鬥指令面板
|
|
*/
|
|
btlInfoPanel: fgui.GComponent = null;
|
|
|
|
/**
|
|
* 戰鬥回合
|
|
*/
|
|
btlRound: number = 0;
|
|
|
|
/**
|
|
* 戰鬥信息
|
|
*/
|
|
btlInfoList: any = [];
|
|
btlInfoEazyList: any = [];
|
|
/**
|
|
* 顯示詳細戰鬥指令
|
|
*/
|
|
showMoreInfo: Boolean = true;
|
|
|
|
/**
|
|
* 需要加載的預製體
|
|
*/
|
|
prefabObject: any = {};
|
|
|
|
|
|
onLoad() {
|
|
if (BtlInfo.Instance === null) {
|
|
BtlInfo.Instance = this;
|
|
this.loadPrefab();
|
|
} else {
|
|
this.destroy();
|
|
return;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 加載預製體
|
|
*/
|
|
loadPrefab() {
|
|
// 加載所需的預製體
|
|
var prefabList = [
|
|
{ url: "Prefabs/SkillDetail", name: "SkillDetail" },
|
|
]
|
|
this.prefabObject = {}
|
|
for (let item of prefabList) {
|
|
cc.loader.loadRes(item.url, cc.Prefab, (err, prefab) => {
|
|
if (err)
|
|
console.warn(err);
|
|
else {
|
|
this.prefabObject[item.name] = prefab;
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
openBtlInfoPanel() {
|
|
if (!this.btlInfoPanel || (this.btlInfoPanel && !this.btlInfoPanel.node && !SKUIUtil.isValid(this.btlInfoPanel.node))) {
|
|
this.btlInfoPanel = FGUtil.create("main_ui", "btl_info_panel");
|
|
FGUtil.root().addChild(this.btlInfoPanel);
|
|
this.btlInfoPanel.makeFullScreen();
|
|
}
|
|
|
|
let showMoreBtn = FGUtil.getButton(this.btlInfoPanel, "alert/check");
|
|
showMoreBtn.clearClick()
|
|
showMoreBtn.onClick(() => {
|
|
this.showMoreInfo = !this.showMoreInfo;
|
|
FGUtil.getControl(this.btlInfoPanel, "alert/check/selected").selectedIndex = this.showMoreInfo ? 1 : 0;
|
|
let infoList = FGUtil.getList(this.btlInfoPanel, "alert/list");
|
|
infoList.numItems = this.showMoreInfo ? this.btlInfoList.length : this.btlInfoEazyList.length;
|
|
|
|
let bui = cc.find('Canvas/BattleUILayer/BattleUI');
|
|
var btlUIlogic = bui.getComponent('BattleUI');
|
|
btlUIlogic.dontShowMoreBtlInfo()
|
|
}, this)
|
|
FGUtil.getControl(this.btlInfoPanel, "alert/check/selected").selectedIndex = this.showMoreInfo ? 1 : 0;
|
|
|
|
// 指令列表
|
|
let infoList = FGUtil.getList(this.btlInfoPanel, "alert/list");
|
|
// 設置初始化方法
|
|
infoList.itemRenderer = this.initInfoItem.bind(this);
|
|
// 虛擬列表
|
|
infoList.setVirtual();
|
|
infoList.numItems = this.showMoreInfo ? this.btlInfoList.length : this.btlInfoEazyList.length;
|
|
|
|
var mask = FGUtil.getComponent(this.btlInfoPanel, "mask");
|
|
var close = FGUtil.getButton(this.btlInfoPanel, "alert/close");
|
|
this.pushCloseEvent(mask, this.btlInfoPanel);
|
|
this.pushCloseEvent(close, this.btlInfoPanel);
|
|
}
|
|
|
|
|
|
initInfoItem(idx, obj: fairygui.GObject) {
|
|
let item = obj.asCom;
|
|
let rc = FGUtil.getRichTextField(item, "title")
|
|
rc.linkUnderline = false;
|
|
rc.text = this.showMoreInfo ? this.btlInfoList[idx].msg : this.btlInfoEazyList[idx].msg;
|
|
rc.on(fgui.Event.LINK, this.onClickLink, this);
|
|
}
|
|
|
|
onClickLink(href) {
|
|
if (href[0] == "@") {
|
|
var id = href.substring(1)
|
|
console.log("角色", id)
|
|
if (id != 0)
|
|
GameModel.send("c2c_goods_info", { type: 3, id: id.toString() });
|
|
} else if (href[0] == "#") {
|
|
var id = href.substring(1)
|
|
console.log("技能", id)
|
|
this.addSkillItem(id)
|
|
} else if (href[0] == "*") {
|
|
var id = href.substring(1)
|
|
console.log("道具", id)
|
|
GameModel.send("c2c_goods_info", { type: 2, id: id.toString() });
|
|
}
|
|
}
|
|
|
|
addSkillItem(itemInfo) {
|
|
if (itemInfo != null && this.prefabObject["SkillDetail"] != null) {
|
|
let detail = cc.instantiate(this.prefabObject["SkillDetail"]);
|
|
detail.parent = this.btlInfoPanel.node;
|
|
detail.setPosition(this.btlInfoPanel.node.width / 2, -this.btlInfoPanel.node.height / 2)
|
|
detail.name = 'SkillDetail';
|
|
detail.getComponent('SkillDetail').loadInfo(itemInfo);
|
|
}
|
|
}
|
|
/**
|
|
* 添加戰鬥指令信息
|
|
*/
|
|
addInfo(msg) {
|
|
this.btlInfoList.push(msg)
|
|
if (this.btlInfoPanel && this.btlInfoPanel.node && SKUIUtil.isValid(this.btlInfoPanel.node)) {
|
|
let infoList = FGUtil.getList(this.btlInfoPanel, "alert/list");
|
|
infoList.numItems = this.showMoreInfo ? this.btlInfoList.length : this.btlInfoEazyList.length;
|
|
}
|
|
}
|
|
addRoundInfo() {
|
|
if (this.btlRound > 0) {
|
|
var msg = { type: 2, msg: `第[color=#FA8C82]${this.btlRound}[/color]回合結束` }
|
|
this.btlInfoList.push(msg)
|
|
this.btlInfoEazyList.push(msg)
|
|
}
|
|
this.btlRound++
|
|
var msg = { type: 2, msg: `第[color=#FA8C82]${this.btlRound}[/color]回合開始` }
|
|
this.btlInfoList.push(msg)
|
|
this.btlInfoEazyList.push(msg)
|
|
if (this.btlInfoPanel && this.btlInfoPanel.node && SKUIUtil.isValid(this.btlInfoPanel.node)) {
|
|
let infoList = FGUtil.getList(this.btlInfoPanel, "alert/list");
|
|
infoList.numItems = this.showMoreInfo ? this.btlInfoList.length : this.btlInfoEazyList.length;
|
|
}
|
|
}
|
|
/**
|
|
* 關閉面板
|
|
*/
|
|
closePanel() {
|
|
this.btlInfoList = [];
|
|
this.btlInfoEazyList = [];
|
|
FGUtil.dispose(this.btlInfoPanel);
|
|
}
|
|
/**
|
|
* 添加關閉事件
|
|
*/
|
|
pushCloseEvent(item: fairygui.GComponent, target: fairygui.GComponent, call: Function = null) {
|
|
item.clearClick();
|
|
item.onClick(() => {
|
|
call && call()
|
|
FGUtil.dispose(target);
|
|
}, this)
|
|
}
|
|
}
|