123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- const GameModule = require("./utils/GameModule");
- const DWTool = require("./utils/DWTool");
- const Api = require('./net/Api');
- const NotiKey = require('./utils/GameEnum').GameNotificationKey;
- const BuildingModel = require('./utils/BuildingModel');
- const AlertManager = require('./utils/AlertManager');
- cc.Class({
- extends: cc.Component,
- properties: {
- _reportFailDuration: 0,
- grossIncomeLabel: cc.Label,
- grossCoin: sp.Skeleton,
- // rateLabel: cc.Label,
- headSprite: cc.Sprite,
- starsLabel: cc.Label,
- starNode: cc.Node,
- diamondLabel: cc.Label,
-
- recordModify: [],
- recordUnlockModify: [],
- stars: {
- get: function () {
- return this._stars;
- },
- set: function (value) {
- this._stars = value;
- this.starsLabel.string = this._stars;
- this.updateStarAnimation();
- }
- },
- grossIncome: {
- get: function () {
- return this._grossIncome;
- },
- set: function (value) {
- this._grossIncome = value;
- this.grossIncomeLabel.string = DWTool.coinParse(this._grossIncome);
- }
- },
- // rate: {
- // get: function() {
- // return this._rate;
- // },
- // set: function(value) {
- // this._rate = value;
- // this.rateLabel.string = DWTool.coinParse(this._rate) + " / 秒"
- // }
- // },
- diamond: {
- get: function() {
- return this._diamond;
- },
- set: function(value) {
- this._diamond = value;
- this.diamondLabel.string = this._diamond;
- }
- },
- },
- onLoad() {
- GameModule.userInfo = this;
- this._stars = 0;
- this._grossIncome = 0;
- this._rate = 0;
- this._isPlayAnimation = false;
- this.seq = 1;
- this.headSprite.node.on(cc.Node.EventType.TOUCH_END, _.debounce(() => {
- Global.GameEvent.fire(NotiKey.ShowUserInfomation, this.userInfo.id);
- }, 1000, true), this);
- //监听用户收取金币事件
- Global.GameEvent.on(NotiKey.UserCollectCoin, this, (flag) => {
- console.log(flag);
- let animKey = flag ? 'jinbi_huoqu2' : 'jinbi_huoqu'
- this.grossCoin.setAnimation(0, animKey, false)
- })
- this.reportFunc = () => {
- if (this._reportFailDuration > 0) {
- this._reportFailDuration -= 5;
- return;
- }
- DWTool.reportInfo(this.seq, this.grossIncome, this.stars, this.recordModify, this.recordUnlockModify)
- .then((result) => {
-
- this._reportFailDuration = 0;
- this.recordModify = [];
- this.recordUnlockModify = [];
- this.seq += 1;
- }).catch((err) => {
- if (err.code === -4) {
- this._reportFailDuration = 60;
- }
- cc.error(err.msg);
- });
- }
- this.schedule(this.reportFunc, 5.0);
- },
- setUserInfo(userInfo) {
- if (arguments.length < 1) {
- throw new Error("setUserInfo Missing parameter...");
- }
- this.userInfo = userInfo;
- Api.createImageFromUrl(userInfo.head, (spriteFrame) => {
- this.headSprite.spriteFrame = spriteFrame;
- }, null);
- },
- setGrossIncomeAndStars(grossIncome, stars) {
- if (arguments.length < 2) {
- throw new Error("setGrossIncomeAndStars Missing parameter...");
- }
- this.grossIncome = grossIncome;
- this.stars = stars;
- },
- updateStarAnimation() {
- if (this._isPlayAnimation) { return; }
-
- this._isPlayAnimation = true;
- let jumpHeight = 30;
- let duration = 0.2;
- let animationArray = [];
- while(jumpHeight > 0.1) {
- jumpHeight = jumpHeight - (jumpHeight / 3);
- duration = duration - (duration / 3);
- let upAction = cc.moveBy(duration, 0, jumpHeight).easing(cc.easeCubicActionOut());
- let downAction = cc.moveBy(duration, 0, -jumpHeight).easing(cc.easeCubicActionIn());
- animationArray.push(upAction);
- animationArray.push(downAction);
- }
- let callback = cc.callFunc(() => {
- this._isPlayAnimation = false;
- });
- animationArray.push(callback);
- this.starsLabel.node.runAction(cc.sequence(animationArray));
- },
- updateRecordModify(buildingInfo) {
- for (let i = 0; i < this.recordModify.length; i++) {
- let temp = this.recordModify[i];
- if (buildingInfo.buildingId == temp.buildingId) {
- this.recordModify.splice(i, buildingInfo)
- return;
- }
- }
- this.recordModify.push(buildingInfo);
- }
- });
|