// Learn TypeScript: // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html // Learn Attribute: // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html import { SaveDataManager } from "../../component/SaveDataManager"; import { GlobalEvent, tMgr } from "../../Global"; import { getGlobalNode } from "../../kernel/battle/BattleConst"; import { GameSceneObjTable, TableName } from "../../kernel/table/TableDefine"; const { ccclass, property } = cc._decorator; @ccclass export default class GameSceneUnlockTool extends cc.Component { private _configId: number = 0; private _config: GameSceneObjTable = null; get config(): GameSceneObjTable { return this._config; } private _disableNode: cc.Node = null; private _enableNode: cc.Node = null; //#region LIFE-CYCLE CALLBACKS: onLoad() { this._disableNode = this.node.getChildByName('btn').getChildByName('disableNode'); this._enableNode = this.node.getChildByName('btn').getChildByName('enableNode'); this._disableNode.active = true; this._enableNode.active = false; } start() { } protected onEnable(): void { getGlobalNode().on(GlobalEvent.CHANGE_EVENT_STAR, this.refresh, this); this.refresh(); } protected onDisable(): void { getGlobalNode().off(GlobalEvent.CHANGE_EVENT_STAR, this.refresh, this); } // update (dt) {} //#endregion //#region public method setObjId(id: number) { this._configId = id; this._config = tMgr.getConfig(TableName.GAME_SCENE_OBJ, id) as GameSceneObjTable; this.refresh(); } //#endregion //#region private method private refresh() { if (this._config) { this._disableNode.active = SaveDataManager.ins.runtimeData.star < this._config.Star; this._enableNode.active = !this._disableNode.active; } } //#endregion }