Consume.js 2.7 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. setConfirmButton(button) {
  15. this.button = button;
  16. },
  17. bindData(type) {
  18. let leftIcon = '';
  19. let secondIcon = '';
  20. if (type === JobPageType.ChangeJob) {
  21. leftIcon = './job/change_job_consume_icon';
  22. secondIcon = './job/change_job_card';
  23. this.secondText.string = '<b>转职卡</b><color=#f33e35>(0/15)</color>';
  24. } else {
  25. leftIcon = './job/level_up_consume_icon';
  26. secondIcon = './job/level_up_consume_actor';
  27. this.secondText.string = '<b>转职卡</b><color=#f33e35>(0/15)</color>';
  28. }
  29. cc.loader.loadRes(leftIcon, cc.SpriteFrame, (error, spriteFrame) => {
  30. this.iconSprite.spriteFrame = spriteFrame;
  31. });
  32. cc.loader.loadRes(secondIcon, cc.SpriteFrame, (error, spriteFrame) => {
  33. this.secondSprite.spriteFrame = spriteFrame;
  34. });
  35. },
  36. bindChangeJob(gold, cardInfo, pack) {
  37. this.firstText.string = gold + '';
  38. let cardCount = 0;
  39. if (pack && pack.length > 0) {
  40. cardCount = pack[0].count;
  41. }
  42. this.secondText.string = this.stringFormat(cardInfo.name, cardCount, cardInfo.number);
  43. cc.loader.loadRes('./job/change_job_consume_icon', cc.SpriteFrame, (error, spriteFrame) => {
  44. this.iconSprite.spriteFrame = spriteFrame;
  45. });
  46. cc.loader.loadRes('./job/change_job_card', cc.SpriteFrame, (error, spriteFrame) => {
  47. this.secondSprite.spriteFrame = spriteFrame;
  48. });
  49. },
  50. bindDataLevelUp(gold, cardInfo, pack) {
  51. this.firstText.string = gold + '';
  52. let cardCount = 0;
  53. if (pack && pack.length > 0) {
  54. cardCount = pack[0].count;
  55. }
  56. this.secondText.string = this.stringFormat(cardInfo.name, cardCount, cardInfo.number);
  57. cc.loader.loadRes('./job/level_up_consume_icon', cc.SpriteFrame, (error, spriteFrame) => {
  58. this.iconSprite.spriteFrame = spriteFrame;
  59. });
  60. cc.loader.loadRes('./job/level_up_consume_actor', cc.SpriteFrame, (error, spriteFrame) => {
  61. this.secondSprite.spriteFrame = spriteFrame;
  62. });
  63. },
  64. stringFormat(name, pack, consume) {
  65. this.button.interactable = pack >= consume;
  66. let color = consume > pack ? '#f33e35' : '#ffffff'
  67. return `<b>${name}</b><color=${color}>(${pack}/${consume})</color>`;
  68. },
  69. // update (dt) {},
  70. });