202 lines
8.3 KiB
JavaScript
202 lines
8.3 KiB
JavaScript
"use strict";
|
|
cc._RF.push(module, 'e1b90/rohdEk4SdmmEZANaD', 'Helloworld');
|
|
// Script/Helloworld.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 GameData_1 = require("./GameData");
|
|
var List_1 = require("./ListView/List");
|
|
var serverAPI_1 = require("./crypto/serverAPI");
|
|
// import { apiSign } from "./crypto/sign";
|
|
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
|
|
var Helloworld = /** @class */ (function (_super) {
|
|
__extends(Helloworld, _super);
|
|
function Helloworld() {
|
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
_this.Player = null;
|
|
_this.selfNode = null;
|
|
_this.phone = null;
|
|
return _this;
|
|
}
|
|
Helloworld.prototype.onLoad = function () {
|
|
this.rankList = cc.find("ScrollView", this.node).getComponent(List_1.default);
|
|
this.listData = [];
|
|
this.selfData = null;
|
|
this.rankNumber = 100;
|
|
this.rankTotal = 100;
|
|
this.selfNode.opacity = 0;
|
|
};
|
|
Helloworld.prototype.start = function () {
|
|
this.getRank();
|
|
};
|
|
Helloworld.prototype.getRankData = function (data) {
|
|
if (data) {
|
|
console.log(data);
|
|
this.listData = data.data.list;
|
|
this.selfData = data.data.info;
|
|
var rankData = [];
|
|
var self = false;
|
|
for (var i = 0; i <= this.listData.length - 1; i++) {
|
|
rankData.push({ rank: (i + 1), name: this.listData[i].nickName, total: this.listData[i].totalSunCount, pic: this.listData[i].pic });
|
|
if (GameData_1.default._instance.GM_INFO.userId == this.listData[i].userId) {
|
|
self = true;
|
|
this.rankNumber = i;
|
|
this.selfNode.getChildByName("rankLab").getComponent(cc.Label).string = (i + 1) + "";
|
|
}
|
|
if (i == (this.listData.length - 1) && self == false) {
|
|
this.rankNumber = i;
|
|
this.selfNode.getChildByName("rankLab").getComponent(cc.Label).string = "99+";
|
|
}
|
|
}
|
|
this.rankList.setData(rankData);
|
|
if (this.selfData.nickName.length > 6) {
|
|
this.selfData.nickName = this.selfData.nickName.substring(0, 6) + "...";
|
|
}
|
|
this.selfNode.getChildByName("nameLab").getComponent(cc.Label).string = this.selfData.nickName;
|
|
this.selfNode.getChildByName("totalLab").getComponent(cc.Label).string = this.selfData.totalSunCount;
|
|
this.setPic(this.selfData.pic);
|
|
this.setPic2(this.selfData.pic);
|
|
if (this.selfNode.getChildByName("rankLab").getComponent(cc.Label).string == "1") {
|
|
this.selfNode.getChildByName("rank").getChildByName("one").active = true;
|
|
}
|
|
else if (this.selfNode.getChildByName("rankLab").getComponent(cc.Label).string == "2") {
|
|
this.selfNode.getChildByName("rank").getChildByName("two").active = true;
|
|
}
|
|
else if (this.selfNode.getChildByName("rankLab").getComponent(cc.Label).string == "3") {
|
|
this.selfNode.getChildByName("rank").getChildByName("three").active = true;
|
|
}
|
|
else {
|
|
// this.selfNode.getChildByName("four").active = true;
|
|
}
|
|
this.selfNode.opacity = 255;
|
|
}
|
|
};
|
|
Helloworld.prototype.backClick = function () {
|
|
cc.director.loadScene("LoadScene");
|
|
};
|
|
Helloworld.prototype.playerAction = function () {
|
|
var _this = this;
|
|
//-254 377 210 453
|
|
var time = 1;
|
|
this.tween = cc.tween(this.Player)
|
|
.to(2, { position: cc.v3(210, 453, 0) })
|
|
.start();
|
|
time = (this.listData.length - this.rankNumber) / this.listData.length;
|
|
if (this.listData.length >= 99) {
|
|
if (this.rankNumber >= 99) {
|
|
time = (Math.random() * 49 + 1) / 100;
|
|
}
|
|
}
|
|
setTimeout(function () {
|
|
if (_this.tween)
|
|
_this.tween.stop();
|
|
}, time * 2000);
|
|
};
|
|
Helloworld.prototype.getRank = function () {
|
|
var postData = {
|
|
"page": 1,
|
|
"pageSize": 100
|
|
};
|
|
serverAPI_1.default.rankData(2, this.getRankData.bind(this), postData);
|
|
};
|
|
Helloworld.prototype.setPic = function (pic) {
|
|
var _this = this;
|
|
this.phone.node.parent.getChildByName("icon").active = false;
|
|
this.phone.node.active = false;
|
|
var url = pic;
|
|
fetch(url)
|
|
.then(function (response) {
|
|
return response.headers.get('Content-Length');
|
|
})
|
|
.then(function (errNo) {
|
|
if (errNo == "5093") {
|
|
_this.phone.node.parent.getChildByName("icon").active = true;
|
|
}
|
|
})
|
|
.catch(function (error) {
|
|
console.error('Error fetching X-Info:', error);
|
|
});
|
|
var self = this;
|
|
cc.assetManager.loadRemote(url, { ext: '.jpg' }, function (err, texture) {
|
|
if (texture) {
|
|
_this.phone.node.active = true;
|
|
self.phone.spriteFrame = new cc.SpriteFrame(texture);
|
|
}
|
|
else {
|
|
console.log(err, texture);
|
|
}
|
|
});
|
|
};
|
|
Helloworld.prototype.setPic2 = function (pic) {
|
|
var _this = this;
|
|
this.Player.getChildByName("mask").getChildByName("icon").active = false;
|
|
this.Player.getChildByName("mask").getChildByName("phone").active = false;
|
|
var url = pic;
|
|
fetch(url)
|
|
.then(function (response) {
|
|
return response.headers.get('Content-Length');
|
|
})
|
|
.then(function (errNo) {
|
|
if (errNo == "5093") {
|
|
_this.Player.getChildByName("mask").getChildByName("icon").active = true;
|
|
}
|
|
})
|
|
.catch(function (error) {
|
|
console.error('Error fetching X-Info:', error);
|
|
});
|
|
var self = this;
|
|
cc.assetManager.loadRemote(url, { ext: '.jpg' }, function (err, texture) {
|
|
if (texture) {
|
|
_this.Player.getChildByName("mask").getChildByName("phone").active = true;
|
|
_this.Player.getChildByName("mask").getChildByName("phone").getComponent(cc.Sprite)
|
|
.spriteFrame = new cc.SpriteFrame(texture);
|
|
setTimeout(function () {
|
|
_this.playerAction();
|
|
}, 500);
|
|
// console.log("设置头像成功",err);
|
|
}
|
|
else {
|
|
// console.log("设置头像失败",url);
|
|
console.log(err, texture);
|
|
setTimeout(function () {
|
|
_this.playerAction();
|
|
}, 500);
|
|
}
|
|
});
|
|
};
|
|
__decorate([
|
|
property(cc.Node)
|
|
], Helloworld.prototype, "Player", void 0);
|
|
__decorate([
|
|
property(cc.Node)
|
|
], Helloworld.prototype, "selfNode", void 0);
|
|
__decorate([
|
|
property(cc.Sprite)
|
|
], Helloworld.prototype, "phone", void 0);
|
|
Helloworld = __decorate([
|
|
ccclass
|
|
], Helloworld);
|
|
return Helloworld;
|
|
}(cc.Component));
|
|
exports.default = Helloworld;
|
|
|
|
cc._RF.pop(); |