| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- // 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
- import GamePlay from "../GamePlay";
- import PlayerConst from "../data/PlayerConst";
- import EffectMgr from "../mgr/EffectMgr";
- import GameMgr, { UI_NAME } from "../mgr/GameMgr";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class PauseUI extends cc.Component {
- @property(cc.Node)
- node_bg: cc.Node = null;
- @property(cc.Node)
- node_closeBtn: cc.Node = null;
- @property(cc.Node)
- node_musicSwitch: cc.Node = null;
- @property(cc.Node)
- node_music_on: cc.Node = null;
- @property(cc.Node)
- node_music_off: cc.Node = null;
- @property(cc.Node)
- node_effectSwitch: cc.Node = null;
- @property(cc.Node)
- node_effect_on: cc.Node = null;
- @property(cc.Node)
- node_effect_off: cc.Node = null;
- @property(cc.Node)
- node_restartBtn: cc.Node = null;
- @property(cc.Node)
- node_exitBtn: cc.Node = null;
- // LIFE-CYCLE CALLBACKS:
- onLoad() {
-
- }
- start() {
- mk.ad.showNativeAd(4);
- this.node_bg.setContentSize(cc.winSize.width, cc.winSize.height);
- this.initEvent();
- }
- onEnable() {
- GameMgr.Inst.sendEvent(UI_NAME.PauseUI, "进入暂停界面");
- //显示广告
- // AdMgr.Inst.showNativeAd(4, true);
- this.initMsuicSwitchState();
- this.initEffectSwitchState();
- }
- onDisable() {
- //显示广告
- // AdMgr.Inst.destroyNativeAd();
- }
- // update (dt) {}
- init() {
- //this.initSwitchState();
- }
- //初始化
- initMsuicSwitchState() {
- this.node_music_on.active = mk.audio.getSwitchMusic();
- this.node_music_off.active = !this.node_music_on.active
- }
- initEffectSwitchState() {
- this.node_effect_on.active = mk.audio.getSwitchEffect();
- this.node_effect_off.active = !this.node_effect_on.active;
- }
- initEvent() {
- this.node_closeBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
- this.node_musicSwitch.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
- this.node_effectSwitch.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
- this.node_restartBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
- this.node_exitBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
- }
- onClickBtn(event: cc.Event.EventTouch) {
- // AudioMgr.Inst.playEffect(AUDIO_CLIP_NAME.buttonClick);
- mk.audio.playEffect("button");
- switch (event.currentTarget) {
- case this.node_closeBtn:
- this.onClickClose();
- break;
- case this.node_musicSwitch:
- this.onClickMusicSwitch();
- break;
- case this.node_effectSwitch:
- this.onClickEffectSwitch();
- break;
- case this.node_exitBtn:
- this.onClickExitBtn();
- break;
- case this.node_restartBtn:
- this.onClickRestartBtn();
- break;
- }
- }
- onClickClose() {
- // this.node.active = false;
- console.log("点击关闭按钮", this.node.name);
- mk.ui.closePanel(this.node.name);
- mk.ad.destroyNativeAd();
- }
- onClickMusicSwitch() {
- mk.audio.switchMusicFunc();
- this.initMsuicSwitchState();
- }
- onClickEffectSwitch() {
- mk.audio.switchEffectFunc();
- this.initEffectSwitchState();
- }
- onClickRestartBtn() {
- //GameMgr.Inst.sendEvent(UI_NAME.PauseUI, "点击重新开始按钮");
- GamePlay.Inst.restart();
- mk.ui.closePanel(this.node.name);
- }
- onClickExitBtn() {
- GameMgr.Inst.sendEvent(UI_NAME.PauseUI, "点击退出按钮");
- mk.ui.closePanel("PauseUI")
- GamePlay.Inst.restart(false);//退出不扣体力
- GamePlay.Inst.node.active = false;
- // let timeOut = setTimeout(()=>{
- // Main.Inst.node_start.active = true;
- // Main.Inst.node_game.active = false;
- // },2000)
- mk.ad.destroyNativeAd();
- }
- }
|