123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- var Sprite = require('./libs/sprite.js').Sprite
- var Label = require('./libs/label.js').Label
- function RankItem(x, y, width, height) {
- this.x = x;
- this.y = y;
- this.width = width;
- this.height = height;
- }
- RankItem.prototype.create = function() {
- let labelOffset = 62;
- let labelStyle = "#3C8E39FF";
- let fontSize = "35px";
- // if(this.id%2 == 0)
- // {
- // this.rankbg = new Sprite("openDataContext/asset/paihang_1_4.png",this.x, this.y + this.height * 0.5 - 150 * 0.5, 650, 140);
- // this.rankbg.parent = this;
- // }
- this.rankLabel = new Label(this.x + 75, this.y + labelOffset);
- this.rankLabel.fontSize = "55px";
- this.rankLabel.fillStyle = labelStyle;
- this.rankLabel.textAlign = 'center';
- this.rankLabel.font = "Microsoft YaHei";
- let rankWidth = 67;
- let rankHeight = 63;
- this.rankimg = new Sprite('openDataContext/asset/paihang_1_6_1.png', this.x + 20, this.y + this.height * 0.5 - rankHeight * 0.5, rankWidth, rankHeight);
- let offsetX = 90;
- let iconWidth = 76;
- let iconHeight = 76;
- this.icon = new Sprite('', this.x + offsetX + 30, this.y + this.height * 0.5 - iconHeight * 0.5, iconWidth, iconHeight);
- this.nameLabel = new Label(this.x + 210, this.y + labelOffset);
- this.nameLabel.fontSize = fontSize;
- this.nameLabel.fillStyle = labelStyle;
- this.nameLabel.font = "Microsoft YaHei";
- this.nameLabel.textcolor = "000000FF";
- this.scoreNum = new Label(this.x + this.width - 130, this.y + 66);
- this.scoreNum.fontSize = "55px";
- this.scoreNum.fillStyle = labelStyle;
- this.scoreNum.textAlign = "center"
- this.scoreNum.font = "Microsoft YaHei";
- this.scoreLabel = new Label(this.x + this.width - 50, this.y + labelOffset);
- this.scoreLabel.fontSize = fontSize;
- this.scoreLabel.fillStyle = labelStyle;
- this.scoreLabel.textAlign = "right"
- this.scoreLabel.font = "Microsoft YaHei";
- }
- RankItem.prototype.getBgFillStyle = function(num) {
- let rankNum = num;
- let style = "#7E7E7E";
- if (num % 2 == 1) {
- style = "#B4B4B4";
- }
- return style;
- }
- var rank1url = "openDataContext/asset/rank1.png";
- var rank2url = "openDataContext/asset/rank2.png";
- var rank3url = "openDataContext/asset/rank3.png";
- var bgImg = "openDataContext/asset/bg.png";
- RankItem.prototype.getRankUrl = function(num) {
- let rankNum = num;
- let url = "";
- switch (rankNum) {
- case 1:
- url = rank1url;
- break;
- case 2:
- url = rank2url;
- break;
- case 3:
- url = rank3url;
- break;
- default:
- url = "";
- break;
- }
- return url;
- }
- RankItem.prototype.setData = function(rankNum, iconUrl, name, score, keyName) {
- this.icon.src = iconUrl;
- this.nameLabel.text = name;
- this.scoreNum.text = score;
- this.scoreLabel.text ="第 关";
- this.rankLabel.text = rankNum;
- if (rankNum <= 3) {
- //this.rankLabel.visible = false;
- //this.rankimg.visible = true;
- //this.rankimg.src = this.getRankUrl(rankNum);
- } else {
- //this.rankLabel.visible = true;
- //this.rankimg.visible = false;
- //this.rankLabel.text = rankNum;
- }
- }
- RankItem.prototype.position = function(x, y) {
- this.x = x;
- this.y = y;
- let labelOffset = 80;
- this.rankLabel.position(this.x + 45, this.y + labelOffset);
- let rankWidth = 51;
- let rankHeight = 73;
- //this.rankimg.position(this.x + 20, this.y + this.height * 0.5 - rankHeight * 0.5);
- let offsetX = 90;
- let iconWidth = 76;
- let iconHeight = 76;
- this.icon.position(this.x + offsetX + 10, this.y + this.height * 0.5 - iconHeight * 0.5);
- this.nameLabel.position(this.x + 210, this.y + labelOffset);
- this.scoreLabel.position(this.x + this.width - 50, this.y + labelOffset);
- }
- RankItem.prototype.drawToCanvas = function(ctx) {
- this.rankLabel.drawToCanvas(ctx);
- this.scoreNum.drawToCanvas(ctx);
- this.icon.drawToCanvas(ctx);
- this.nameLabel.drawToCanvas(ctx);
- this.scoreLabel.drawToCanvas(ctx);
- }
- module.exports.RankItem = RankItem;
|