| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- // 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 DailyData from "../datas/DailyData";
- import GameM from "../manager/GameM";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class DailyUpItem extends cc.Component {
- @property(cc.Node)
- bgNormal: cc.Node = null;
- @property(cc.Node)
- bgSel: cc.Node = null;
- @property(cc.Sprite)
- icon: cc.Sprite = null;
- @property(cc.Label)
- labState: cc.Label = null;
- @property(cc.Node)
- iconGet: cc.Node = null;
- @property(cc.Node)
- red: cc.Node = null;
- private selState = false
- /** 数据
- * index 下标 从0开始
- getDay 第x天可领取
- rewardType 奖励类型 1:红包币 2:汽车
- rewardNum 奖励数量/汽车等级
- conditionType 获得条件类型 1:累计登陆x天 2:汽车等级达到x级 3:玩家等级达到x级
- conditionLv 获得条件累计登陆天数/汽车等级/玩家等级
- */
- data = null
- start() {
- }
- init(data, hasGet) {
- this.data = data
- //console.log("Data:",data);
- let iconName = ''
- if (this.data.rewardType == 1) {
- iconName = 'hongbao'
- this.icon.node.scale = 0.15
- }
- else {
- this.icon.node.scale = 0.22
- iconName = 'che_' + this.data.rewardNum.toString()
- }
- cc.loader.loadRes('daily/' + iconName, cc.SpriteFrame, (err, assets) => {
- if (err) {
- cc.error(err);
- return;
- }
- this.icon.getComponent(cc.Sprite).spriteFrame = assets;
- })
- if (hasGet) {
- this.iconGet.parent.active = true
- this.iconGet.active = true
- this.labState.string = '已领取'
- this.red.active = false
- }
- else {
- this.iconGet.parent.active = false
- this.iconGet.active = false
- this.labState.string = `登录${this.data.getDay}天`
- }
- this.setSel(false)
- this.showRed()
- }
- showRed() {
- let red = false
- let data = null
- data = DailyData.Instance.dailyCfg[this.node.name]
- if (DailyData.Instance.dailyGetArr[this.node.name] == '0') {
- if (GameM.commonData.loginDays >= data.getDay) {
- if (data.conditionType == 1) {
- red = true
- }
- if (data.conditionType == 2) {
- if (GameM.commonData.maxCarLevel >= data.conditionLv) {
- red = true
- }
- }
- else if (data.conditionType == 3) {
- if (GameM.commonData.roleData.lv >= data.conditionLv) {
- red = true
- }
- }
- }
- }
- this.red.active = red
- }
- setSel(sel) {
- this.selState = sel
- if (this.selState) {
- this.bgSel.active = true
- // this.bgNormal.active = false
- }
- else {
- this.bgSel.active = false
- // this.bgNormal.active = true
- }
- }
- // update (dt) {}
- }
|