import { _decorator, v3, Node, tween } from 'cc'; import { Main } from './Main'; 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 { BuyItemLayer } from '../gameui/BuyItemLayer'; import { GameConst, ITEM_FROZEN_LV, ITEM_HINT_LV, ITEM_TYPE } from '../core/common/GameConst'; import { levelsData } from '../user/LevelsData'; import i18n from '../core/i18n/runtime-scripts/LanguageData'; const { ccclass, property } = _decorator; @ccclass('GameUI') export class GameUI extends BasePanel { private hint_time = 0; public starNode: Node = null; onBtnClicked(event: any, customEventData: any) { var btnName = event.target.name; switch (btnName) { case "btn_pause": audioMgr.playOneShot(GameConst.audios.btnclick); this.pasue = true; WindowManager.ins.open("PauseLayer") break; case "item_left": audioMgr.playOneShot(GameConst.audios.btnclick); if (Date.now() - this.hint_time < 2000) return; if (Data.user.lv < ITEM_HINT_LV) { MsgHints.show(i18n("main.关卡%{value}解锁", { value: ITEM_HINT_LV})); return; } if (Data.user.hint > 0) { this.dispatch(GameConst.USE_ITEM_HINT); this.hint_time = Date.now(); } else { WindowManager.ins.open("BuyItemLayer").then((com: BuyItemLayer) => { com.setItemType(ITEM_TYPE.Hint); }) } break; case "btn_sp_01"://移除 audioMgr.playOneShot(GameConst.audios.btnclick); Main.I._GameNode.remove(); break; case "btn_sp_02"://凑齐 audioMgr.playOneShot(GameConst.audios.btnclick); Main.I._GameNode.prompt(); break; case "btn_sp_03"://乱序 audioMgr.playOneShot(GameConst.audios.btnclick); Main.I._GameNode.mess(); break; case "item_right": if (this.freezetime) { MsgHints.show(i18n("main.冰冻中...")); return; } if (Data.user.lv < ITEM_FROZEN_LV) { MsgHints.show(i18n("main.关卡%{value}解锁", { value: ITEM_FROZEN_LV})); return; } if (Data.user.frozen > 0) { Data.user.frozen--; this.freezetime = true; setTimeout(() => { this.freezetime = false; }, 5000); audioMgr.playOneShot(GameConst.audios.freeze); } else { WindowManager.ins.open("BuyItemLayer").then((com: BuyItemLayer) => { com.setItemType(ITEM_TYPE.Frozen); }) } break; } } start() { this.register(GameConst.USE_ITEM_TIME, this.doUseTime.bind(this)) this.register("PAUSE_LAYER_CLOSE", () => { this.pasue = false; }) this.starNode = this.GetGameObject("star-with-outline"); } restart() { this.SetText("lbl_lv", i18n("main.关卡%{value}", { value: Data.user.lv})); let obj = levelsData.getCurLevelInfo(); console.log("关卡数据:", obj); this.levelTime = obj.time; this.GetGameObject("match-timer-freeze-background").active = false; this.GetGameObject("match-extra-time-power-up-small").active = false; this.SetText("lbl_left_item_lv", "关卡" + ITEM_HINT_LV); this.SetText("lbl_right_item_lv", "关卡" + ITEM_FROZEN_LV); this.freezetime = false; this.pasue = false; this.passedTime = 0; } doUseTime() { Data.user.time--; let node = this.GetGameObject("match-extra-time-power-up-small"); node.active = true; node.setPosition(v3(0, 0, 0)); tween(node).to(0.5, { worldPosition: this.GetGameObject("lbl_time").worldPosition }).call(() => { this.levelTime += 60; node.active = false; }).start(); } levelTime = 0; passedTime = 0; pasue: boolean = false; freezetime: boolean = false; public star = 0; update(dt) { if(WindowManager.ins.isShow("OutOfBoxLayer")||WindowManager.ins.isShow("DrawStarLayer")||WindowManager.ins.isShow("LevelClearLayer")||WindowManager.ins.isShow("FailLayer"))return this.GetGameObject("match-timer-freeze-background").active = this.freezetime; if (!this.pasue && !this.freezetime) this.passedTime += dt; this.SetText("lbl_star", this.star + ""); let nLeft = this.levelTime - this.passedTime; if (nLeft > 0) { this.SetText("lbl_time", Utils.getTimeStrByS(nLeft)); }else {//游戏结束 WindowManager.ins.open("FailLayer") } if (Data.user.lv < ITEM_HINT_LV) { this.GetGameObject("item_left_Locked").active = true; this.GetGameObject("item_left_icon").active = false; }else { this.GetGameObject("item_left_Locked").active = false; this.GetGameObject("item_left_icon").active = true; this.SetText("lbl_item_left_count", Data.user.hint == 0 ? "+" : Data.user.hint + ""); } if (Data.user.lv < ITEM_FROZEN_LV) { this.GetGameObject("item_right_Locked").active = true; this.GetGameObject("item_right_icon").active = false; }else { this.GetGameObject("item_right_Locked").active = false; this.GetGameObject("item_right_icon").active = true; this.SetText("lbl_item_rihgt_count", Data.user.frozen == 0 ? "+" : Data.user.frozen + ""); } } }