Consume.js 3.3 KB

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