"use strict"; cc._RF.push(module, 'e74a999IDFOabyymZgXQIiy', 'RankManager'); // Script/RankManager.ts "use strict"; 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 List_1 = require("./module/RankList/List"); var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property; //排行榜 var RankManager = /** @class */ (function (_super) { __extends(RankManager, _super); function RankManager() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.Player = null; _this.selfNode = null; _this.phone = null; return _this; } RankManager.prototype.onLoad = function () { this.init(); }; //初始化数据 RankManager.prototype.init = function () { this.rankList = cc.find("ScrollView", this.node).getComponent(List_1.default); this.Player.getChildByName("rank").active = false; this.listData = []; this.selfData = null; this.rankNumber = 100; this.rankTotal = 100; this.selfNode.opacity = 0; this.fit(); }; RankManager.prototype.start = function () { this.Player.active = false; this.getRank(); }; RankManager.prototype.fit = function () { var jg = cc.fx.GameTool.setFit(); if (!jg) { this.node.getChildByName("ScrollView").getChildByName("view").height = 800; } }; //调用获取排行榜接口 RankManager.prototype.getRank = function () { var _this = this; var dataFile = { length: 100 }; cc.fx.GameTool.getRank(dataFile, function (data) { return _this.getRankData(data); }); }; //实际设置排行数据 RankManager.prototype.getRankData = function (data) { if (data) { cc.fx.GameTool.getRankData(data, this, 6); this.setPic(this.selfData.pic); } }; //返回按钮 RankManager.prototype.backClick = function () { cc.director.loadScene("LoadScene"); }; //最上方用户动画 RankManager.prototype.playerAction = function () { var _this = this; //-254 377 210 453 this.Player.getChildByName("rank").active = false; var time = 1; this.tween = cc.tween(this.Player) .to(2, { position: cc.v3(232, 446, 0) }) .call(function () { _this.Player.getChildByName("rank").active = true; _this.Player.getChildByName("rank").getChildByName("number") .getComponent(cc.Label).string = parseInt(time * 100 + "") + "%"; }) .start(); if (this.listData.length > 0) { time = (this.listData.length - this.rankNumber) / this.listData.length; if (this.listData.length >= 99) { if (this.rankNumber >= 99) { time = (Math.random() * 49 + 1) / 100; var matchId = cc.sys.localStorage.getItem("matchNumber"); if (matchId == null || matchId == undefined) { time = 0; } } else time = (this.listData.length - this.rankNumber) / this.listData.length; } else { if (this.rankNumber > 99) { time = 0; } else time = (this.listData.length - this.rankNumber) / this.listData.length; } } else time = 0; setTimeout(function () { if (_this.tween) _this.tween.stop(); _this.Player.getChildByName("rank").active = true; _this.Player.getChildByName("rank").getChildByName("number") .getComponent(cc.Label).string = parseInt(time * 100 + "") + "%"; }, time * 2000); }; //设置头像 处理的逻辑比较多,不用公共类的了 RankManager.prototype.setPic = function (pic) { var _this = this; this.phone.node.parent.getChildByName("icon").active = false; this.phone.node.active = false; this.Player.active = true; this.Player.opacity = 0; this.Player.getChildByName("mask").getChildByName("icon").active = false; this.Player.getChildByName("mask").getChildByName("phone").active = false; fetch(pic) .then(function (response) { return response.headers.get('Content-Length'); }) .then(function (errNo) { if (errNo == "5093") { _this.phone.node.parent.getChildByName("icon").active = true; _this.Player.getChildByName("mask").getChildByName("icon").active = true; } }) .catch(function (error) { // console.error('Error fetching X-Info:', error); }); var self = this; cc.assetManager.loadRemote(pic, { ext: '.png' }, function (err, texture) { self.Player.opacity = 255; if (texture) { self.phone.node.active = true; self.phone.spriteFrame = new cc.SpriteFrame(texture); self.Player.getChildByName("mask").getChildByName("icon").active = false; self.Player.getChildByName("mask").getChildByName("phone").active = true; self.Player.getChildByName("mask").getChildByName("phone").getComponent(cc.Sprite) .spriteFrame = new cc.SpriteFrame(texture); setTimeout(function () { self.playerAction(); }, 500); } else { self.Player.getChildByName("mask").getChildByName("icon").active = true; setTimeout(function () { self.playerAction(); }, 500); } }); }; __decorate([ property(cc.Node) //用户上方头像 ], RankManager.prototype, "Player", void 0); __decorate([ property(cc.Node) //用户最下方个人信息 ], RankManager.prototype, "selfNode", void 0); __decorate([ property(cc.Sprite) //用户头像换图 ], RankManager.prototype, "phone", void 0); RankManager = __decorate([ ccclass ], RankManager); return RankManager; }(cc.Component)); exports.default = RankManager; cc._RF.pop();