// 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 { OpenActionType } from "../../../mk/system/UISystem"; import TimeUtil from "../../../mk/utils/TimeUtil"; export enum RedBagItemType { /** 开始界面 */ StartUI = 0, /** 关卡界面 */ LevelUI = 1 } const { ccclass, property } = cc._decorator; /** [FC][V2.0.1]气泡红包新增脚本 */ @ccclass export default class RedBagItem extends cc.Component { @property(cc.Label) public label_tip: cc.Label = null; @property(cc.Node) public node_qipaoBg: cc.Node = null; @property(cc.Node) public node_tip: cc.Node = null; @property({ type: cc.Enum(RedBagItemType), displayName: '气泡红包类型' }) public type: number = 0; @property(cc.Integer) public index: number = 0; @property({ displayName: '点击回调', tooltip: "点击时触发", type: cc.Component.EventHandler }) public onComplete: cc.Component.EventHandler[] = []; /** 存储的key */ public stroageKey: string = ""; // LIFE-CYCLE CALLBACKS: // onLoad () {} start() { this.node.on(cc.Node.EventType.TOUCH_START, this.onClick, this); this.init(); } // update (dt) {} /** 初始化 */ init() { //显示之后再初始化 gData.redBagData.init(); this.stroageKey = `RedBagItem${this.index}` let curDate = mk.time.getNowDayString(new Date().getTime()); let lastDate = mk.time.getNowDayString(gData.gameData.gameData.lastTime * 1000); console.log("===[v2.0.1] curDate != lastDate", "curDate:" + curDate, "lastDate:" + lastDate, "curDate != lastDate:" + curDate != lastDate); if (curDate != lastDate) { mk.storage.setStorage(this.stroageKey, 0); } let ifClicked = mk.storage.getStorage(this.stroageKey); // console.log("===[v2.0.1] ifClicked && ifClicked == 1", ifClicked && ifClicked == 1, "=+++ " + ifClicked); /** 有值 且 为1(0 也会被判定为有值) */ if (ifClicked && ifClicked == 1) { this.scheduleOnce(() => { this.hide(); }, 0.01) } else { // console.log("===[v2.0.1]", "RedBagItem active" + this.node.active + "inxdex:" + this.index); gData.redBagData.addRedBagItem(this.type, this); } //开始界面或者游戏界面最后一个 则开始显示文案提示 if (this.index == 2 || this.index == 6) { this.scheduleOnce(() => { gData.redBagData.showTip(this.type); }, 0.1); } } /** 重设 */ reset() { mk.storage.setStorage(this.stroageKey, 0); } /** 被点击 */ async onClick() { //如果未开启,则不操作 if (!gData.redBagData.ifOpen) { await mk.ui.openPanel("module/reward/rewardLuck", OpenActionType.normal); this.callBack(); } else { //倒计时未结束,则不操作 if (this.type == RedBagItemType.StartUI) { if (gData.redBagData.curStartLeftTime >= 1) { mk.tip.pop("请等待倒计时结束之后领取红包"); return; } } else if (this.type == RedBagItemType.LevelUI) { if (gData.redBagData.curLevelLeftTime >= 1) { mk.tip.pop("请等待倒计时结束之后领取红包"); return; } } await mk.ui.openPanel("module/reward/rewardLuck", OpenActionType.normal); this.callBack(); gData.redBagData.removeRedBagItem(this.type, this); gData.redBagData.startCountDown(this.type, gData.redBagData.countTotalTime); gData.redBagData.showTip(this.type, this.index); } } callBack() { const c_count = this.onComplete.length; for (let i = 0; i < c_count; i++) { if (this.onComplete[i].handler) this.onComplete[i].emit([]) } } /** 倒计时 */ countDown(time: string) { this.label_tip.string = time; this.node.color = cc.Color.GRAY; this.node_qipaoBg.color = cc.Color.GRAY; } /** 停止倒计时 */ stopCountDown() { this.label_tip.string = "可领"; this.node.color = cc.Color.WHITE; this.node_qipaoBg.color = cc.Color.WHITE; } /** 隐藏 */ hide() { console.log("==[v2.0.1 index :" + this.index, "隐藏"); this.node.active = false; if (this.node_tip.active) { this.node_tip.active = false; } } showTip() { this.node_tip.active = true; } }