rankitem.js 3.8 KB

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