Consume.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. const JobPageType = require('../utils/GameEnum').JobPageType;
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. iconSprite: cc.Sprite,
  6. firstSprite: cc.Sprite,
  7. firstText: cc.RichText,
  8. secondSprite: cc.Sprite,
  9. secondText: cc.RichText,
  10. },
  11. // onLoad () {},
  12. start() {
  13. },
  14. bindData(type) {
  15. let leftIcon = '';
  16. let secondIcon = '';
  17. if (type === JobPageType.ChangeJob) {
  18. leftIcon = './textures/job/change_job_consume_icon';
  19. secondIcon = './textures/job/change_job_card';
  20. this.secondText.string = '<b>转职卡</b><color=#f33e35>(0/15)</color>';
  21. } else {
  22. leftIcon = './textures/job/level_up_consume_icon';
  23. secondIcon = './textures/job/level_up_consume_actor';
  24. this.secondText.string = '<b>转职卡</b><color=#f33e35>(0/15)</color>';
  25. }
  26. cc.loader.loadRes(leftIcon, cc.SpriteFrame, (error, spriteFrame) => {
  27. this.iconSprite.spriteFrame = spriteFrame;
  28. });
  29. cc.loader.loadRes(secondIcon, cc.SpriteFrame, (error, spriteFrame) => {
  30. this.secondSprite.spriteFrame = spriteFrame;
  31. });
  32. },
  33. bindChangeJob(itemConsume, pack) {
  34. let coinNumber = itemConsume.coin;
  35. let itemInfoCount = itemConsume.itemInfo ? itemConsume.itemInfo[0].count : 0;
  36. this.firstText.string = coinNumber + '';
  37. let cardCount = 0;
  38. if (pack && pack.length > 0) {
  39. cardCount = pack[0].count;
  40. }
  41. this.secondText.string = this.stringFormat('转职卡', cardCount, itemInfoCount);
  42. cc.loader.loadRes('./textures/job/change_job_consume_icon', cc.SpriteFrame, (error, spriteFrame) => {
  43. this.iconSprite.spriteFrame = spriteFrame;
  44. });
  45. cc.loader.loadRes('./textures/job/change_job_card', cc.SpriteFrame, (error, spriteFrame) => {
  46. this.secondSprite.spriteFrame = spriteFrame;
  47. });
  48. },
  49. bindDataLevelUp(itemConsume, pack) {
  50. let coinNumber = itemConsume.coin;
  51. let itemInfoCount = itemConsume.itemInfo ? itemConsume.itemInfo[0].count : 0;
  52. this.firstText.string = coinNumber + '';
  53. let cardCount = 0;
  54. if (pack && pack.length > 0) {
  55. cardCount = pack[0].count;
  56. }
  57. this.secondText.string = this.stringFormat(itemConsume.itemInfo[0].name, cardCount, itemInfoCount);
  58. cc.loader.loadRes('./textures/job/level_up_consume_icon', cc.SpriteFrame, (error, spriteFrame) => {
  59. this.iconSprite.spriteFrame = spriteFrame;
  60. });
  61. cc.loader.loadRes('./textures/job/level_up_consume_actor', cc.SpriteFrame, (error, spriteFrame) => {
  62. this.secondSprite.spriteFrame = spriteFrame;
  63. });
  64. },
  65. stringFormat(name, pack, consume) {
  66. let color = consume > pack ? '#f33e35' : '#ffffff'
  67. return `<b>${name}</b><color=${color}>(${pack}/${consume})</color>`;
  68. },
  69. // update (dt) {},
  70. });