123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- import { _decorator, Component, Label, Node } from 'cc';
- import platformSystem from '../platform/platformSystem';
- import BasePanel from '../core/component/BasePanel';
- import { audioMgr } from '../core/manager/AudioManager';
- import Data from '../core/manager/Data';
- import Utils from '../core/utils/Utils';
- import { GameConst } from '../core/common/GameConst';
- import i18n from '../core/i18n/runtime-scripts/LanguageData';
- const { ccclass, property } = _decorator;
- @ccclass('BuyLifeLayer')
- export class BuyLifeLayer extends BasePanel {
- update() {
- this.SetText("lbl_life", Data.user.life + "")
- if (Data.user.life >= GameConst.MAX_LIFE) {
- this.SetText("lbl_life_time", i18n("main.已满"))
- }
- else {
- if (Data.user.life_cost_time == 0) {
- Data.user.life_cost_time = Date.now();
- }
- let nLeft = (Date.now() - Data.user.life_cost_time) / 1000;
- let addLife = Math.floor(nLeft / 60 / GameConst.MAX_LIFE_RECOVERY_TIME);
- if (addLife > 0)
- Data.user.life += addLife;
- nLeft -= addLife * GameConst.MAX_LIFE_RECOVERY_TIME * 60;
- this.SetText("lbl_life_time", Utils.getTimeStrByS(GameConst.MAX_LIFE_RECOVERY_TIME * 60 - nLeft))
- }
- }
- star() {
- platformSystem.platform.showInterstitialAd();
- }
- onBtnClicked(event: any, customEventData: any) {
- audioMgr.playOneShot(GameConst.audios.btnclick);
- var btnName = event.target.name;
- switch (btnName) {
- case "btn_close":
- this.close();
- break;
- case "btn_ad":
- platformSystem.platform.showRewardVideo((b) => {
- if (b) {
- Data.user.life += 1;
- Data.save();
- this.close();
- }
- })
- break;
- }
- }
- }
|