1
0

UserInfo.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. const GameModule = require("./utils/GameModule");
  2. const DWTool = require("./utils/DWTool");
  3. const Api = require('./net/Api');
  4. const NotiKey = require('./utils/GameEnum').GameNotificationKey;
  5. const BuildingModel = require('./utils/BuildingModel');
  6. const AlertManager = require('./utils/AlertManager');
  7. cc.Class({
  8. extends: cc.Component,
  9. properties: {
  10. _reportFailDuration: 0,
  11. grossIncomeLabel: cc.Label,
  12. grossCoin: sp.Skeleton,
  13. // rateLabel: cc.Label,
  14. headSprite: cc.Sprite,
  15. starsLabel: cc.Label,
  16. starNode: cc.Node,
  17. diamondLabel: cc.Label,
  18. recordModify: [],
  19. recordUnlockModify: [],
  20. stars: {
  21. get: function () {
  22. return this._stars;
  23. },
  24. set: function (value) {
  25. this._stars = value;
  26. this.starsLabel.string = this._stars;
  27. this.updateStarAnimation();
  28. DWTool.submitWechatStars(this._stars);
  29. }
  30. },
  31. grossIncome: {
  32. get: function () {
  33. return this._grossIncome;
  34. },
  35. set: function (value) {
  36. this._grossIncome = value;
  37. this.grossIncomeLabel.string = DWTool.coinParse(this._grossIncome);
  38. }
  39. },
  40. // rate: {
  41. // get: function() {
  42. // return this._rate;
  43. // },
  44. // set: function(value) {
  45. // this._rate = value;
  46. // this.rateLabel.string = DWTool.coinParse(this._rate) + " / 秒"
  47. // }
  48. // },
  49. diamond: {
  50. get: function () {
  51. return this._diamond;
  52. },
  53. set: function (value) {
  54. this._diamond = value;
  55. this.diamondLabel.string = this._diamond;
  56. }
  57. },
  58. levelHomeItemFullCount: 0
  59. },
  60. onLoad() {
  61. GameModule.userInfo = this;
  62. this._stars = 0;
  63. this._grossIncome = 0;
  64. this._rate = 0;
  65. this._isPlayAnimation = false;
  66. this.seq = 1;
  67. this.headSprite.node.on(cc.Node.EventType.TOUCH_END, _.debounce(() => {
  68. GameEvent.fire(NotiKey.ShowUserInfomation, this.userInfo.uid);
  69. }, 1000, true), this);
  70. //监听用户收取金币事件
  71. GameEvent.on(NotiKey.UserCollectCoin, this, (flag) => {
  72. console.log(flag);
  73. let animKey = flag ? 'jinbi_huoqu2' : 'jinbi_huoqu'
  74. this.grossCoin.setAnimation(0, animKey, false)
  75. });
  76. GameEvent.on(NotiKey.LevelHomeItemBuildingFull, this, () => {
  77. this.levelHomeItemFullCount += 1;
  78. if (this.levelHomeItemFullCount === 5) {
  79. GameEvent.fire(NotiKey.LevelHomeItemBuildingAllFull);
  80. GameEvent.fire(NotiKey.CurrentCompanyMax);
  81. }
  82. });
  83. this.reportFunc = () => {
  84. if (this._reportFailDuration > 0) {
  85. this._reportFailDuration -= 5;
  86. return;
  87. }
  88. DWTool.reportInfo(this.seq, this.grossIncome, this.stars, this.recordModify, this.recordUnlockModify)
  89. .then((result) => {
  90. this._reportFailDuration = 0;
  91. this.recordModify = [];
  92. this.recordUnlockModify = [];
  93. this.seq += 1;
  94. }).catch((err) => {
  95. if (err.code === -4) {
  96. this._reportFailDuration = 60;
  97. }
  98. console.log(err.msg);
  99. });
  100. }
  101. this.schedule(this.reportFunc, 3.0);
  102. },
  103. setUserInfo(userInfo) {
  104. if (arguments.length < 1) {
  105. throw new Error("setUserInfo Missing parameter...");
  106. }
  107. this.userInfo = userInfo;
  108. Api.createImageFromUrl(userInfo.head, (spriteFrame) => {
  109. this.headSprite.spriteFrame = spriteFrame;
  110. }, null);
  111. },
  112. setGrossIncomeAndStars(grossIncome, stars) {
  113. if (arguments.length < 2) {
  114. throw new Error("setGrossIncomeAndStars Missing parameter...");
  115. }
  116. this.grossIncome = grossIncome;
  117. this.stars = stars;
  118. },
  119. updateStarAnimation() {
  120. if (this._isPlayAnimation) { return; }
  121. this._isPlayAnimation = true;
  122. let jumpHeight = 30;
  123. let duration = 0.2;
  124. let animationArray = [];
  125. while (jumpHeight > 0.1) {
  126. jumpHeight = jumpHeight - (jumpHeight / 3);
  127. duration = duration - (duration / 3);
  128. let upAction = cc.moveBy(duration, 0, jumpHeight).easing(cc.easeCubicActionOut());
  129. let downAction = cc.moveBy(duration, 0, -jumpHeight).easing(cc.easeCubicActionIn());
  130. animationArray.push(upAction);
  131. animationArray.push(downAction);
  132. }
  133. let callback = cc.callFunc(() => {
  134. this._isPlayAnimation = false;
  135. });
  136. animationArray.push(callback);
  137. this.starsLabel.node.runAction(cc.sequence(animationArray));
  138. },
  139. updateRecordModify(buildingInfo) {
  140. for (let i = 0; i < this.recordModify.length; i++) {
  141. let temp = this.recordModify[i];
  142. if (buildingInfo.buildingId == temp.buildingId) {
  143. this.recordModify.splice(i, buildingInfo)
  144. return;
  145. }
  146. }
  147. this.recordModify.push(buildingInfo);
  148. }
  149. });