import { _decorator, Component, Label, log, Node, Sprite } from 'cc'; import { BundleName } from 'db://assets/script/Config/EnumCfg'; import { GameCfg } from 'db://assets/script/Config/GameCfg'; import { LayerMgr } from 'db://assets/script/Manager/LayerMgr'; import { page_game } from './page_game'; import { Today, User } from 'db://assets/script/Manager/LocalDataMgr'; import EventMgr from 'db://assets/script/Manager/EventMgr'; import { page_unlock } from './page_unlock'; import { gamecfg } from '../dtta/interfaceMgr'; const { ccclass, property } = _decorator; @ccclass('item_level') export class item_level extends Component { @property(Label) txt_title: Label = null; @property(Sprite) img_show: Sprite = null @property(Node) node_lock: Node = null; data: gamecfg = null index: number = 0 Init(data: gamecfg, index: number) { this.txt_title.string = data.title; this.data = data; this.index = index; LayerMgr.instance.ShowSprite(BundleName.hall, "image/levelbg/level" + data.unit, this.img_show.node) if (User.userData.unlockUnits.indexOf(data.unit) != -1 || Today.todayData.isUnlockAll) { this.node_lock.active = false; } else { this.node_lock.active = true; } EventMgr.ins.addEventListener("unlock_unit", (unit) => { if (unit == this.data.unit) { this.node_lock.active = false; } }, this) EventMgr.ins.addEventListener("unlock_all", (unit) => { this.node_lock.active = false; }, this) EventMgr.ins.addEventListener("daojishi_over", () => { if (User.userData.unlockUnits.indexOf(this.data.unit) == -1) { this.node_lock.active = true; } }, this) } OnClickThis() { if (User.userData.unlockUnits.indexOf(this.data.unit) != -1 || Today.todayData.isUnlockAll) { GameCfg.CurUnit = this.index; log(GameCfg.CurUnit + " " + this.index) LayerMgr.instance.ShowPrefab(BundleName.hall, "prefab/page_game", (node) => { node.getComponent(page_game).Init(this.data) }) } else { console.error("没有解锁") LayerMgr.instance.ShowPrefab(BundleName.hall, "prefab/page_unlock", (node) => { node.getComponent(page_unlock).data = this.data }) } } }