import DataMgr from "../data/DataMgr"; import { GameMode, PlaceBallType, POWER_TIME } from "../data/Define"; import UIBase from "../fgui/core/UIBase"; import ui_UILevelProp from "../fgui/res/game/ui_UILevelProp"; import { xGame } from "../xGame"; import MoneyNode from "./item/MoneyNode"; import ShowItem from "./item/ShowItem"; import UIAddProp from "./UIAddProp"; import { UIGame } from "./UIGame"; import UILevelDisplay from "./UILevelDisplay"; import UIMain from "./UIMain"; import UIPower from "./UIPower"; import JSBridgeUtils from "../utils/JSBridgeUtils"; import { LocalStorageManager } from "../utils/LocalStorageManager"; /** * 摆球达人界面,选择关卡界面 */ export default class UILevelProp extends UIBase { public ui: ui_UILevelProp; public moneyNode: MoneyNode; public level: number; public data: cfgTable.placeball; public firstPos: number = 385; public secondPos: number = 467; // public showItemArr: Array = []; public constructor() { super(); // try { // Laya.loader.load("res/font/arial.ttf", Laya.Handler.create(this, this.onFontLoaded)); // console.log("zh: constructor加载arial字体成功"); // } catch (error) { // console.log("zh: constructor加载arial字体失败"); // } } // private onFontLoaded(): void { // try { // Laya.Text.defaultFont = "arial";//仅这样设置无效 // this.ui.myNode.conditionTxt.font = "arial"; // console.log("zh: onFontLoaded 设置arial字体成功"); // } catch (error) { // console.log("zh: constructor onFontLoaded加载arial字体失败"); // } // } public onConstructor(): void { this.ui = ui_UILevelProp.createInstance(); this.contentPane = this.ui; this.isEject = false; this.addUIClick(this.ui.closeBtn, this.hideWin); this.moneyNode = new MoneyNode(this.ui.moneyNode); this.addUIClick(this.ui.myNode.startBtn, this.startGame); this.addUIClick(this.ui.myNode.n_yd_zzq_btn3, this.startGame); } public show(level): void { console.log('zh:show.') super.show(); this.ui.t1.play(); // this.level = level; this.data = cfgTable.placeballData[this.level]; this.updateSelf(); this.showPreView(); this.moneyNode.ui.c1.selectedIndex = 2; this.moneyNode.checkPowerTime(); this.moneyNode.powerChange(); // this.setGlobalFont("arial", this.ui); this.yinDaoForLianxi(); this.setGlobalFont(this.ui) } /** * 练习模式 引导 ,他给人家起名字是什么挑战模式 */ yinDaoForLianxi() { let lianXiGuide = DataMgr.getLianXiGuide(); console.log('zh:lianXiGuide=', lianXiGuide); if (lianXiGuide === 0) { this.ui.myNode.n_yd_3.visible = true; console.log('zh:yinDaoForLianxi 333 set ok') // let x = this.ui.myNode.startBtn.x; // let y = this.ui.myNode.startBtn.y; // this.ui.n_yd_zzq_btn.x = x; // this.ui.n_yd_zzq_btn.y = y; // let x1 = this.ui.myNode.x; // let y1 = this.ui.myNode.y; // this.ui.n_lc3.x = x1; // this.ui.n_lc3.y = y1; } else { this.ui.myNode.n_yd_3.visible = false; console.log('zh:无需引导33') } } //展示关卡预览图 showPreView() { let item: ShowItem; let data; for (let index = 0; index < this.showItemArr.length; index++) { item = this.showItemArr[index]; item.destroySelf(); } this.showItemArr = []; let cfgData = xGame.cfgMgr.getPlaceBallByLevel(this.level); for (const key in cfgData) { data = cfgData[key]; item = new ShowItem(); item.setParent(this.ui.myNode.displayRoot); item.setPos(data.x, data.y); item.setUrl(data.value); this.showItemArr.push(item); } } updateSelf() { this.ui.myNode.levelTxt.text = `Level ${this.level}` this.ui.myNode.modeNode.c1.selectedIndex = this.data.type; // try { // this.ui.myNode.conditionTxt.font = "arial"; // console.log('zh: set arial 字体OK') // } catch (error) { // console.log('zh: 加载arial字体失败') // } if (this.data.ball == -1) { //打进场上所有球 this.ui.myNode.conditionTxt.text = "Pocket all the balls on the table"; } else { this.ui.myNode.conditionTxt.text = `Successfully pocketed ${this.data.ball} balls in total` //`累计打进${this.data.ball}个球`; } // 或者动态加载字体后设置 // Laya.loader.load("res/font/arial", laya.utils.Handler.create(this, onFontLoaded)); // function onFontLoaded() { // // txt.font = "fontName"; // 替换为实际的字体名 // } let localData = DataMgr.getPlaceBallLevel(this.level); let getAward = localData.getAward; let cfg = cfgTable.placeballData[this.level]; // let coin = this.data.award[0]; let diamond = this.data.award[1]; if (cfg.type == PlaceBallType.challenge) { diamond = 0; coin = 100; } this.ui.myNode.coinNode.visible = coin == 0 ? false : true; this.ui.myNode.diamondNode.visible = diamond == 0 ? false : true; this.ui.myNode.coinNode.numTxt.text = coin + ""; if (cfg.type == PlaceBallType.challenge) { this.ui.myNode.coinNode.numTxt.text = ""; } this.ui.myNode.diamondNode.numTxt.text = diamond + ""; if (coin > 0 && diamond > 0) { this.ui.myNode.diamondNode.x = 385; this.ui.myNode.coinNode.x = 467; } else { this.ui.myNode.diamondNode.x = 385; this.ui.myNode.coinNode.x = 385; } if (!getAward) { this.ui.myNode.coinNode.c1.selectedIndex = 0; this.ui.myNode.diamondNode.c1.selectedIndex = 0; } else { this.ui.myNode.diamondNode.c1.selectedIndex = 1; this.ui.myNode.coinNode.c1.selectedIndex = 1; } } startGame() { //let needCoin = xGame.common.enterPlaceBallNeedCoin; console.log("zh:startGame"); if (DataMgr.powerEnough()) { console.log('zh:powerEnough =' + DataMgr.powerEnough()); this.ui.myNode.startBtn.touchable = false; this.ui.myNode.startBtn.powerEft.t0.play(Laya.Handler.create(this, () => { console.log('zh:startGame dh ') // this.ui.myNode.startBtn.touchable = true; DataMgr.setPower(-1); xGame.eventMgr.event(POWER_TIME); // xGame.common.gameMode = GameMode.placeBall; xGame.common.placeBallCurLevel = this.level; xGame.uiMgr.Show(UIGame); //关闭选择关卡界面和主界面 xGame.uiMgr.Hide(UILevelDisplay); xGame.uiMgr.Hide(UIMain); this.logEventForChallenge_level_start(this.level); this.hideWin(); // })) // console.log('zh:eeeee') } else { let guide = DataMgr.getLianXiGuide(); if (guide == 0 && xGame.common.gameMode == GameMode.placeBall) { console.log('zh:自动添加2点体力,以便于完成练习引导模式') DataMgr.setPower(2); } console.log('zh:guide = ' + guide) console.log('zh:xGame.common.gameMode = ' + xGame.common.gameMode) console.log('zh:powerEnough不足=' + DataMgr.powerEnough()); xGame.uiMgr.Show(UIPower); } } /** * 埋点challenge模式开始 challenge_level_start * @param level */ logEventForChallenge_level_start(level) { // 埋点:challenge模式开始 challenge_level_start 参数: 1开始了几次 // - 2金币数量// - 3当前是第几关// - 4钻石数量 let keyStr = 'sjmd_challenge_level_start'; let jsonStr = { "count": 1, "gold_balance ": DataMgr.getCoin(), "level": level, "diamond_balance ": DataMgr.getDiamond() } if (LocalStorageManager.hasJosnKey(keyStr)) { const d = LocalStorageManager.getItem<{ count: number, level: number }>(keyStr); if (level > d.level) { jsonStr.count = d.count + 1; LocalStorageManager.setItem(keyStr, jsonStr); } else { //NO } } else { LocalStorageManager.setItem(keyStr, jsonStr); } const reqStr = JSON.stringify(jsonStr); JSBridgeUtils.instance.logEventForAdHaveParams('challenge_level_start', reqStr); } public hideWin() { super.hide(); // 重置start按钮状态 if (this.ui.myNode.startBtn) { this.ui.myNode.startBtn.touchable = true; // 停止可能正在播放的动画 if (this.ui.myNode.startBtn.powerEft.t0) { this.ui.myNode.startBtn.powerEft.t0.stop(); } } } } UILevelProp.uiName = "UILevelProp";