"use strict"; cc._RF.push(module, '6bab23+1R5JurQ3NisvK/RF', 'LeveRankItem'); // scripts/prefabs/LeveRankItem.ts "use strict"; // 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 var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); var SaveDataManager_1 = require("../component/SaveDataManager"); var Global_1 = require("../Global"); var BattleConst_1 = require("../kernel/battle/BattleConst"); var TableDefine_1 = require("../kernel/table/TableDefine"); var UIManager_1 = require("../ui/UIManager"); var UITitleData_1 = require("../ui/uiView/UITitleData"); var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property; var LevelRankItem = /** @class */ (function (_super) { __extends(LevelRankItem, _super); function LevelRankItem() { var _this = _super !== null && _super.apply(this, arguments) || this; _this._levelId = 0; return _this; } LevelRankItem.prototype.onLoad = function () { this._line = this.node.getChildByName('line'); }; LevelRankItem.prototype.start = function () { BattleConst_1.getGlobalNode().on(Global_1.GlobalEvent.LEVEL_STAR_CHANGE, this.onStarChange, this); }; LevelRankItem.prototype.onDestroy = function () { BattleConst_1.getGlobalNode().targetOff(this); }; LevelRankItem.prototype.setLevelId = function (id) { this._levelId = id; this.refresh(); }; LevelRankItem.prototype.setLineLayer = function (node) { this._lineLayer = node; // this._line.removeFromParent(); // this._lineLayer.addChild(this._line); // this._line.active = true; }; LevelRankItem.prototype.refresh = function () { var isUnlocked = (this._levelId <= SaveDataManager_1.SaveDataManager.ins.runtimeData.curLevel); this.node.getChildByName('btn').getComponentInChildren(cc.Label).string = this._levelId.toString(); var curNext = (this._levelId == SaveDataManager_1.SaveDataManager.ins.runtimeData.curLevel + 1); if (!isUnlocked && curNext) { this.node.getChildByName('back').active = false; this.node.getChildByName('btn').active = true; var backSp = this.node.getChildByName('btn').getChildByName('Background').getComponent(cc.Sprite); backSp.spriteFrame = this.node.getChildByName('linkRes').getChildByName('UI_gqlb_2').getComponent(cc.Sprite).spriteFrame; this.node.getChildByName('imgCur').active = true; } else { this.node.getChildByName('btn').active = isUnlocked; if (isUnlocked) { var backSp = this.node.getChildByName('btn').getChildByName('Background').getComponent(cc.Sprite); backSp.spriteFrame = this.node.getChildByName('linkRes').getChildByName('UI_gqlb_1').getComponent(cc.Sprite).spriteFrame; } this.node.getChildByName('back').active = !isUnlocked; this.node.getChildByName('imgCur').active = false; } var star = 0; if (SaveDataManager_1.SaveDataManager.ins.runtimeData.levelScoreMap[this._levelId]) { star = SaveDataManager_1.SaveDataManager.ins.runtimeData.levelScoreMap[this._levelId]; } var starContainer = cc.find('btn/Background/starContainer', this.node); for (var i = 0; i < 3; ++i) { var starNode = starContainer.children[i]; starNode.getComponent(cc.Sprite).spriteFrame = this.node.getChildByName('linkRes').getChildByName('star' + (i + 1 <= star ? '1' : '2')).getComponent(cc.Sprite).spriteFrame; } this.scheduleOnce(this.updateLine.bind(this), 0); }; LevelRankItem.prototype.updateLine = function () { if (this._line.parent != this._lineLayer) { this._line.removeFromParent(); this._lineLayer.addChild(this._line); this._line.active = true; } var nextLv = this._levelId + 1; var maxLv = Global_1.tMgr.getConfig(TableDefine_1.TableName.GAME_PLAY, 22).Value; if (nextLv > maxLv) { this._line.active = false; return; } var nextIsLihgt = (nextLv <= SaveDataManager_1.SaveDataManager.ins.runtimeData.curLevel + 1); this._line.getComponent(cc.Sprite).spriteFrame = (this.node.getChildByName('linkRes').getChildByName('line' + (nextIsLihgt ? '1' : '2'))).getComponent(cc.Sprite).spriteFrame; var isEnd = (this._levelId % 5 == 0); var isReverse = (Math.ceil(this._levelId / 5) % 2 == 0); //是否反向 if (isEnd) { this._line.angle = 90; this._line.setPosition(this.node.position.x, this.node.position.y - this.node.height / 2); } else { this._line.angle = 0; this._line.setPosition(this.node.position.x + this.node.width / 2 * (isReverse ? -1 : 1), this.node.position.y); } }; LevelRankItem.prototype.onStarChange = function (level) { if (level == this._levelId || level == this._levelId - 1) { this.refresh(); } }; LevelRankItem.prototype.onBtnClick = function () { UITitleData_1.UITitleData.id = this._levelId; // UIManager.ins.closeWindow(WindowName.LEVEL_RANK); UIManager_1.UIManager.ins.openWindow(Global_1.WindowName.PREVIEW, UITitleData_1.UITitleData.id); }; LevelRankItem = __decorate([ ccclass ], LevelRankItem); return LevelRankItem; }(cc.Component)); exports.default = LevelRankItem; cc._RF.pop();