123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- const loginReward = require('../data/loginReward');
- const GameModule = require('../utils/GameModule');
- const {GameNotificationKey, WechatShareType} = require('../utils/GameEnum');
- const InviteApi = require('../net/InviteApi');
- const ArtistManager = require("../utils/ArtistManager");
- const TapTapTool = require("../utils/TapTapTool");
- const AlertManager = require('../utils/AlertManager');
- const WeChat = require('../net/WeChat');
- const DWTool = require('../utils/DWTool');
- const GameRedDot = require('../utils/GameEnum').GameRedDot;
- cc.Class({
- extends: cc.Component,
- properties: {
- signButton: cc.Button,
- signButtonSpriteFrame: [cc.SpriteFrame],
- shareNode: cc.Node,
- shareLabel: cc.Label,
- shareSelectedNode: cc.Node,
- layout: cc.Layout,
- itemPrefab: cc.Prefab,
- starSprite: cc.Sprite,
- starRichText: cc.RichText,
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- this.shareNode.on(cc.Node.EventType.TOUCH_END, this.changeShareType, this);
- this.refreshButton();
- },
- start () {
- for (var i = 0; i < loginReward.length - 1; i++) {
- let itemModel = loginReward[i];
- let item = cc.instantiate(this.itemPrefab);
- this.layout.node.addChild(item);
- item.getComponent('LoginRewardItem').init(itemModel);
- if (this.reward == undefined) {
- if (itemModel.rewardId > GameGlobal.userLoginReward.rewardCount) {
- this.reward = itemModel;
- if (window.tt != undefined) {
- this.shareLabel.string = '分享领取双倍签到奖励';
- }
- }
- }
- }
- //
- let itemModel = loginReward[loginReward.length - 1];
- if (itemModel.starId > 0) {
- let imageId = 50000 + itemModel.starId;
- ArtistManager.loadStarAvatarSpriteFrame(imageId, this.starSprite);
- this.star = GameGlobal.BuildingManager.getStarInfo(itemModel.starId);
- this.starRichText.string = `<b><outline color=#ff6e19 width=2>累计登录7天\n即可获得${this.star.name}签约资格~</outline></b>`;
- if (GameGlobal.userLoginReward.rewardCount >= 6 && !GameGlobal.userLoginReward.isLoginReward) {
- this.shareLabel.string = '分享到群炫耀';
- if (window.tt != undefined) {
- this.shareLabel.string = '分享炫耀';
- }
- this.reward = itemModel;
- }
- }
- },
- closeNode() {
- GameModule.audioMng.playClickButton();
- this.node.destroy();
- },
- changeShareType() {
- this.shareSelectedNode.active = !this.shareSelectedNode.active;
- },
- signLoginReward() {
- GameModule.audioMng.playClickButton();
- this.signButton.interactable = false;
- //是否选择分享翻倍奖励
- if (this.shareSelectedNode.active) {
- if (CC_WECHATGAME) {
- GameEvent.on(GameNotificationKey.ShowShareAction, this, (type, isOk) => {
- if (type != WechatShareType.LoginReward) { return; }
- if (isOk) {
- this.shareActionCallback();
- } else {
- this.signButton.interactable = true;
- }
- GameEvent.off(GameNotificationKey.ShowShareAction, this);
- });
- WeChat.shareAction(WechatShareType.LoginReward, () => {
- }, () => {
- this.signButton.interactable = true;
- console.log('分享失败或取消');
- });
- } else {
- this.gainReward(1);
- }
- } else {
- this.gainReward(0);
- }
- },
- shareActionCallback() {
- this.gainReward(1);
- GameEvent.off(GameNotificationKey.ShowShareAction, this);
- },
- refreshButton() {
- if (GameGlobal.userLoginReward.isLoginReward) {
- this.signButton.interactable = false;
- this.signButton.getComponent(cc.Sprite).spriteFrame = this.signButtonSpriteFrame[1];
- } else {
- this.signButton.interactable = true;
- this.signButton.getComponent(cc.Sprite).spriteFrame = this.signButtonSpriteFrame[0];
- }
- },
- gainReward(isShare) {
- InviteApi.postLoginReward(this.reward.rewardId, isShare, (responseData) => {
- GameGlobal.userLoginReward.isLoginReward = true;
- GameGlobal.userLoginReward.rewardCount = this.reward.rewardId;
- TapTapTool.removeRedDot(GameRedDot.sign);
- this.refreshButton();
- var gold = TapTapTool.goldStrToClass(this.reward.coin);
- if (this.reward.diamond > 0) {
- GameModule.audioMng.playGetAward();
- let diamond = isShare ? this.reward.diamond * 2 : this.reward.diamond;
- let text = `钻石 x ${diamond}`;
- AlertManager.showActGiftAlert('diamond', text);
- GameModule.userInfo.updateUserRes({
- diamond: parseInt(diamond)
- });
- } else if (gold.n > 0) {
- GameModule.audioMng.playGetAward();
- gold = isShare ? TapTapTool.multiple(gold, 2) : gold;
- let text = `金币 x ${TapTapTool.parseToString(gold)}`;
- AlertManager.showActGiftAlert('coin', text);
- GameModule.userInfo.updateUserRes({
- gold: gold
- });
- } else if (this.reward.starId > 0) {
- this.showGetStar();
- }
- if (this.reward.rewardId >= 7) {
- GameEvent.fire(GameNotificationKey.LoginRewardGainFinish);
- } else {
- GameEvent.fire(GameNotificationKey.LoginRewardGainOneDay, this.reward.rewardId);
- }
- }, (error) => {
- this.signButton.interactable = true;
- GameGlobal.commonAlert.showCommonErrorAlert("签到失败");
- });
- },
- showGetStar() {
- GameModule.audioMng.playGetAward();
- let imageId = 50000 + this.reward.starId;
- let desc = "<color=#d5ba9c>签约条件</c><br/><br/><color=#540904>第七天登录 </c><img src='star_true'/>";
- DWTool.loadResPrefab("./prefabs/star/getStarAlert")
- .then((result) => {
- let alert = cc.instantiate(result);
- cc.find('Canvas').addChild(alert);
- alert.getComponent('StarGetStarAlert').initGetStar(imageId, `${this.star.name}`, desc);
- });
- GameEvent.fire(GameNotificationKey.RefreshSignArtistList);
- }
- // update (dt) {},
- });
|