| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- // 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 PlayerConst from "../../data/PlayerConst";
- import GameConst from "../../data/GameConst";
- import EffectMgr from "../../mgr/EffectMgr";
- import GameMgr, { UIITEM_NAME } from "../../mgr/GameMgr";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class ClockInItem extends cc.Component {
- /**普通bg */
- @property(cc.Node)
- node_nromalClockInBg: cc.Node = null;
- /**未打卡bg */
- @property(cc.Node)
- node_unClockInBg: cc.Node = null;
- /**已经打卡icon */
- @property(cc.Node)
- node_haveClockInIcon: cc.Node = null;
- /**红包 */
- @property(cc.Node)
- node_reaPacket: cc.Node = null;
- /**提示 */
- @property(cc.Node)
- node_tip: cc.Node = null;
- /**宝箱 */
- @property(cc.Node)
- node_box: cc.Node = null;
- /**当前打卡天 */
- public curClockInDay: number = 0;
- /**奖励类型 null 是无奖励 1 红包 2 是宝箱 */
- public rewardType: number = null;
- /**奖励数量 */
- public rewardNum: number = null;
- /**红包数目 */
- public reaPacketCashNum: number = 0;
- /**是否打卡成功 */
- public ifClockInDay: boolean = false;
- // LIFE-CYCLE CALLBACKS:
- // onLoad () {}
- start() {
- this.node.on(cc.Node.EventType.TOUCH_END, this.onClick, this);
- }
- // update (dt) {}
- init(day: number = null) {
- // LogUtil.log("day",day)
- // if (!day) {
- // return;
- // }
- if (day) {
- this.curClockInDay = day;
- }
- // LogUtil.log("this.curClockInDay", this.curClockInDay);
- let config = GameConst.config_clockIn[this.curClockInDay - 1];
- // LogUtil.log("GameConst.config_clockIn", GameConst.config_clockIn);
- this.rewardType = config.rewardType;
- this.rewardNum = config.rewardNum
- this.ifClockInDay = PlayerConst.ifClockInToday;
- let curRealClockInDay: number = 0;
- //如果已经打卡 1 对应 1
- if (this.ifClockInDay) {
- curRealClockInDay = this.curClockInDay;
- }
- //如果未打开 1 对应 0
- else {
- curRealClockInDay = this.curClockInDay - 1;
- }
- if (curRealClockInDay < PlayerConst.clockInDay) {
- this.node_unClockInBg.active = false;
- this.node_nromalClockInBg.active = true;
- if (this.rewardType == 1) {
- this.node_nromalClockInBg.setScale(1, 1);
- }
- else {
- this.node_nromalClockInBg.setScale(0.8, 0.8);
- }
- this.node_reaPacket.active = this.rewardType == 1;
- this.node_haveClockInIcon.active = true;
-
- this.node_tip.active = false;
- this.node_box.active = this.curClockInDay == GameConst.maxClockInDay;
- }
- else if (curRealClockInDay == (PlayerConst.clockInDay)) {
- this.node_unClockInBg.active = false;
- this.node_nromalClockInBg.active = true;
- this.node_nromalClockInBg.setScale(1, 1);
- this.node_reaPacket.active = this.rewardType == 1;
- mk.console.log(" this.ifClockInDay", this.ifClockInDay);
- this.node_haveClockInIcon.active = this.ifClockInDay;
- this.node_tip.active = !this.ifClockInDay;
- this.node_box.active = this.curClockInDay == GameConst.maxClockInDay;
- }
- else {
- this.node_haveClockInIcon.active = false;
- this.node_nromalClockInBg.active = false;
- this.node_unClockInBg.active = true;
- this.node_reaPacket.active = this.rewardType == 1;
- this.node_box.active = this.rewardType == 2;
- }
- // if (this.curClockInDay < PlayerConst.clockInDay) {
- // //第一天情况特殊
- // if (PlayerConst.clockInDay == 0) {
- // this.node_unClockInBg.active = false;
- // this.node_nromalClockInBg.active = true;
- // this.node_nromalClockInBg.setScale(1, 1);
- // this.node_reaPacket.active = this.rewardType == 1;
- // LogUtil.log(" this.ifClockInDay", this.ifClockInDay);
- // this.node_haveClockInIcon.active = this.ifClockInDay;
- // this.node_tip.active = !this.ifClockInDay;
- // this.node_box.active = this.curClockInDay == GameConst.maxClockInDay;
- // }
- // else {
- // this.node_unClockInBg.active = false;
- // this.node_nromalClockInBg.active = true;
- // if (this.rewardType == 1) {
- // this.node_nromalClockInBg.setScale(1, 1);
- // }
- // else {
- // this.node_nromalClockInBg.setScale(0.8, 0.8);
- // }
- // this.node_reaPacket.active = this.rewardType == 1;
- // this.node_haveClockInIcon.active = true;
- // this.node_box.active = this.curClockInDay == GameConst.maxClockInDay;
- // }
- // }
- // else if (this.curClockInDay == (PlayerConst.clockInDay)) {
- // this.node_unClockInBg.active = false;
- // this.node_nromalClockInBg.active = true;
- // this.node_nromalClockInBg.setScale(1, 1);
- // this.node_reaPacket.active = this.rewardType == 1;
- // LogUtil.log(" this.ifClockInDay", this.ifClockInDay);
- // this.node_haveClockInIcon.active = this.ifClockInDay;
- // this.node_tip.active = !this.ifClockInDay;
- // this.node_box.active = this.curClockInDay == GameConst.maxClockInDay;
- // }
- // else {
- // this.node_haveClockInIcon.active = false;
- // this.node_nromalClockInBg.active = false;
- // this.node_unClockInBg.active = true;
- // this.node_reaPacket.active = this.rewardType == 1;
- // this.node_box.active = this.rewardType == 2;
- // }
- }
- onClick() {
- GameMgr.Inst.sendEvent(UIITEM_NAME.ClockInItem, `点击${this.curClockInDay}打卡Item`);
- if (this.curClockInDay == PlayerConst.clockInDay && this.ifClockInDay) {
- if (this.rewardType != null) {
- EffectMgr.Inst.addTip(`打卡成功,可以提现啦`);
- }
- else {
- EffectMgr.Inst.addTip(`继续累计打卡,领取后面红包吧`);
- }
- }
- else {
- if (this.rewardType != null) {
- if (this.curClockInDay == GameConst.maxClockInDay) {
- EffectMgr.Inst.addTip(`连续打卡${this.curClockInDay}天,领取神秘宝箱`)
- }
- else {
- EffectMgr.Inst.addTip(`连续打卡${this.curClockInDay}天,提现${this.rewardNum}元`)
- }
- }
- }
- }
- }
|