1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- import { _decorator, director } from 'cc';
- import { BuyItemLayer } from './BuyItemLayer';
- 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 { Main } from '../game/Main';
- import { ITEM_MAGENT_LV, ITEM_TIME_LV, GameConst, ITEM_TYPE } from '../core/common/GameConst';
- const { ccclass, property } = _decorator;
- @ccclass('LevelLayer')
- export class LevelLayer extends BasePanel {
- start() {
- this.GetGameObject("lock1").active = Data.user.lv < ITEM_MAGENT_LV;
- this.GetGameObject("icon1").active = Data.user.lv >= ITEM_MAGENT_LV;
- this.GetGameObject("lock2").active = Data.user.lv < ITEM_TIME_LV;
- this.GetGameObject("icon2").active = Data.user.lv >= ITEM_TIME_LV;
- this.SetText("lbl_item_magent_lv", ITEM_MAGENT_LV + "级解锁");
- this.SetText("lbl_item_time_lv", ITEM_TIME_LV + "级解锁");
- if (Data.user.magnet > 0) {
- this.SetText("lbl_item1_num", Data.user.magnet + "");
- }
- else {
- this.SetText("lbl_item1_num", "+");
- }
- if (Data.user.time > 0) {
- this.SetText("lbl_item2_num", Data.user.time + "");
- }
- else {
- this.SetText("lbl_item2_num", "+");
- }
- this.SetText("lbl_lvv", "关卡" + Data.user.lv);
- }
- 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_item_1":
- if (Data.user.lv < ITEM_MAGENT_LV) return;
- if (Data.user.magnet == 0) {
- WindowManager.ins.open("BuyItemLayer").then((com: BuyItemLayer) => {
- com.setItemType(ITEM_TYPE.Magnet);
- })
- this.close();
- }
- else {
- this.GetGameObject("choose_item1").active = !this.GetGameObject("choose_item1").active;
- }
- break
- case "btn_item_2":
- if (Data.user.lv < ITEM_TIME_LV) return;
- if (Data.user.time == 0) {
- WindowManager.ins.open("BuyItemLayer").then((com: BuyItemLayer) => {
- com.setItemType(ITEM_TYPE.Time);
- })
- this.close();
- }
- else {
- this.GetGameObject("choose_item2").active = !this.GetGameObject("choose_item2").active;
- }
- break;
- case "btn_play":
- Data.user.useMagnet = this.GetGameObject("choose_item1").active;
- Data.user.useTime = this.GetGameObject("choose_item2").active;
- this.close();
- Main.Instance().play();
- break;
- case "btn_back":
- this.close();
- break;
- }
- }
- }
|