2025-04-24 17:03:28 +08:00

464 lines
17 KiB
TypeScript

import GameModel from "../core/GameModel";
import FGUtil from "../gear_2.3.4/fgui/FGUtil";
import SKUIUtil from "../gear_2.3.4/util/SKUIUtil";
import MsgAlert from "../game/msg/MsgAlert";
import ItemUtil from "../core/ItemUtil";
import GameUtil from "../core/GameUtil";
import SKDataUtil from "../gear_2.3.4/util/SKDataUtil";
const { ccclass, property } = cc._decorator;
export default class DebateDao extends cc.Component {
/**
* 逐鹿單例實例
*/
public static Instance: DebateDao = null;
/**
* 逐鹿面板
*/
battlePanel: fgui.GComponent = null;
/**
* 排名面板
*/
battleSortPanel: fgui.GComponent = null;
/**
* 勝利面板
*/
battleWinPanel: fgui.GComponent = null;
/**
* 失敗面板
*/
battleLosePanel: fgui.GComponent = null;
/**
* 逐鹿玩法面板
*/
playInfoPanel: fgui.GComponent = null;
/**
* 勝利公告面板
*/
winNoticePanel: fgui.GComponent = null;
/**
* 開啟時間
*/
cutdownTime: number = 0;
/**
* 階段狀態
*/
stageType: number = 0;
/**
* 惡鬼積分
*/
yuanmoScore: number = 0;
/**
* 巔峰積分
*/
peakScore: number = 0;
/**
* 逐鹿積分
*/
zhengdaoScore: number = 0;
/**
* 倒計時函數
*/
cutdownTimeFunc: any = null;
/**
* 排名數據
*/
sortData: any = null;
/**
* 需要加載的預製體
*/
prefabObject: any = {};
onLoad() {
if (DebateDao.Instance === null) {
DebateDao.Instance = this;
// this.loadPrefab();
} else {
this.destroy();
return;
}
}
/**
* 加載預製體
*/
loadPrefab() {
// 加載所需的預製體
var prefabList = [
// { url: "Prefabs/UIRole", name: "UIRole" },
]
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;
}
})
}
}
openDebateDaoPanel() {
if (!this.battlePanel || (this.battlePanel && !this.battlePanel.node && !SKUIUtil.isValid(this.battlePanel.node))) {
this.battlePanel = FGUtil.create("main_ui", "debate_panel");
FGUtil.root().addChild(this.battlePanel);
this.battlePanel.makeFullScreen();
}
FGUtil.getTextField(this.battlePanel, "alert/n2/title").text = "逐鹿之戰"
let zdBtn = FGUtil.getButton(this.battlePanel, "btn/n2");
zdBtn.onClick(this.openDebateDaoInfoPanel, this);
let sortBtn = FGUtil.getButton(this.battlePanel, "alert/n14");
sortBtn.onClick(this.openDebateDaoSortPanel, this);
let leaveBtn = FGUtil.getButton(this.battlePanel, "alert/n15");
leaveBtn.onClick(this.leaveTip, this)
let mask = FGUtil.getComponent(this.battlePanel, "mask");
let close = FGUtil.getComponent(this.battlePanel, "alert/n17");
this.pushCloseDebatePanelEvent(mask);
this.pushCloseDebatePanelEvent(close);
FGUtil.getTextField(this.battlePanel, "btn/n3").text = `惡鬼積分:${this.yuanmoScore}`;
FGUtil.getTextField(this.battlePanel, "btn/n4").text = `逐鹿積分:${this.zhengdaoScore}`;
if (this.stageType == 1 || this.stageType == 3) {
FGUtil.getControl(this.battlePanel, "alert/noWatch").selectedIndex = 1
} else {
FGUtil.getControl(this.battlePanel, "alert/noWatch").selectedIndex = 0
}
this.setTitle(this.stageType);
}
leaveTip() {
MsgAlert.addMsg("本地圖只能通過逐鹿離開")
}
leaveSuccess() {
this.unscheduleAllCallbacks()
if (this.battlePanel)
FGUtil.dispose(this.battlePanel);
this.battlePanel = null;
if (this.battleSortPanel)
FGUtil.dispose(this.battleSortPanel);
this.battleSortPanel = null;
if (this.battleWinPanel)
FGUtil.dispose(this.battleWinPanel);
this.battleWinPanel = null;
if (this.battleLosePanel)
FGUtil.dispose(this.battleLosePanel);
this.battleLosePanel = null;
this.cutdownTime = 0;
this.stageType = 0;
this.yuanmoScore = 0;
this.zhengdaoScore = 0;
this.cutdownTimeFunc = null;
this.sortData = null;
}
setScore(matchScore, satScore, peakScore, type) {
if (!SKUIUtil.isFGUIValid(this.battlePanel)) return;
this.yuanmoScore = matchScore;
this.zhengdaoScore = satScore;
let matchScoreLabel = FGUtil.getTextField(this.battlePanel, "btn/n3")
let satScoreLabel = FGUtil.getTextField(this.battlePanel, "btn/n4")
if (type == 1) {
if (matchScoreLabel)
matchScoreLabel.text = `惡鬼積分:${this.yuanmoScore}`;
} else {
this.peakScore = peakScore;
if (matchScoreLabel)
matchScoreLabel.text = `巔峰積分:${this.peakScore}`;
}
if (satScoreLabel)
satScoreLabel.text = `逐鹿積分:${this.zhengdaoScore}`;
}
updateSayPeakScore(peakScore) {
if (!SKUIUtil.isFGUIValid(this.battlePanel)) return;
this.peakScore = peakScore;
let matchScoreLabel = FGUtil.getTextField(this.battlePanel, "btn/n3")
if (matchScoreLabel)
matchScoreLabel.text = `巔峰積分:${this.peakScore}`;
}
openDebateDaoInfoPanel() {
if (!this.battlePanel || (this.battlePanel && !this.battlePanel.node && !SKUIUtil.isValid(this.battlePanel.node))) {
console.warn("未找到面板");
return;
}
GameModel.send("c2s_say_team_info", {
teamId: GameModel.player.teamid,
})
FGUtil.getControl(this.battlePanel, "show").selectedIndex = 1
}
refreshBattlePanel(data: any = null) {
if (!this.battlePanel || (this.battlePanel && !this.battlePanel.node && !SKUIUtil.isValid(this.battlePanel.node))) {
console.warn("未找到面板");
return;
}
if (data == null) {
console.warn("數據錯誤");
return;
}
var list = FGUtil.getList(this.battlePanel, "alert/n10");
list.removeChildrenToPool();
var teamInfo = JSON.parse(data.teamInfo)
for (let i in teamInfo) {
var item = list.addItem().asCom;
FGUtil.getImage(item, "cap").visible = parseInt(i) == 0 ? true : false;
FGUtil.getLoader(item, "icon").texture = GameModel.getRoleHead(teamInfo[i].resid);
FGUtil.getLoader(item, "race").url = `ui://main_ui/icon_race${teamInfo[i].race}`;
FGUtil.getTextField(item, "name").text = teamInfo[i].name;
FGUtil.getTextField(item, "grade").text = `${teamInfo[i].relive}${teamInfo[i].level}`;
}
}
openDebateDaoSortPanel() {
if (!this.battleSortPanel || (this.battleSortPanel && !this.battleSortPanel.node && !SKUIUtil.isValid(this.battleSortPanel.node))) {
this.battleSortPanel = FGUtil.create("main_ui", "debate_sort_panel");
FGUtil.root().addChild(this.battleSortPanel);
this.battleSortPanel.makeFullScreen();
}
var closeBtn = FGUtil.getButton(this.battleSortPanel, "alert/close")
var mask = FGUtil.getComponent(this.battleSortPanel, "mask")
this.pushCloseEvent(closeBtn, this.battleSortPanel);
this.pushCloseEvent(mask, this.battleSortPanel);
GameModel.send("c2s_say_integral_info", {
type: this.stageType < 3 ? 1 : 0,
});
FGUtil.getTextField(this.battleSortPanel, "alert/n12/title").text = this.stageType < 3 ? "惡鬼" : "逐鹿"
var chooseTypeBtn = FGUtil.getComponent(this.battleSortPanel, "alert/n12");
chooseTypeBtn.onClick(this.showChooseType, this);
var typeBtn1 = FGUtil.getComponent(this.battleSortPanel, "alert/yuanmo");
typeBtn1.node["name"] = "yuanmo"
var typeBtn2 = FGUtil.getComponent(this.battleSortPanel, "alert/zhengdao");
typeBtn2.node["name"] = "zhengdao"
typeBtn1.onClick(this.chooseType, this);
typeBtn2.onClick(this.chooseType, this);
var list = FGUtil.getList(this.battleSortPanel, "alert/list");
// 設置初始化方法
list.itemRenderer = this.initSortItem.bind(this);
// 虛擬列表
list.setVirtual();
}
showChooseType() {
if (!this.battleSortPanel || (this.battleSortPanel && !this.battleSortPanel.node && !SKUIUtil.isValid(this.battleSortPanel.node))) {
console.warn("未找到面板");
return;
}
FGUtil.getControl(this.battleSortPanel, "alert/showChose").selectedIndex = 1;
}
chooseType(e: Event) {
var idx = "yuanmo";
if (e && e.target && e.target["name"])
idx = e.target["name"];
if (!this.battleSortPanel || (this.battleSortPanel && !this.battleSortPanel.node && !SKUIUtil.isValid(this.battleSortPanel.node))) {
console.warn("未找到面板");
return;
}
FGUtil.getControl(this.battleSortPanel, "alert/showChose").selectedIndex = 0;
if (idx == "yuanmo") {
GameModel.send("c2s_say_integral_info", {
type: 1,
});
FGUtil.getTextField(this.battleSortPanel, "alert/n12/title").text = "惡鬼"
} else {
GameModel.send("c2s_say_integral_info", {
type: 0,
});
FGUtil.getTextField(this.battleSortPanel, "alert/n12/title").text = "逐鹿"
}
}
refreshSortPanel(data: any = null) {
this.sortData = JSON.parse(data);
if (!this.battleSortPanel || (this.battleSortPanel && !this.battleSortPanel.node && !SKUIUtil.isValid(this.battleSortPanel.node))) {
console.warn("未找到面板");
return;
}
if (data == null) {
console.warn("數據錯誤");
return;
}
var list = FGUtil.getList(this.battleSortPanel, "alert/list");
// 虛擬列表更新
list.numItems = this.sortData.length;
}
initSortItem(idx, obj: fairygui.GObject) {
var item = obj.asCom;
if (idx < 3) {
// 前三名
FGUtil.getControl(item, "sort").selectedIndex = idx + 1;
} else {
FGUtil.getControl(item, "sort").selectedIndex = 0;
FGUtil.getTextField(item, "index_tf").text = (idx + 1).toString();
}
FGUtil.getRichTextField(item, "name_rt").text = this.sortData[idx].captainName;
FGUtil.getTextField(item, "two_tf").text = this.sortData[idx].score.toString();
var teamInfo = JSON.parse(this.sortData[idx].teamInfo);
FGUtil.getControl(item, "num").selectedIndex = teamInfo.length - 1;
for (let i in teamInfo) {
FGUtil.getLoader(item, `h${i}/icon`).texture = GameModel.getRoleHead(teamInfo[i].resid);
}
}
setCutDownTime(t: number = 0) {
this.unscheduleAllCallbacks();
this.cutdownTimeFunc = function () {
if (this.cutdownTime <= 0) {
this.unschedule(this.cutdownTimeFunc);
}
this.cutdownTime -= 1000;
if (this.cutdownTime < 0) this.cutdownTime = 0;
if (this.battlePanel && this.battlePanel.node) {
var t = Math.floor(this.cutdownTime / 1000);
var m = Math.floor(t / 60);
var s = t % 60;
FGUtil.getTextField(this.battlePanel, "alert/n12").text = `準備中\n還有${m}:${s}開始`;
}
}
this.cutdownTime = t;
this.schedule(this.cutdownTimeFunc, 1)
}
setTitle(type) {
this.stageType = type;
var str = "";
switch (type) {
case 1: str = "惡鬼競賽(備戰)"; break;
case 2: str = "惡鬼競賽"; break;
case 3: str = "巔峰對決(備戰)"; break;
case 4: str = "巔峰對決"; break;
default: str = "逐鹿";
}
if (this.battlePanel && this.battlePanel.node)
FGUtil.getTextField(this.battlePanel, "alert/n6").text = str;
}
openWinPanel(data) {
if (!this.battleWinPanel || (this.battleWinPanel && !this.battleWinPanel.node && !SKUIUtil.isValid(this.battleWinPanel.node))) {
this.battleWinPanel = FGUtil.create("main_ui", "crosspk_war_win_panel");
FGUtil.root().addChild(this.battleWinPanel);
this.battleWinPanel.makeFullScreen();
}
FGUtil.getRichTextField(this.battleWinPanel, "alert/n15").text = `${data.exp}`;
FGUtil.getRichTextField(this.battleWinPanel, "alert/n17").text = `${data.petExp}`;
FGUtil.getRichTextField(this.battleWinPanel, "alert/n19").text = `${data.score}`;
var icon = ItemUtil.getItemData(data.icon).icon;
FGUtil.getLoader(this.battleWinPanel, "alert/item/icon").url = `ui://main_ui/${icon}`;
let closeBtn = FGUtil.getComponent(this.battleWinPanel, "alert/mask")
let mask = FGUtil.getComponent(this.battleWinPanel, "mask")
this.pushCloseEvent(closeBtn, this.battleWinPanel);
this.pushCloseEvent(mask, this.battleWinPanel);
this.scheduleOnce(() => {
if (this.battleWinPanel && this.battleWinPanel.node) {
FGUtil.dispose(this.battleWinPanel);
}
}, 3)
}
openLosePanel(data) {
if (!this.battleLosePanel || (this.battleLosePanel && !this.battleLosePanel.node && !SKUIUtil.isValid(this.battleLosePanel.node))) {
this.battleLosePanel = FGUtil.create("main_ui", "crosspk_war_lose_panel");
FGUtil.root().addChild(this.battleLosePanel);
this.battleLosePanel.makeFullScreen();
}
FGUtil.getRichTextField(this.battleLosePanel, "alert/n15").text = `${data.exp}`;
FGUtil.getRichTextField(this.battleLosePanel, "alert/n17").text = `${data.petExp}`;
FGUtil.getRichTextField(this.battleLosePanel, "alert/n19").text = `${data.score}`;
var icon = ItemUtil.getItemData(data.icon).icon;
FGUtil.getLoader(this.battleLosePanel, "alert/item/icon").url = `ui://main_ui/${icon}`;
let closeBtn = FGUtil.getComponent(this.battleLosePanel, "alert/mask")
let mask = FGUtil.getComponent(this.battleLosePanel, "mask")
this.pushCloseEvent(closeBtn, this.battleLosePanel);
this.pushCloseEvent(mask, this.battleLosePanel);
this.scheduleOnce(() => {
if (this.battleLosePanel && this.battleLosePanel.node) {
FGUtil.dispose(this.battleLosePanel);
}
}, 3)
}
openPlayInfo(index) {
if (!this.playInfoPanel || (this.playInfoPanel && !this.playInfoPanel.node && !SKUIUtil.isValid(this.playInfoPanel.node))) {
this.playInfoPanel = FGUtil.create("main_ui", "play_info_panel");
FGUtil.root().addChild(this.playInfoPanel);
this.playInfoPanel.makeFullScreen();
}
let closeBtn = FGUtil.getButton(this.playInfoPanel, "alert/close");
let mask = FGUtil.getComponent(this.playInfoPanel, "mask");
this.pushCloseEvent(closeBtn, this.playInfoPanel);
this.pushCloseEvent(mask, this.playInfoPanel);
let rT = FGUtil.getRichTextField(this.playInfoPanel, "alert/info/title");
let info = GameModel.conf_playing_method[index];
let str = "";
if (info && SKDataUtil.hasProperty(info, "content")) {
str = info.content;
}
rT.text = str;
if (info && SKDataUtil.hasProperty(info, "bg")) {
FGUtil.getControl(this.playInfoPanel, "alert/bg").selectedIndex = info.bg;
}
}
/**
* 打開胜利公告面板
* info=[{ name: "玩家名字", relive: 3, level: 11, resid: 1101 },
* { name: "玩家名字", relive: 3, level: 11, resid: 1101 }])
*/
openWinNoticePanel(info: any = null) {
var num = info.length;
if (!SKUIUtil.isFGUIValid(this.winNoticePanel)) {
this.winNoticePanel = FGUtil.create("main_ui", "win_notice_panel");
FGUtil.getControl(this.winNoticePanel, "alert/type").selectedIndex = num - 1;
FGUtil.root().addChild(this.winNoticePanel);
this.winNoticePanel.makeFullScreen();
FGUtil.getComponent(this.winNoticePanel, "alert/n67").visible = false;
}
var alert = FGUtil.getComponent(this.winNoticePanel, "alert");
for (let i = 1; i <= num; i++) {
FGUtil.getLoader(alert, `l${num}/role${i}`).texture = GameModel.getRolePosterHead(info[i - 1].resid);
FGUtil.getTextField(alert, `l${num}/name${i}`).text = info[i - 1].name;
FGUtil.getRichTextField(alert, `l${num}/level${i}`).text = GameUtil.getReliveRichText(info[i - 1].relive, info[i - 1].level);
}
var mask = FGUtil.getComponent(this.winNoticePanel, "mask");
this.pushCloseEvent(mask, this.winNoticePanel);
}
/**
* 添加關閉事件
*/
pushCloseDebatePanelEvent(item: fairygui.GComponent) {
item.clearClick();
item.onClick(() => {
FGUtil.getControl(this.battlePanel, "show").selectedIndex = 0;
}, this)
}
/**
* 添加關閉事件
*/
pushCloseEvent(item: fairygui.GComponent, target: fairygui.GComponent, call: Function = null) {
item.clearClick();
item.onClick(() => {
call && call()
FGUtil.dispose(target);
target = null;
}, this)
}
}