GameRankItem.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. const Api = require('../net/Api');
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. headDefaultSpriteFrame: cc.SpriteFrame,
  6. headSprite: cc.Sprite,
  7. background: cc.Sprite,
  8. rankSprite: cc.Sprite,
  9. rankRichText: cc.RichText,
  10. nameLabel: cc.Label,
  11. lvRichText: cc.RichText,
  12. rankSpriteFrame: [cc.SpriteFrame],
  13. backgroundSpriteFrame: [cc.SpriteFrame],
  14. isMe: {
  15. get: function() {
  16. if (!this._isMe) {
  17. this._isMe = false;
  18. }
  19. return this._isMe;
  20. },
  21. set: function(value) {
  22. this._isMe = value;
  23. if (this._isMe) {
  24. this.background.spriteFrame = this.backgroundSpriteFrame[1];
  25. } else {
  26. this.background.spriteFrame = this.backgroundSpriteFrame[0];
  27. }
  28. }
  29. },
  30. },
  31. // LIFE-CYCLE CALLBACKS:
  32. // onLoad () {},
  33. init (model, isMe = false) {
  34. this.configData(model);
  35. this.isMe = isMe;
  36. },
  37. start () {
  38. },
  39. configData(model) {
  40. this.headSprite.spriteFrame = this.headDefaultSpriteFrame;
  41. if (model.head) {
  42. Api.createImageFromUrl(model.head, (spriteFrame) => {
  43. this.headSprite.spriteFrame = spriteFrame;
  44. });
  45. }
  46. if (model.rank < 4) {
  47. this.rankSprite.node.active = true;
  48. this.rankRichText.node.active = false;
  49. this.rankSprite.spriteFrame = this.rankSpriteFrame[(model.rank - 1)];
  50. } else {
  51. this.rankSprite.node.active = false;
  52. this.rankRichText.node.active = true;
  53. let rank = (model.rank > 100) ? "100+" : model.rank;
  54. this.rankRichText.string = `<b><outline color=#692e0e width=2><color=white>${rank}</color></outline></b>`;
  55. }
  56. this.nameLabel.string = model.nick;
  57. this.lvRichText.string = `<b><outline color=white width=2><color=#934C31>LV.${model.buildingLevel}</color></outline></b>`;
  58. },
  59. initQQData(model, isMe = false) {
  60. this.model = model;
  61. this.isMe = isMe;
  62. // model 的字段如下:
  63. //var rd = {
  64. // url: '', // 头像的 url
  65. // nick: '', // 昵称
  66. // score: 1, // 分数
  67. // selfFlag: false, // 是否是自己
  68. //};
  69. this.headSprite.spriteFrame = this.headDefaultSpriteFrame;
  70. if (model.url) {
  71. Api.createImageFromUrl(model.url, (spriteFrame) => {
  72. this.headSprite.spriteFrame = spriteFrame;
  73. });
  74. }
  75. if (model.rank < 4) {
  76. this.rankSprite.node.active = true;
  77. this.rankRichText.node.active = false;
  78. this.rankSprite.spriteFrame = this.rankSpriteFrame[(model.rank - 1)];
  79. } else {
  80. this.rankSprite.node.active = false;
  81. this.rankRichText.node.active = true;
  82. let rank = (model.rank > 100) ? "100+" : model.rank;
  83. this.rankRichText.string = `<b><outline color=#692e0e width=2><color=white>${rank}</color></outline></b>`;
  84. }
  85. this.nameLabel.string = model.nick;
  86. this.lvRichText.string = `<b><outline color=white width=2><color=#934C31>LV.${model.score}</color></outline></b>`;
  87. }
  88. // update (dt) {},
  89. });