Consume.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 itemInfo = itemConsume.itemInfo[0];
  36. this.firstText.string = coinNumber + '';
  37. this.secondText.string = this.stringFormat('转职卡', pack[0].count, itemInfo.count);
  38. cc.loader.loadRes('./textures/job/change_job_consume_icon', cc.SpriteFrame, (error, spriteFrame) => {
  39. this.iconSprite.spriteFrame = spriteFrame;
  40. });
  41. cc.loader.loadRes('./textures/job/change_job_card', cc.SpriteFrame, (error, spriteFrame) => {
  42. this.secondSprite.spriteFrame = spriteFrame;
  43. });
  44. },
  45. bindDataLevelUp(itemConsume, pack) {
  46. let coinNumber = itemConsume.coin;
  47. let itemInfo = itemConsume.itemInfo[0];
  48. this.firstText.string = coinNumber + '';
  49. this.secondText.string = this.stringFormat(itemInfo.name, pack[0].count, itemInfo.count);
  50. cc.loader.loadRes('./textures/job/level_up_consume_icon', cc.SpriteFrame, (error, spriteFrame) => {
  51. this.iconSprite.spriteFrame = spriteFrame;
  52. });
  53. cc.loader.loadRes('./textures/job/level_up_consume_actor', cc.SpriteFrame, (error, spriteFrame) => {
  54. this.secondSprite.spriteFrame = spriteFrame;
  55. });
  56. },
  57. stringFormat(name, pack, consume) {
  58. let color = consume > pack ? '#f33e35' : '#ffffff'
  59. return '<b>' + name + '</b><color=' + color + '>(' + pack + '/' + consume + ')</color>';
  60. },
  61. // update (dt) {},
  62. });