rankitem.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. var Sprite = require('./libs/sprite.js').Sprite
  2. var Label = require('./libs/label.js').Label
  3. function RankItem(x, y, width, height) {
  4. this.x = x;
  5. this.y = y;
  6. this.width = width;
  7. this.height = height;
  8. }
  9. RankItem.prototype.create = function() {
  10. let labelOffset = 55;
  11. let labelStyle = "#ffffff";
  12. let fontSize = "35px";
  13. // this.rankbg = new Sprite("openDataContext/asset/paiwei_xin_1_6_1.png",this.x, this.y + this.height * 0.5 - 150 * 0.5, 650, 140);
  14. // this.rankbg.parent = this;
  15. this.rankLabel = new Label(this.x + 100, this.y + labelOffset+5);
  16. this.rankLabel.fontSize = "40px";
  17. this.rankLabel.fillStyle = labelStyle;
  18. this.rankLabel.textAlign = 'center';
  19. this.rankLabel.fontFamily = "Microsoft YaHei";
  20. let rankWidth = 38;
  21. let rankHeight = 48;
  22. this.rankimg = new Sprite('', this.x + 80, this.y+25/** + this.height * 0.5 - rankHeight * 0.5*/, rankWidth, rankHeight);
  23. let offsetX = 75;
  24. let iconWidth = 56;
  25. let iconHeight = 56;
  26. this.icon = new Sprite('', this.x + offsetX + 50, this.y+20 /**+ this.height * 0.5 - iconHeight * 0.5*/, iconWidth, iconHeight);
  27. this.nameLabel = new Label(this.x + 190, this.y + labelOffset);
  28. this.nameLabel.fontSize = fontSize;
  29. this.nameLabel.fillStyle = labelStyle;
  30. this.nameLabel.fontFamily = "Microsoft YaHei";
  31. this.scoreNum = new Label(this.x + this.width - 160, this.y + 55);
  32. this.scoreNum.fontSize = "35px";
  33. this.scoreNum.fillStyle = labelStyle;
  34. this.scoreNum.textAlign = "center"
  35. this.scoreNum.fontFamily = "Microsoft YaHei";
  36. this.scoreLabel = new Label(this.x + this.width - 100, this.y + labelOffset);
  37. this.scoreLabel.fontSize = fontSize;
  38. this.scoreLabel.fillStyle = labelStyle;
  39. this.scoreLabel.textAlign = "right"
  40. this.scoreLabel.fontFamily = "Microsoft YaHei";
  41. }
  42. RankItem.prototype.getBgFillStyle = function(num) {
  43. let rankNum = num;
  44. let style = "#ffffff";
  45. if (num % 2 == 1) {
  46. style = "#ffffff";
  47. }
  48. return style;
  49. }
  50. var rank1url = "BtmopenDataContext/asset/paihang-1-3.png";
  51. var rank2url = "BtmopenDataContext/asset/paihang-1-4.png";
  52. var rank3url = "BtmopenDataContext/asset/paihang-1-5.png";
  53. var bgImg = "openDataContext/asset/bg.png";
  54. RankItem.prototype.getRankUrl = function(num) {
  55. let rankNum = num;
  56. let url = "";
  57. switch (rankNum) {
  58. case 1:
  59. url = rank1url;
  60. break;
  61. case 2:
  62. url = rank2url;
  63. break;
  64. case 3:
  65. url = rank3url;
  66. break;
  67. default:
  68. url = "";
  69. break;
  70. }
  71. return url;
  72. }
  73. RankItem.prototype.setData = function(rankNum, iconUrl, name, score, keyName) {
  74. this.icon.src = iconUrl;
  75. this.nameLabel.text = name;
  76. this.scoreNum.text = score;
  77. this.scoreLabel.text ="第 关";
  78. this.rankLabel.text = rankNum;
  79. if (rankNum <= 3) {
  80. this.rankLabel.visible = false;
  81. this.rankimg.visible = true;
  82. this.rankimg.src = this.getRankUrl(rankNum);
  83. } else {
  84. this.rankLabel.visible = true;
  85. this.rankimg.visible = false;
  86. this.rankLabel.text = rankNum;
  87. }
  88. }
  89. RankItem.prototype.position = function(x, y) {
  90. this.x = x;
  91. this.y = y;
  92. let labelOffset = 80;
  93. this.rankLabel.position(this.x + 50, this.y + labelOffset);
  94. let rankWidth = 51;
  95. let rankHeight = 73;
  96. this.rankimg.position(this.x + 30, this.y )//+ this.height * 0.5 - rankHeight * 0.5);
  97. let offsetX = 90;
  98. let iconWidth = 60;
  99. let iconHeight = 60;
  100. this.icon.position(this.x + offsetX + 30, this.y-10)// + this.height * 0.5 - iconHeight * 0.5);
  101. this.nameLabel.position(this.x + 110, this.y + labelOffset);
  102. this.scoreLabel.position(this.x + this.width - 50, this.y + labelOffset);
  103. }
  104. RankItem.prototype.drawToCanvas = function(ctx) {
  105. this.rankLabel.drawToCanvas(ctx);
  106. this.rankimg.drawToCanvas(ctx);
  107. this.scoreNum.drawToCanvas(ctx);
  108. this.icon.drawToCanvas(ctx);
  109. this.nameLabel.drawToCanvas(ctx);
  110. this.scoreLabel.drawToCanvas(ctx);
  111. }
  112. module.exports.RankItem = RankItem;