import { _decorator, tween, v3, sp, EditBox } from 'cc'; import BasePanel from '../core/component/BasePanel'; import { audioMgr } from '../core/manager/AudioManager'; import Data from '../core/manager/Data'; import WindowManager from '../core/manager/WindowManager'; import MsgHints from '../core/utils/MsgHints'; import Utils from '../core/utils/Utils'; import { BoxLayer } from '../gameui/BoxLayer'; import { GameConst, BOX_TYPE } from '../core/common/GameConst'; import i18n from '../core/i18n/runtime-scripts/LanguageData'; import { autoBind } from '../core/extend/AutoBind'; const { ccclass, property } = _decorator; @ccclass('HallUI') export class HallUI extends BasePanel { @autoBind(EditBox) public editBox: EditBox = null!; onBtnClicked(event: any, customEventData: any) { audioMgr.playOneShot(GameConst.audios.btnclick); var btnName = event.target.name; switch (btnName) { case "btn_setting": // WindowManager.ins.open("NewPackOpenedLayer"); WindowManager.ins.open("SettingLayer") break; case "btn_play": //获取输入的内容 if(GameConst.isDebug){ let str: string = this.editBox.string; if(!Utils.isNull(str)){ const level: number = parseInt(str); Data.user.lv = level; } } WindowManager.ins.open("LevelLayer"); /*platformSystem.platform.showRewardVideo((b) => { WindowManager.ins.open("LevelLayer"); })*/ break; case "btn_buy_life": if (Data.user.life >= GameConst.MAX_LIFE) { MsgHints.show(i18n("main.体力已满")) return; } WindowManager.ins.open("BuyLifeLayer") break; case "btn_buy_coin": WindowManager.ins.open("BuyCoinLayer"); break; case "full0": let info = Data.user.hasLvBox(); WindowManager.ins.open("BoxLayer").then((com: BoxLayer) => { com.setInfo(BOX_TYPE.LEVEL, GameConst.getLvBoxReward(Math.floor(Data.user.lv / 10))) }); break; case "full1": info = Data.user.hasStarBox(); WindowManager.ins.open("BoxLayer").then((com: BoxLayer) => { com.setInfo(BOX_TYPE.STAR, GameConst.getStarBoxReward(Math.floor(Data.user.lv / 1000))) }); break; } } start() { if(!GameConst.isDebug){ this.editBox.node.active = false; } this.SetText("level_lable", i18n("main.LV:%{value}", { value: Data.user.lv})); this.SetProgressBar("probar_lv", 0.1); let btn_play = this.GetNode("btn_play") tween(btn_play).sequence(tween(btn_play).to(1, { scale: v3(1.05, 1.05, 1.05) }), tween(btn_play).to(1, { scale: v3(1, 1, 1) })).repeatForever().start() } update() { 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)) } this.SetText("lbl_life", Data.user.life + "") this.SetText("lbl_coin", Data.user.coin + "") this.SetText("lbl_lv", Data.user.lv + "") this.SetText("lbl_lv_center", Data.user.lv + "") let info = Data.user.hasLvBox(); this.GetGameObject("full0").active = info let lvmin = Data.user.lv % 10; this.SetText("lbl_pro_lv", lvmin + "/10"); this.SetProgressBar("lbl_pro_star", lvmin / 10); this.SetProgressBar("probar_lv_center", lvmin / 10); this.SetProgressBar("probar_lv", lvmin / 10); info = Data.user.hasStarBox(); if (info) { this.SetText("probar_star", "满"); this.SetProgressBar("probar_star", 1); this.GetGameObject("full1").active = true; }else { let starmin = Data.user.star % 1000; this.GetGameObject("full1").active = false; this.SetText("lbl_pro_star", starmin + "/1000"); this.SetProgressBar("probar_star", starmin / 1000); } } }