| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- import { _decorator, Component, ProgressBar, Node, Label, game, Game } from 'cc';
- import { Http } from '../../core/net/Http';
- import { HttpSystem } from '../../core/net/HttpSystem';
- import { BitmapFont } from '../../core/ui/BitmapFont';
- import { CountDown } from '../../core/ui/CountDown';
- import { WindowManager } from '../../core/ui/window/WindowManager';
- import { WindowOpenMode } from '../../core/ui/window/WindowOpenMode';
- import { Utils } from '../../core/utils/Utils';
- import { ConfigData } from '../../Data/ConfigData';
- import { g } from '../../Data/g';
- import { HttpErrorCode } from '../../Data/HttpErrorCode';
- import { platform } from '../../Data/platform';
- const { ccclass, property } = _decorator;
- @ccclass('UINumerical')
- export class UINumerical extends Component {
- @property({ type: BitmapFont, tooltip: "等级文本" }) lvLabel: BitmapFont;
- @property({ type: ProgressBar, tooltip: "经验值进度条" }) expProgress: ProgressBar;
- @property({ type: BitmapFont, tooltip: "钻石文本" }) diamondLabel: BitmapFont;
- @property({ type: BitmapFont, tooltip: "红包文本" }) bonusLabel: BitmapFont;
- @property({ type: Node, tooltip: "任务红点" }) taskPrize: Node;
- @property({ type: Node, tooltip: "新人红点" }) newrewardPrize: Node;
- @property({ type: Node, tooltip: "邀请提示" }) inviteTips: Node;
- @property({ type: Node, tooltip: "试玩按钮" }) tryGameButton: Node;
- @property({ type: Node, tooltip: "新人福利" }) newRewardButton: Node;
- @property({ type: Http, tooltip: "网络请求" }) http: Http;
- @property({ type: Label, tooltip: "新人奖励任务计时" }) countlabel: Label;
- @property({ type: CountDown, displayName: "倒计时组件", tooltip: "倒计时组件" }) countDown: CountDown = null;
- @property({ type: Label, tooltip: "时间文本" }) txtTime: Label = null;
- private _exp = -1;
- private _diamond = -1;
- private _bonus = -1;
- private _ecpm = -1;
- private lvConfig = [];
- private newCountTime = 0;
- private rankRemaindTime = 0;
- async start() {
- if (g.userData.noviceReceived) {
- this.checkTodayGet();
- }
- let result = ConfigData.configMap.get("level");
- for (let k in result) {
- this.lvConfig.push(result[k]);
- }
- // let ecpm = await this.http.send("/api/user/GetAverageEcpm");
- // if (ecpm.code == 0) {
- // g.userData.ecpm = ecpm.data;
- // }
- game.on(Game.EVENT_HIDE, function () {
- console.log("Game Hide");
- });
- game.on(Game.EVENT_SHOW, function () {
- console.log("Game Show");
- g.gameData.isRefreshRankTime = true;
- });
- }
- async update() {
- if (this.taskPrize.active != g.gameData.taskReceive) {
- this.taskPrize.active = g.gameData.taskReceive;
- }
- if (this.newrewardPrize.active != (g.gameData.threeDayTaskReceive != 0)) {
- this.newrewardPrize.active = (g.gameData.threeDayTaskReceive != 0);
- }
- if (this._exp != g.userData.lv && this.lvConfig.length > 0) {
- this._exp = g.userData.lv;
- let lv = g.userData.getLevel();
- if (lv > parseInt(this.lvLabel.string)) {
- platform.reportThinking("level_up", JSON.stringify({ current_level: lv, old_level: parseInt(this.lvLabel.string) }));
- }
- let progress = this.lvConfig[lv] ? (g.userData.lv - this.lvConfig[lv - 1].total_exp) / this.lvConfig[lv].single_exp : 1;
- this.lvLabel.string = lv + "";
- this.expProgress.progress = progress;
- }
- if (this._diamond != g.userData.diamond) {
- this._diamond = g.userData.diamond;
- this.diamondLabel.string = g.userData.diamond + "";
- }
- if (this._bonus != g.userData.bonus) {
- this._bonus = g.userData.bonus;
- this.bonusLabel.string = g.userData.bonus + "";
- }
- if (!this.inviteTips.active && g.userData.contribution == 2999) {
- this.inviteTips.active = true;
- } else if (this.inviteTips.active && g.userData.contribution != 2999) {
- this.inviteTips.active = false;
- }
- // if (this._ecpm != g.userData.ecpm) {
- // this._ecpm = g.userData.ecpm;
- // if (g.userData.ecpm > 150) {
- // this.tryGameButton.active = false;
- // } else {
- // this.tryGameButton.active = true;
- // }
- // }
- if (g.gameData.threedayTaskTime) {
- this.newCountTime = g.gameData.threedayTaskTime * 1000;
- } else {
- this.newCountTime = g.userData.createTime * 1000 + 3 * 60 * 60 * 1000;
- }
- if (this.newRewardButton.active) {
- if (Date.now() < this.newCountTime) {
- if (this.countlabel.string != Utils.formatCountDown(this.newCountTime - Date.now(), false)) {
- this.countlabel.string = Utils.formatCountDown(this.newCountTime - Date.now(), false);
- }
- } else {
- this.countlabel.string = "已失效";
- if (Date.now() - this.newCountTime >= 24 * 60 * 60 * 1000) {
- this.newRewardButton.active = false;
- }
- }
- }
- if (this.rankRemaindTime == 0 || g.gameData.isRefreshRankTime) {
- if (g.gameData.rankData != null) {
- g.gameData.isRefreshRankTime = false;
- let deltaTime = g.gameData.rankData.finishTime - HttpSystem.serverTime * 0.001;
- this.rankRemaindTime = deltaTime > 0 ? deltaTime : 0;
- if (this.rankRemaindTime > 0) { this.updateTxtTime(deltaTime); } else { this.countDown.stop(); this.finishCooling(); }
- if (!this.countDown.running && this.rankRemaindTime > 0) { this.countDown.value = this.rankRemaindTime; this.countDown.play(); }
- }
- }
- }
- public updateTxtTime(progress) {
- this.txtTime.string = `${Utils.formatCountDown(progress * 1000, true, true)}`;
- }
- public finishCooling() {
- this.rankRemaindTime = 0;
- this.txtTime.string = ``;
- }
- /**
- * 查询每日登陆奖励是否已经领取
- * 该方法只执行一次
- */
- async checkTodayGet() {
- let result = await this.http.send("/api/dailyLogin/getDailyLoginReceived");
- //每日奖励未领取
- if (result.code == 0 && result.data.received == false) {
- WindowManager.open("Prefabs/DayLogin/DayLogin", WindowOpenMode.NotCloseAndAdd, [
- result.data.dayCount, [
- "Prefabs/Turntable/Turntable",
- "Prefabs/DayPrize/DayPrize"
- ]
- ]);
- } else if (result.code == HttpErrorCode.VideoADCD) {
- WindowManager.showTips("请求频繁,请稍后再试");
- } else {
- WindowManager.open("Prefabs/Turntable/Turntable", WindowOpenMode.NotCloseAndAdd, ["Prefabs/DayPrize/DayPrize"]);
- }
- }
- public tryGame(): void {
- platform.umUp("gameListClick");//试玩埋点
- platform.intoGameList(g.userData.id + "");
- }
- public onNewRewardButton(): void {
- if (g.gameData.threedayTaskTime) {
- WindowManager.open("Prefabs/NewRewardWindow/NewRewardWindow_3", WindowOpenMode.NotCloseAndAdd);
- } else {
- WindowManager.open("Prefabs/NewRewardWindow/NewRewardWindow_2", WindowOpenMode.NotCloseAndAdd);
- }
- }
- }
|