UINumerical.ts 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import { _decorator, Component, ProgressBar, Node, Label, game, Game } from 'cc';
  2. import { Http } from '../../core/net/Http';
  3. import { HttpSystem } from '../../core/net/HttpSystem';
  4. import { BitmapFont } from '../../core/ui/BitmapFont';
  5. import { CountDown } from '../../core/ui/CountDown';
  6. import { WindowManager } from '../../core/ui/window/WindowManager';
  7. import { WindowOpenMode } from '../../core/ui/window/WindowOpenMode';
  8. import { Utils } from '../../core/utils/Utils';
  9. import { ConfigData } from '../../Data/ConfigData';
  10. import { g } from '../../Data/g';
  11. import { HttpErrorCode } from '../../Data/HttpErrorCode';
  12. import { platform } from '../../Data/platform';
  13. const { ccclass, property } = _decorator;
  14. @ccclass('UINumerical')
  15. export class UINumerical extends Component {
  16. @property({ type: BitmapFont, tooltip: "等级文本" }) lvLabel: BitmapFont;
  17. @property({ type: ProgressBar, tooltip: "经验值进度条" }) expProgress: ProgressBar;
  18. @property({ type: BitmapFont, tooltip: "钻石文本" }) diamondLabel: BitmapFont;
  19. @property({ type: BitmapFont, tooltip: "红包文本" }) bonusLabel: BitmapFont;
  20. @property({ type: Node, tooltip: "任务红点" }) taskPrize: Node;
  21. @property({ type: Node, tooltip: "新人红点" }) newrewardPrize: Node;
  22. @property({ type: Node, tooltip: "邀请提示" }) inviteTips: Node;
  23. @property({ type: Node, tooltip: "试玩按钮" }) tryGameButton: Node;
  24. @property({ type: Node, tooltip: "新人福利" }) newRewardButton: Node;
  25. @property({ type: Http, tooltip: "网络请求" }) http: Http;
  26. @property({ type: Label, tooltip: "新人奖励任务计时" }) countlabel: Label;
  27. @property({ type: CountDown, displayName: "倒计时组件", tooltip: "倒计时组件" }) countDown: CountDown = null;
  28. @property({ type: Label, tooltip: "时间文本" }) txtTime: Label = null;
  29. private _exp = -1;
  30. private _diamond = -1;
  31. private _bonus = -1;
  32. private _ecpm = -1;
  33. private lvConfig = [];
  34. private newCountTime = 0;
  35. private rankRemaindTime = 0;
  36. async start() {
  37. if (g.userData.noviceReceived) {
  38. this.checkTodayGet();
  39. }
  40. let result = ConfigData.configMap.get("level");
  41. for (let k in result) {
  42. this.lvConfig.push(result[k]);
  43. }
  44. // let ecpm = await this.http.send("/api/user/GetAverageEcpm");
  45. // if (ecpm.code == 0) {
  46. // g.userData.ecpm = ecpm.data;
  47. // }
  48. game.on(Game.EVENT_HIDE, function () {
  49. console.log("Game Hide");
  50. });
  51. game.on(Game.EVENT_SHOW, function () {
  52. console.log("Game Show");
  53. g.gameData.isRefreshRankTime = true;
  54. });
  55. }
  56. async update() {
  57. if (this.taskPrize.active != g.gameData.taskReceive) {
  58. this.taskPrize.active = g.gameData.taskReceive;
  59. }
  60. if (this.newrewardPrize.active != (g.gameData.threeDayTaskReceive != 0)) {
  61. this.newrewardPrize.active = (g.gameData.threeDayTaskReceive != 0);
  62. }
  63. if (this._exp != g.userData.lv && this.lvConfig.length > 0) {
  64. this._exp = g.userData.lv;
  65. let lv = g.userData.getLevel();
  66. if (lv > parseInt(this.lvLabel.string)) {
  67. platform.reportThinking("level_up", JSON.stringify({ current_level: lv, old_level: parseInt(this.lvLabel.string) }));
  68. }
  69. let progress = this.lvConfig[lv] ? (g.userData.lv - this.lvConfig[lv - 1].total_exp) / this.lvConfig[lv].single_exp : 1;
  70. this.lvLabel.string = lv + "";
  71. this.expProgress.progress = progress;
  72. }
  73. if (this._diamond != g.userData.diamond) {
  74. this._diamond = g.userData.diamond;
  75. this.diamondLabel.string = g.userData.diamond + "";
  76. }
  77. if (this._bonus != g.userData.bonus) {
  78. this._bonus = g.userData.bonus;
  79. this.bonusLabel.string = g.userData.bonus + "";
  80. }
  81. if (!this.inviteTips.active && g.userData.contribution == 2999) {
  82. this.inviteTips.active = true;
  83. } else if (this.inviteTips.active && g.userData.contribution != 2999) {
  84. this.inviteTips.active = false;
  85. }
  86. // if (this._ecpm != g.userData.ecpm) {
  87. // this._ecpm = g.userData.ecpm;
  88. // if (g.userData.ecpm > 150) {
  89. // this.tryGameButton.active = false;
  90. // } else {
  91. // this.tryGameButton.active = true;
  92. // }
  93. // }
  94. if (g.gameData.threedayTaskTime) {
  95. this.newCountTime = g.gameData.threedayTaskTime * 1000;
  96. } else {
  97. this.newCountTime = g.userData.createTime * 1000 + 3 * 60 * 60 * 1000;
  98. }
  99. if (this.newRewardButton.active) {
  100. if (Date.now() < this.newCountTime) {
  101. if (this.countlabel.string != Utils.formatCountDown(this.newCountTime - Date.now(), false)) {
  102. this.countlabel.string = Utils.formatCountDown(this.newCountTime - Date.now(), false);
  103. }
  104. } else {
  105. this.countlabel.string = "已失效";
  106. if (Date.now() - this.newCountTime >= 24 * 60 * 60 * 1000) {
  107. this.newRewardButton.active = false;
  108. }
  109. }
  110. }
  111. if (this.rankRemaindTime == 0 || g.gameData.isRefreshRankTime) {
  112. if (g.gameData.rankData != null) {
  113. g.gameData.isRefreshRankTime = false;
  114. let deltaTime = g.gameData.rankData.finishTime - HttpSystem.serverTime * 0.001;
  115. this.rankRemaindTime = deltaTime > 0 ? deltaTime : 0;
  116. if (this.rankRemaindTime > 0) { this.updateTxtTime(deltaTime); } else { this.countDown.stop(); this.finishCooling(); }
  117. if (!this.countDown.running && this.rankRemaindTime > 0) { this.countDown.value = this.rankRemaindTime; this.countDown.play(); }
  118. }
  119. }
  120. }
  121. public updateTxtTime(progress) {
  122. this.txtTime.string = `${Utils.formatCountDown(progress * 1000, true, true)}`;
  123. }
  124. public finishCooling() {
  125. this.rankRemaindTime = 0;
  126. this.txtTime.string = ``;
  127. }
  128. /**
  129. * 查询每日登陆奖励是否已经领取
  130. * 该方法只执行一次
  131. */
  132. async checkTodayGet() {
  133. let result = await this.http.send("/api/dailyLogin/getDailyLoginReceived");
  134. //每日奖励未领取
  135. if (result.code == 0 && result.data.received == false) {
  136. WindowManager.open("Prefabs/DayLogin/DayLogin", WindowOpenMode.NotCloseAndAdd, [
  137. result.data.dayCount, [
  138. "Prefabs/Turntable/Turntable",
  139. "Prefabs/DayPrize/DayPrize"
  140. ]
  141. ]);
  142. } else if (result.code == HttpErrorCode.VideoADCD) {
  143. WindowManager.showTips("请求频繁,请稍后再试");
  144. } else {
  145. WindowManager.open("Prefabs/Turntable/Turntable", WindowOpenMode.NotCloseAndAdd, ["Prefabs/DayPrize/DayPrize"]);
  146. }
  147. }
  148. public tryGame(): void {
  149. platform.umUp("gameListClick");//试玩埋点
  150. platform.intoGameList(g.userData.id + "");
  151. }
  152. public onNewRewardButton(): void {
  153. if (g.gameData.threedayTaskTime) {
  154. WindowManager.open("Prefabs/NewRewardWindow/NewRewardWindow_3", WindowOpenMode.NotCloseAndAdd);
  155. } else {
  156. WindowManager.open("Prefabs/NewRewardWindow/NewRewardWindow_2", WindowOpenMode.NotCloseAndAdd);
  157. }
  158. }
  159. }