// Learn TypeScript: // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html // Learn Attribute: // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html const { ccclass, property } = cc._decorator; @ccclass export default class NewClass extends cc.Component { @property(cc.Label) label: cc.Label = null; @property text: string = 'hello'; btnStatic: number = 0; propName: string = ""; // LIFE-CYCLE CALLBACKS: // onLoad () {} start() { this.updateLayerOneView(); // console.log(cc.fx.GameConfig.GM_INFO.level, "新模式"); for (let i = 0; i < cc.fx.GameConfig.NEW_LEVEL.length; i++) { if ((cc.fx.GameConfig.GM_INFO.level + 1) == cc.fx.GameConfig.NEW_LEVEL[i].level) { this.propName = cc.fx.GameConfig.NEW_LEVEL[i].name; const path = 'Window_Prop/' + this.propName; if (i == 6 || (i < 11 && i > 7)) this.node.getChildByName("newmode").getChildByName("icon").y = 155 - 50 else this.node.getChildByName("newmode").getChildByName("icon").y = 100 - 50 if (i > 10) this.node.getChildByName("newmode").getChildByName("light").y = 140 - 50 else this.node.getChildByName("newmode").getChildByName("light").y = -72 - 50 cc.resources.load(path, cc.SpriteFrame, (err, spriteFrame: cc.SpriteFrame) => { if (err) { console.error('动态加载背景图失败:', err); return; } this.node.getChildByName("newmode").getChildByName("icon").getComponent(cc.Sprite).spriteFrame = spriteFrame; }) break; } } } updateLayerOneView() { const newmode = this.node.getChildByName("newmode"); if (!newmode) { return; } const layerOneOpen = !!cc.fx.GameConfig.GM_INFO.abTests && Number(cc.fx.GameConfig.GM_INFO.abTests.layer_one) == 2; this.setNodeActive(newmode, "diban", layerOneOpen); this.setNodeActive(newmode, "bg2", layerOneOpen); this.setNodeActive(newmode, "title2", layerOneOpen); this.setNodeActive(newmode, "btn2", layerOneOpen); this.setNodeActive(newmode, "bg", !layerOneOpen); this.setNodeActive(newmode, "title", !layerOneOpen); this.setNodeActive(newmode, "btn", !layerOneOpen); } setNodeActive(parent: cc.Node, name: string, active: boolean) { const child = parent.getChildByName(name); if (child) { child.active = active; } } setMode(mode: number) { this.btnStatic = mode; this.updateLayerOneView(); // mode 0 表示从结算界面自动弹出,关闭后仍停留在结算界面。 if (mode == 0 || mode == 3) { return; } let name = "GameScene"; if (mode == 1) { name = "HomeScene"; } cc.director.preloadScene(name, () => { }) } clickBtn() { cc.fx.AudioManager._instance.playEffect("anniu_Big", null); if (this.btnStatic == 0) { this.node.active = false; this.node.emit("new-mode-confirmed"); } else if (this.btnStatic == 1) { cc.fx.GameTool.getUserAvatar(() => { }) cc.director.loadScene("HomeScene"); } else if (this.btnStatic == 2) { cc.director.loadScene("GameScene"); } else if (this.btnStatic == 3) { this.node.active = false; } } returnBtn() { cc.fx.AudioManager._instance.playEffect("anniu_Big", null); this.node.active = false; this.node.emit("new-mode-returned"); } // update (dt) {} }