123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- const DWTool = require("../utils/DWTool");
- const {GameNotificationKey, GameRedDot} = require('../utils/GameEnum');
- const InviteApi = require('../net/InviteApi');
- const TapTapTool = require("../utils/TapTapTool");
- const GameModule = require("../utils/GameModule");
- //任务状态[0 : 完成可领取, 1 : 未完成, 2 : 完成已领取]
- var InviteMissionItemType = cc.Enum({
- Gain: 0,
- NoFinished: 1,
- Finished: 2
- });
- cc.Class({
- extends: cc.Component,
- properties: {
- awardNode1: cc.Node,
- awardItemNode1: cc.Node,
- countLabel1: cc.Label,
- awardRichText: cc.RichText,
- noButton: cc.Button,
- gainButton: cc.Button,
- finishButton: cc.Button,
- },
- // LIFE-CYCLE CALLBACKS:
- // onLoad () {},
- start () {
- },
- hideAllButton() {
- this.noButton.node.active = false;
- this.gainButton.node.active = false;
- this.finishButton.node.active = false;
- },
- onDisable() {
- },
- configData(model, invitedCount) {
- this.model = model;
- this.hideAllButton();
- switch (model.state) {
- case InviteMissionItemType.NoFinished:
- this.noButton.node.active = true;
- break;
- case InviteMissionItemType.Finished:
- this.finishButton.node.active = true;
- break;
- case InviteMissionItemType.Gain:
- this.gainButton.node.active = true;
- break;
- }
- let diamond = model.diamond;
- if (diamond > 0) {
- this.awardNode1.active = true;
- cc.loader.loadRes("/textures/invite/talent_invite_diamond", cc.SpriteFrame, (err, spriteFrame) => {
- if (err) {
- } else {
- this.awardItemNode1.getComponent('cc.Sprite').spriteFrame = spriteFrame;
- }
- });
- this.countLabel1.string = DWTool.coinParse(diamond);
- }
- if (invitedCount >= model.count) {
- this.awardRichText.string = `<color=#362E2B>邀请奖励</c>\n<color=#AF7434>(好友:${model.count}/${model.count}名)</c>`;
- } else {
- this.awardRichText.string = `<color=#362E2B>邀请奖励</c>\n<color=#AF7434>(好友:${invitedCount}/${model.count}名)</c>`;
- }
- },
- gainAward() {
- InviteApi.postGainAward(this.model.id, (responseData) => {
- if (responseData.isCancel) {
- TapTapTool.removeRedDot(GameRedDot.inviteFriend);
- }
- this.refreshButtonState();
- }, (error) => {
- GameGlobal.commonAlert.showCommonErrorAlert("领取失败");
- });
- },
- refreshButtonState() {
- GameModule.audioMng.playGetAward();
- this.model.state = InviteMissionItemType.Finished;
- this.hideAllButton();
- this.finishButton.node.active = true;
- GameEvent.fire(GameNotificationKey.InviteGainAward, this.model);
- },
- // update (dt) {},
- });
|