illustrative.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * @author heyuchang
  3. */
  4. cc.Class({
  5. extends: cc.Component,
  6. properties: {
  7. container: cc.Node,
  8. avatar: cc.Node,
  9. prefab: cc.Prefab,
  10. },
  11. init(c) {
  12. this._controller = c
  13. if (c.social.node.active) {
  14. let highLevel = c.social.getHighestLevel()
  15. if (highLevel) {
  16. this.showAvatar(highLevel)
  17. this.loadContainer(+highLevel)
  18. } else {
  19. this.avatar.active = false
  20. this.loadContainer(1)
  21. }
  22. } else {
  23. this.avatar.active = false
  24. }
  25. },
  26. showAvatar(level) {
  27. this.avatar.active = true
  28. let data = this._controller.gameData.json.levelData[+level - 1]
  29. let heightScore = this._controller.social.getHighestScore()
  30. this.avatar.getChildByName('name').getComponent(cc.Label).string = 'Historical highest:' + data.name
  31. this.avatar.getChildByName('score').getComponent(cc.Label).string = 'grade:' + heightScore
  32. setTimeout(() => {
  33. this._controller.scoreMgr.characterMgr.showAvatarCharacter(+level, this.avatar.getChildByName('db'))
  34. }, 1000)
  35. },
  36. loadContainer(level) {
  37. let data = this._controller.gameData.json.levelData
  38. this.clearContainer()
  39. setTimeout(() => {
  40. for (let i = 0; i < data.length; i++) {
  41. let card = cc.instantiate(this.prefab)
  42. card.parent = this.container
  43. this.initCard(card, data[i], i, level)
  44. }
  45. }, 1000)
  46. },
  47. clearContainer() {
  48. this.container.children.map(item => {
  49. item.destroy()
  50. })
  51. },
  52. initCard(card, info, level, selfLevel) {
  53. if (level < selfLevel) {
  54. card.getChildByName('name').getComponent(cc.Label).string = info.name
  55. //card.getChildByName('score').getComponent(cc.Label).string = "得分:" + info.score
  56. card.getChildByName('db').color = cc.Color.WHITE
  57. card.getChildByName('giftStep').getComponent(cc.Label).string = "Starting bonus" + info.giftStep + "step"
  58. this._controller.scoreMgr.characterMgr.showCharacter(level + 1, card.getChildByName('db'))
  59. } else {
  60. card.getChildByName('name').getComponent(cc.Label).string = '???'
  61. card.getChildByName('giftStep').getComponent(cc.Label).string = "Starting bonus???step"
  62. card.getChildByName('db').color = cc.Color.BLACK
  63. this._controller.scoreMgr.characterMgr.showCharacter(level + 1, card.getChildByName('db'), cc.Color.BLACK)
  64. }
  65. // this._controller.scoreMgr.characterMgr.showCharacter(level + 1, card.getChildByName('db'), 0)
  66. }
  67. });