GameRankItem.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. // update (dt) {},
  60. });