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

185 lines
5.4 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import GameModel from "../core/GameModel";
import ItemUtil from "../core/ItemUtil";
import MsgAlert from "../game/msg/MsgAlert";
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";
import SKTimeUtil from "../../ts/gear_2.3.4/util/SKTimeUtil";
const { ccclass, property } = cc._decorator;
export default class TianTiPanel extends cc.Component {
/**
* 轉盤單例實例
*/
public static Instance: TianTiPanel = null;
/**
* 是否已加入隊伍
*/
hasTeam: Boolean = false;
/**
* 隊伍ID
*/
teamId: number = 0;
/**
* 是否為隊長
*/
isLeader: Boolean = false;
/**
* 天梯面板
*/
ManiPanel: fgui.GComponent = null;
/**
* 天梯面板总节点
*/
alrt: fgui.GComponent = null;
countDownTime: number = 13;
quxiaopipei: fgui.GButton = null;
/**阻止點擊 */
stopTap: boolean = false;
timestr: fgui.GTextField
count = 0;
callback: Function = null;
/**
* 需要加載的預製體
*/
prefabObject: any = {};
onLoad() {
if (TianTiPanel.Instance === null) {
TianTiPanel.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;
}
})
}
}
/**
* 打開天梯面板
*/
openTianTiPiPeiPanel(refresh: boolean = false, data: any = null) {
if (!this.ManiPanel || (this.ManiPanel && !this.ManiPanel.node && !SKUIUtil.isValid(this.ManiPanel.node))) {
this.ManiPanel = FGUtil.create("main_ui", "pipei");//面板
FGUtil.root().addChild(this.ManiPanel);
this.ManiPanel.makeFullScreen();
}
// 設置是否有隊伍、是否為隊長;關閉速度顯示 B
this.isLeader = GameModel.player.isleader;
this.teamId = GameModel.player.teamid;
this.hasTeam = this.teamId > 0;
this.quxiaopipei = FGUtil.getButton(this.ManiPanel, `n0/quxiaopipei`);
this.pushCloseEvent(this.quxiaopipei, this.ManiPanel, () => {//取消匹配
GameModel.send('c2s_tianfu_quxiao', {
roleid: GameModel.player.roleid,
});
});
this.timestr = FGUtil.getTextField(this.ManiPanel, `n0/TIME`);
var memberList = GameModel.player.teamInfo.objlist;
for (let i in memberList) {
//頭像
// FGUtil.getLoader(this.ManiPanel, `n0/L${i}`).texture = GameModel.getRoleHead(memberList[i].resid);
FGUtil.getLoader(this.ManiPanel, `n0/L${i}`).url = `ui://main_ui/roleB_${memberList[i].resid}`
FGUtil.getTextField(this.ManiPanel, `n0/N${i}`).text = `${memberList[i].name}`
}
this.timestr.text = `匹配中。 。 。 `
}
reShow(data: any) {
this.timestr.text = `匹配成功! `
let teamS = data.teamS;
let teamE = data.teamE;
for (const indx in teamS) {
let valuestr = teamS[indx];
console.log(valuestr.resid)
console.log(valuestr.name)
console.log(valuestr.level)
FGUtil.getLoader(this.ManiPanel, `n0/L${indx}`).url = `ui://main_ui/roleB_${valuestr.resid}`
// FGUtil.getLoader(this.ManiPanel, `n0/L${indx}`).texture = GameModel.getRoleHead(valuestr.resid);
FGUtil.getTextField(this.ManiPanel, `n0/N${indx}`).text = `${valuestr.name}`
}
for (const indx in teamE) {
let valuestr = teamE[indx];
console.log(valuestr.resid)
console.log(valuestr.name)
console.log(valuestr.level)
FGUtil.getLoader(this.ManiPanel, `n0/LL${indx}`).url = `ui://main_ui/roleB_${valuestr.resid}`
// FGUtil.getLoader(this.ManiPanel, `n0/LL${indx}`).texture = GameModel.getRoleHead(valuestr.resid);
FGUtil.getTextField(this.ManiPanel, `n0/NN${indx}`).text = `${valuestr.name}`
}
this.count = 10;
//10秒倒計時
//interval -以秒為單位的Tick間隔。 0表示每幀打勾。 (人話:多久執行一次
//repeat -選擇器將被執行(重複+ 1)次你可以使用cc.macro。 REPEAT_FOREVER表示無限滴答。 (人話:總共執行多少次)
this.unschedule(this.task1);
this.schedule(this.task1, 1, 10, 1);
}
task1() {
this.count = this.count - (1);
console.log("執行任務1開始==", this.count);
this.timestr.text = `${this.count}`
if (this.count <= 0) {
console.log("倒計時完成");
this.unschedule(this.task1);
FGUtil.dispose(this.ManiPanel);
}
}
/**
* 添加關閉事件
*/
pushCloseEvent(item: fairygui.GComponent, target: fairygui.GComponent, call: Function = null) {
item.clearClick();
item.onClick(() => {
if (this.stopTap) return
call && call();
FGUtil.dispose(target);
}, this)
}
}