1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- const DWTool = require("../utils/DWTool");
- const {GameNotificationKey, GameRedDot, InviteMissionItemType} = require('../utils/GameEnum');
- const InviteApi = require('../net/InviteApi');
- const TapTapTool = require("../utils/TapTapTool");
- const GameModule = require("../utils/GameModule");
- 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) {},
- });
|