import GameModel from "../core/GameModel"; import GameUtil from "../core/GameUtil"; 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"; const { ccclass, property } = cc._decorator; export default class TianTiPanel extends cc.Component { /** * 轉盤單例實例 */ public static Instance: TianTiPanel = null; /** * 勝利面板 */ battleWinPanel: fgui.GComponent = null; /** * 失敗面板 */ battleLosePanel: fgui.GComponent = null; /** * 天梯面板 */ ManiPanel: fgui.GComponent = null; /** * 天梯面板总节点 */ alrt: fgui.GComponent = null; /**戰況節點 */ zhankuang: fgui.GComponent = null; /**獎勵節點 */ jiangli: fgui.GComponent = null; /**頭像節點 */ head: fgui.GLoader = null; /**勝場 */ shengchang: fgui.GTextField = null; /**敗場 */ baichang: fgui.GTextField = null; /**積分 */ jifen: fgui.GTextField = null; /**排名 */ paiming: fgui.GTextField = null; //角色節點 com1: fgui.GComponent = null; com2: fgui.GComponent = null; com3: fgui.GComponent = null; com4: fgui.GComponent = null; com5: fgui.GComponent = null; //排行信息 com1name: fgui.GTextField = null; com2name: fgui.GTextField = null; com3name: fgui.GTextField = null; com4name: fgui.GTextField = null; com5name: fgui.GTextField = null; com1jifen: fgui.GTextField = null; com2jifen: fgui.GTextField = null; com3jifen: fgui.GTextField = null; com4jifen: fgui.GTextField = null; com5jifen: fgui.GTextField = null; //按鈕 com1btn: fgui.GButton = null; com2btn: fgui.GButton = null; com3btn: fgui.GButton = null; com4btn: fgui.GButton = null; com5btn: fgui.GButton = null; /**進入天梯地圖 */ jinMAPBTN: fgui.GButton = null; /**真實天梯積分 */ tiantijifen: fgui.GTextField = null; /**天梯時間 */ shijian: fgui.GTextField = null; /**戰況標籤按鈕 */ zhankuangBtn: fgui.GButton = null; /**戰況標籤按鈕 */ jiangliBtn: fgui.GButton = null; /**兌換按鈕 */ buyBtn: fgui.GButton = null; /**獎勵list */ jiangliList: fgui.GList = null; itemList: any = {}; /**阻止點擊 */ stopTap: boolean = false; /** * 花費類型 0 風雨寶箱 1免費 2單次 3五連抽 */ coastType: number = -1; /** * 需要加載的預製體 */ 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; } }) } } /** * 打開天梯面板 */ openTianTiPanel(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", "TianTIPanel");//面板 this.alrt = FGUtil.getComponent(this.ManiPanel, "alrt");//總節點 this.zhankuang = FGUtil.getComponent(this.alrt, "zhankuang");//戰況節點 this.jiangli = FGUtil.getComponent(this.alrt, "jiangli");//獎勵節點 FGUtil.root().addChild(this.ManiPanel); this.ManiPanel.makeFullScreen(); } // 刷新顯示數據 if (refresh) { if (data == null) { console.warn("天梯數據錯誤") return } // 刷新天梯數據 this.Refreshpandel(data); return; } // 關閉按鈕 // let closeBtn = FGUtil.getButton(this.ManiPanel, "alert/close") let closeBtn = FGUtil.getButton(this.alrt, "close") this.pushCloseEvent(closeBtn, this.ManiPanel, () => { this.unscheduleAllCallbacks() }); //頭像 this.head = FGUtil.getLoader(this.zhankuang, "head"); this.head.url = `ui://main_ui/role_${GameModel.player.resid}` //暱稱 FGUtil.getTextField(this.zhankuang, "nicheng").text = `${GameModel.player.name}` //等級 FGUtil.getTextField(this.zhankuang, "dengji").text = `${GameModel.player.level}` /**勝場 */ this.shengchang = FGUtil.getTextField(this.zhankuang, "shengchang") this.shengchang.text = '0'; /**敗場 */ this.baichang = FGUtil.getTextField(this.zhankuang, "baichang") this.baichang.text = '0'; /**積分 */ this.jifen = FGUtil.getTextField(this.zhankuang, "jifen") this.jifen.text = '0'; //天梯時間 this.shijian = FGUtil.getTextField(this.zhankuang, "n20") /**排名 */ this.paiming = FGUtil.getTextField(this.zhankuang, "paiming") this.paiming.text = '0'; //獎勵界面 this.jiangliList = FGUtil.getList(this.jiangli, "list");//獎勵list this.tiantijifen = FGUtil.getTextField(this.jiangli, "jifen");//自己的真實積分 this.buyBtn = FGUtil.getButton(this.jiangli, "buybnt");//兌換按鈕 this.buyBtn.onClick(this.onClickDuiHuan, this); this.tiantijifen.text = `當前擁有真實積分:${GameModel.player.tianti_integral}`; //角色節點 this.com1 = FGUtil.getComponent(this.zhankuang, "com1"); this.com2 = FGUtil.getComponent(this.zhankuang, "com2"); this.com3 = FGUtil.getComponent(this.zhankuang, "com3"); this.com4 = FGUtil.getComponent(this.zhankuang, "com4"); this.com5 = FGUtil.getComponent(this.zhankuang, "com5"); //排行信息 this.com1name = FGUtil.getTextField(this.zhankuang, "com1name"); this.com1name.text = '虚位以待'; this.com2name = FGUtil.getTextField(this.zhankuang, "com2name"); this.com2name.text = '虚位以待'; this.com3name = FGUtil.getTextField(this.zhankuang, "com3name"); this.com3name.text = '虚位以待'; this.com4name = FGUtil.getTextField(this.zhankuang, "com4name"); this.com4name.text = '虚位以待'; this.com5name = FGUtil.getTextField(this.zhankuang, "com5name"); this.com5name.text = '虚位以待'; this.com1jifen = FGUtil.getTextField(this.zhankuang, "com1jifen"); this.com1jifen.text = '0'; this.com2jifen = FGUtil.getTextField(this.zhankuang, "com2jifen"); this.com2jifen.text = '0'; this.com3jifen = FGUtil.getTextField(this.zhankuang, "com3jifen"); this.com3jifen.text = '0'; this.com4jifen = FGUtil.getTextField(this.zhankuang, "com4jifen"); this.com4jifen.text = '0'; this.com5jifen = FGUtil.getTextField(this.zhankuang, "com5jifen"); this.com5jifen.text = '0'; this.com1btn = FGUtil.getButton(this.zhankuang, "com1btn"); this.com2btn = FGUtil.getButton(this.zhankuang, "com2btn"); this.com3btn = FGUtil.getButton(this.zhankuang, "com3btn"); this.com4btn = FGUtil.getButton(this.zhankuang, "com4btn"); this.com5btn = FGUtil.getButton(this.zhankuang, "com5btn"); // FGUtil.getButton(this.jiangli, "com1btn"); this.jinMAPBTN = FGUtil.getButton(this.zhankuang, "jinMAPBTN"); this.jinMAPBTN.onClick(this.entrMap, this); FGUtil.getButton(this.alrt, "JiangLiBtn").onClick(() => { this.initshop(false, null); }, this); //請求排行榜數據 GameModel.send("c2s_ask_TianTi_info", { type: 1, genre: 0 }) } // 傳送到指定打架地圖 entrMap() { let mapId = 4006; console.log('跳轉地圖' + mapId) let comMapLogic = cc.find('Canvas/MapUI').getComponent('GameMapLogic'); comMapLogic.changeMap(mapId); this.unscheduleAllCallbacks() FGUtil.dispose(this.ManiPanel) } // 只刷新次數顯示 Refreshpandel(data) { this.shengchang.text = `${data.shengchang}`; /**敗場 */ this.baichang.text = `${data.baichang}`; /**積分 */ this.jifen.text = `${data.selfjifen}`; /**排名 */ this.paiming.text = `${data.selfpaiming}`; this.tiantijifen.text = `當前擁有真實積分:${data.tiantijizhenshifen}`; this.shijian.text = `本賽季結束時間:每月最後一天23時59分50秒`; let list = SKDataUtil.jsonBy(data.list); for (const key in list) { if (Object.prototype.hasOwnProperty.call(list, key)) { const element = list[key]; console.log(key) switch (Number(key)) { case 0: this.addUIRole(this.com1.node, element.resid, element.wingId, element.effid); this.com1name.text = element.name; this.com1jifen.text = `${element.jifen}`; break; case 1: this.addUIRole(this.com2.node, element.resid, element.wingId, element.effid); this.com2name.text = element.name; this.com2jifen.text = `${element.jifen}`; break; case 2: this.addUIRole(this.com3.node, element.resid, element.wingId, element.effid); this.com3name.text = element.name; this.com3jifen.text = `${element.jifen}`; break; case 3: this.addUIRole(this.com4.node, element.resid, element.wingId, element.effid); this.com4name.text = element.name; this.com4jifen.text = `${element.jifen}`; break; case 4: this.addUIRole(this.com5.node, element.resid, element.wingId, element.effid); this.com5name.text = element.name; this.com5jifen.text = `${element.jifen}`; break; } } } } //點擊兌換獎勵 onClickDuiHuan() { if (this.jiangliList.selectedIndex < 0) { MsgAlert.addMsg('請選擇需要兌換的物品') } let Cell = this.jiangliList.getChildAt(this.jiangliList.selectedIndex); let data = Cell.node["data"]; console.log(`點擊兌換獎勵:` + data.name + `積分:` + GameModel.player.tianti_integral + '價格:' + data.price) if (GameModel.player.tianti_integral >= data.price) { GameModel.send('c2s_TianTi_buy', { roleid: GameModel.player.roleid, selfjifen: GameModel.player.tianti_integral, itemid: data.itemid, price: data.price, name: data.name, }) GameModel.player.tianti_integral -= data.price; this.tiantijifen.text = `當前擁有真實積分:${GameModel.player.tianti_integral}`; } else ( MsgAlert.addMsg(`你的天梯積分不足以兌換${data.name}`) ) } initshop(refresh: boolean = false, data: any = null) { // 刷新顯示數據 if (refresh) { if (data == null) { console.warn("天梯獎勵數據錯誤") return } this.jiangliList.removeChildrenToPool(); //移除列表 let list = SKDataUtil.jsonBy(data.jiangli); for (const key in list) { if (Object.prototype.hasOwnProperty.call(list, key)) { const element = list[key]; if (element.name) { let item = ItemUtil.getItemData(element.itemid); let cell: fgui.GComponent; cell = this.jiangliList.addItemFromPool().asCom; FGUtil.getLoader(cell, "icon").url = `ui://main_ui/${item.icon}`; FGUtil.getTextField(cell, "title").text = `${element.name}`; FGUtil.getTextField(cell, "price").text = `${element.price}`; FGUtil.getTextField(cell, "des").text = `${element.des}`; cell.node["data"] = element; } } } this.jiangliList.selectedIndex = 0; return; } //請求獎勵數據 GameModel.send("c2s_ask_TianTijiangli_info", { roleid: GameModel.player.roleid }) } /** * 添加人物UI */ addUIRole(pNode, resid, wingId, effid) { if (!pNode) return; // var childs=pNode.node.childNodes; // for(var i=childs.length-1;i>=0;i--){ // pNode.node.removeChild(childs.item(i)); if (this.prefabObject["UIRole"] == null) { cc.loader.loadRes("Prefabs/UIRole", cc.Prefab, (err, prefab) => { if (err) console.warn(err); else { this.prefabObject["UIRole"] = prefab; this.addUIRole(pNode, resid, wingId, effid) } }) return } var roleNode: cc.Node = cc.instantiate(this.prefabObject["UIRole"]); roleNode.parent = pNode; roleNode.setPosition(0, 55) // var info = ItemUtil.getItemData(id).json // if (!info) { // console.warn("寵物信息錯誤,寵物id:" + id) // return // } // var key = JSON.parse(info).petid; // if (SKDataUtil.hasProperty(GameModel.conf_role, resid)) { // let resid = GameModel.conf_role[resid].resid; roleNode.getComponent("UIRole").setInfo({ resid: resid, name: '', petcolor: 0, wingId: SKDataUtil.findByDict(GameModel.game_conf.wing, "resid", wingId, "id", 0), bodyEffectId: effid }) roleNode.getComponent("UIRole").offTouchRole(); // } } 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) } setScore(matchScore, satScore, peakScore, type) { if (!SKUIUtil.isFGUIValid(this.ManiPanel)) return; } /** * 添加關閉事件 */ pushCloseEvent(item: fairygui.GComponent, target: fairygui.GComponent, call: Function = null) { item.clearClick(); item.onClick(() => { if (this.stopTap) return call && call(); FGUtil.dispose(target); }, this) } }