/** * 游戏内获取道具弹窗 */ import { PROPTYPE } from "../data/Enum"; import GamePlay from "../GamePlay"; import DataMgr from "../mgr/DataMgr"; import EffectMgr from "../mgr/EffectMgr"; const { ccclass, property } = cc._decorator; @ccclass export default class GetPropUI extends cc.Component { @property(cc.Node) public node_rectBg: cc.Node = null; @property(cc.Node) public node_closeBtn: cc.Node = null; @property(cc.Node) public node_getBtn: cc.Node = null; @property(cc.Node) node_prop: cc.Node = null; start() { this.adapt(); this.initEvent(); } onEnable() { this.init(); } onDisable() { GamePlay.Inst.curPropType = PROPTYPE.Null; } /**适配 */ adapt() { this.node_rectBg.setContentSize(cc.winSize.width, cc.winSize.height); } init() { for (var i = 0; i < this.node_prop.childrenCount; i++) { let prop = this.node_prop.children[i]; let propCode = prop.children[0] ? prop.children[0].name : ""; if (propCode == GamePlay.Inst.curPropType) { prop.active = true; } else { prop.active = false; } } } /**初始化事件 */ initEvent() { this.node_getBtn.on(cc.Node.EventType.TOUCH_END, this.onClick, this); this.node_closeBtn.on(cc.Node.EventType.TOUCH_END, this.onClick, this); } onClick(event: cc.Event.EventTouch) { mk.audio.playEffect("button"); switch (event.currentTarget) { case this.node_getBtn: this.onClickGet(); break; case this.node_closeBtn: this.onClickClose(); break; } } onClickClose() { mk.ui.closePanel("GetPropUI"); } /**点击获取 */ onClickGet() { GamePlay.Inst.cancelShowInter(); mk.ad.watchAd((ifsuccess: boolean) => { this.watchCallBack(ifsuccess) }); } /**观看回调 */ watchCallBack(ifSuccess: boolean = false) { if (ifSuccess) { this.scheduleOnce(() => { mk.tip.pop("观看成功,获取奖励") }, 0) this.watchSuccess(); } else { this.scheduleOnce(() => { mk.tip.pop("观看失败,无法领取奖励哦") }, 0) this.watchFailed(); } } /**观看成功 */ watchSuccess() { EffectMgr.Inst.addTip("观看视频成功,获得道具"); DataMgr.Inst.updatePropNum(1, GamePlay.Inst.curPropType, 1); } /**观看失败 */ watchFailed() { // EffectMgr.Inst.addTip("观看视频失败,请稍后再试"); } }