105 lines
4.8 KiB
JavaScript
105 lines
4.8 KiB
JavaScript
"use strict";
|
|
cc._RF.push(module, 'ca0f9k0oBVDbpQC+OMNTF3m', 'ItemRender');
|
|
// Script/module/RankList/ItemRender.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 _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
|
|
var ItemRender = /** @class */ (function (_super) {
|
|
__extends(ItemRender, _super);
|
|
function ItemRender() {
|
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
/**数据 */
|
|
_this.data = null;
|
|
/**索引 0表示第一项*/
|
|
_this.itemIndex = 0;
|
|
return _this;
|
|
}
|
|
/**数据改变时调用 */
|
|
ItemRender.prototype.dataChanged = function () {
|
|
var name = cc.fx.GameTool.subName(this.data.name, 6);
|
|
this.node.getChildByName("rankLab").getComponent(cc.Label).string = this.data.rank + "";
|
|
this.node.getChildByName("nameLab").getComponent(cc.Label).string = name + "";
|
|
this.node.getChildByName("totalLab").getComponent(cc.Label).string = this.data.total + "%";
|
|
var timeTemp = cc.fx.GameTool.getTimeShenNong(this.data.time);
|
|
this.node.getChildByName("timeLab").getComponent(cc.Label).string = timeTemp + "";
|
|
this.node.getChildByName("rank").getChildByName("one").active = false;
|
|
this.node.getChildByName("rank").getChildByName("two").active = false;
|
|
this.node.getChildByName("rank").getChildByName("three").active = false;
|
|
if (this.data.rank == 1) {
|
|
this.node.getChildByName("rank").getChildByName("one").active = true;
|
|
this.node.getChildByName("rankLab").active = false;
|
|
}
|
|
else if (this.data.rank == 2) {
|
|
this.node.getChildByName("rank").getChildByName("two").active = true;
|
|
this.node.getChildByName("rankLab").active = false;
|
|
}
|
|
else if (this.data.rank == 3) {
|
|
this.node.getChildByName("rank").getChildByName("three").active = true;
|
|
this.node.getChildByName("rankLab").active = false;
|
|
}
|
|
else {
|
|
this.node.getChildByName("rankLab").active = true;
|
|
}
|
|
this.setPic();
|
|
};
|
|
ItemRender.prototype.setPic = function () {
|
|
var _this = this;
|
|
this.node.getChildByName("pic").getChildByName("icon").active = false;
|
|
this.node.getChildByName("pic").getChildByName("pic").active = false;
|
|
var self = this;
|
|
var url = this.data.pic;
|
|
fetch(url)
|
|
.then(function (response) {
|
|
return response.headers.get('Content-Length');
|
|
})
|
|
.then(function (errNo) {
|
|
// console.log(this.data.rank,'X-Info:', errNo); // 输出X-ErrNo的值
|
|
if (errNo == "5093") {
|
|
// console.log(this.data.rank,"没头像");
|
|
_this.node.getChildByName("pic").getChildByName("icon").active = true;
|
|
}
|
|
})
|
|
.catch(function (error) {
|
|
// console.error('Error fetching X-Info:', error);
|
|
});
|
|
cc.assetManager.loadRemote(url, { ext: '.png' }, function (err, texture) {
|
|
if (texture) {
|
|
_this.node.getChildByName("pic").getChildByName("pic").active = true;
|
|
var sprite = _this.node.getChildByName("pic").getChildByName("pic").getComponent(cc.Sprite);
|
|
sprite.spriteFrame = new cc.SpriteFrame(texture);
|
|
// console.log(this.data.rank,"设置头像成功",err);
|
|
}
|
|
else {
|
|
// console.log("设置头像失败",url);
|
|
// console.log(err,texture)
|
|
}
|
|
});
|
|
};
|
|
ItemRender = __decorate([
|
|
ccclass
|
|
], ItemRender);
|
|
return ItemRender;
|
|
}(cc.Component));
|
|
exports.default = ItemRender;
|
|
|
|
cc._RF.pop(); |