UserInfo.js 5.4 KB

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