zhuguoqing ff550d5d6a init
2022-05-22 10:32:02 +08:00

233 lines
5.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var PAGE_SIZE = 76;
var ITEM_HEIGHT = 76;
var OFFSET_X = -40;
var OFFSET_Y_ORIGIN = 0;
var OFFSET_Y = -8;
var CLIP_HEIGHT = 360;
var CLIP_WIDTH =800
var TODAYKEY = "datakey1"
var assets = {
btn:"wx-open-data-project/btn.png",
};
function preloadAssets() {
var preloaded = 0;
var count = 0;
for (var asset in assets) {
count++;
var img = wx.createImage();
img.onload = function () {
preloaded++;
if (preloaded == count) {
}
}
img.src = assets[asset];
assets[asset] = img;
}
}
var RANK_STRING = "stage"
var RankListRenderer = /** @class */ function () {
//console.log('test2');
this.totalPage = 0;
this.currPage = 0;
this.myrank = 0;
this.todayopenids = []
this.stagecfg=[]
this.gameDatas = []; //https://developers.weixin.qq.com/minigame/dev/document/open-api/data/UserGameData.html
this.init();
};
RankListRenderer.prototype.init = function () {
//console.log('test3');
this.canvas = wx.getSharedCanvas();
this.ctx = this.canvas.getContext('2d');
this.ctx.imageSmoothingEnabled = true;
this.ctx.imageSmoothingQuality = "high";
this.showFriendRank = false;
this.itemCount = 0;
this.todaysharecount = 0;
this.limitsharecout = 999;
this.shareurl = " "
this.sharetitle =" "
this.oldheight = this.canvas.height
this.oldwidth = this.canvas.width
this.avatarImages2 = []
this.nodeplayfriendlist = []
//this.getMyselfInfo(); 排行榜相关 暂时屏蔽
// this.cleantodaykey(); 排行榜相关 暂时屏蔽
// console.log('111111111111111111')
this.refreshnotplaylist();//获取没玩过列表
// console.log('22222222222222222222')
};
RankListRenderer.prototype.refreshnotplaylist = function(){
var self = this
wx.getPotentialFriendList({
success: (data) => {
let list = data.list || [];
console.log('getPotentialFriendList', data);
self.nodeplayfriendlist = list
self.avatarImages2 = []
for(let i=0;i<list.length;i++){
let avatarImg = wx.createImage();
self.avatarImages2.push(avatarImg);
if(list[i].avatarUrl){
avatarImg.src = list[i].avatarUrl;
}
}
}
});
}
RankListRenderer.prototype.getMyselfInfo = function () {
var _this = this;
wx.getUserInfo({
openIdList: ['selfOpenId'],
success: function (res) {
_this.myselfAvatarUrl = res.data[0].avatarUrl;
_this.myName = res.data[0].nickName;
}
});
};
RankListRenderer.prototype.listen = function () {
this.statu = 0;/*0:指正在游戏1显示排行榜2显示群排行3显示短排行榜4显示单人排行*/
wx.onMessage(msg => {
switch (msg.type) {
case 'displayinfo'://渲染
this.ctx.clearRect(0, 0, 1024, 512);
this.drawinvitelist()
break;
case 'clear':
this.statu = 0;
this.showFriendRank = false;
this.clearAll();
this.refreshnotplaylist();//刷新玩家列表
break;
case 'sharetofriend':
this.dosharetofriend(msg.idx)//邀请
break;
case 'sharepic':
this.shareurl = msg.url
this.sharetitle = msg.title
break;
case 'changerank':
this.updaterank(msg.num);
break;
default:
console.log("未知消息类型:msg.type=" + msg.type);
break;
}
});
};
RankListRenderer.prototype.dosharetofriend = function (idx) {
var vidx = Number(idx)-1
if(!this.nodeplayfriendlist[vidx]){
return
}
wx.shareMessageToFriend&&wx.shareMessageToFriend({
openId:this.nodeplayfriendlist[vidx].openid,
imageUrl:this.shareurl,
title:this.sharetitle,
success:function(res){
},
})
}
RankListRenderer.prototype.updaterank = function (num) {
console.log(num)
var kvDataList = new Array();
kvDataList.push({key:'winrank',value:'num'});
wx.setUserCloudStorage&&wx.setUserCloudStorage({
KVDataList:kvDataList,
success:function(res){
console.log("setUserCloudStorage success");
},
fail:function(res){
console.log("setUserCloudStorage fail");
},
complete:function(res){
console.log(res);
}
});
}
RankListRenderer.prototype.drawinvitelist = function () {
var ctx =this.ctx
var len = this.nodeplayfriendlist.length
if(len>5){
len = 5
}
ctx.fillStyle = "#000000";
ctx.textAlign = "left";
ctx.textBaseline = "middle";
for(var i=0;i<len;i++){
var dt = this.nodeplayfriendlist[i]
if(this.avatarImages2[i]){
ctx.drawImage(this.avatarImages2[i], 20, 10+i*60, 40, 40);
}
//名字
ctx.fillStyle = "#FFFFFF";
ctx.font = "bold 24px 黑体, sans-serif";
var nick = dt.nickname.length <= 5 ? dt.nickname : dt.nickname.substr(0, 5) + "...";
ctx.fillText(nick, 68, 25+i*60);
ctx.drawImage(assets.btn,240, 12+i*60, 80, 40);
ctx.fillStyle = "#FFFFFF";
ctx.font = "bold 24px 黑体, sans-serif";
ctx.strokeStyle = "#000000";
ctx.strokeText("邀请",255, 30+i*60);
ctx.fillText("邀请", 255, 30+i*60);
//avatarUrl nickname openid
}
}
RankListRenderer.prototype.clearAll = function(data){
this.ctx.clearRect(0, 0, CLIP_WIDTH, CLIP_HEIGHT+500);
};
var rankList = new RankListRenderer();
rankList.listen();
preloadAssets()
//console.log('test0');