LoginRewardItem.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. const TapTapTool = require("../utils/TapTapTool");
  2. const DWTool = require("../utils/DWTool");
  3. const {GameNotificationKey} = require('../utils/GameEnum');
  4. cc.Class({
  5. extends: cc.Component,
  6. properties: {
  7. dayRichText: cc.RichText,
  8. itemSprite: cc.Sprite,
  9. itemCountRichText: cc.RichText,
  10. isGainNode: cc.Node,
  11. isSigned: {
  12. get: function() {
  13. if (!this._isSigned) {
  14. this._isSigned = false;
  15. }
  16. return this._isSigned;
  17. },
  18. set: function(value) {
  19. this._isSigned = value;
  20. if (this._isSigned) {
  21. this.isGainNode.active = true;
  22. } else {
  23. this.isGainNode.active = false;
  24. }
  25. }
  26. },
  27. },
  28. // LIFE-CYCLE CALLBACKS:
  29. onLoad () {
  30. GameEvent.on(GameNotificationKey.LoginRewardGainOneDay, this, (rewardId) => {
  31. if (this.model.rewardId == rewardId) {
  32. this.isSigned = true;
  33. }
  34. });
  35. },
  36. onDestroy() {
  37. GameEvent.off(GameNotificationKey.LoginRewardGainOneDay, this);
  38. },
  39. start () {
  40. },
  41. init(model) {
  42. this.model = model;
  43. this.configData();
  44. },
  45. configData() {
  46. this.dayRichText.string = `<b>${this.model.title}</b>`;
  47. let gold = TapTapTool.goldStrToClass(this.model.coin);
  48. if (this.model.diamond > 0) {
  49. DWTool.loadResSpriteFrame("./textures/loginReward/login_reward_diamond")
  50. .then((spriteFrame) => {
  51. this.itemSprite.spriteFrame = spriteFrame;
  52. }).catch((err) => {
  53. console.log(err);
  54. });
  55. this.itemCountRichText.string = `<b><outline color=#000000 width=2>钻石 X${this.model.diamond}</outline></b>`;
  56. } else if (gold.n > 0) {
  57. DWTool.loadResSpriteFrame("./textures/loginReward/login_reward_coin")
  58. .then((spriteFrame) => {
  59. this.itemSprite.spriteFrame = spriteFrame;
  60. }).catch((err) => {
  61. console.log(err);
  62. });
  63. this.itemCountRichText.string = `<b><outline color=#000000 width=2>金币 X${TapTapTool.parseToString(gold)}</outline></b>`;
  64. }
  65. if (GameGlobal.userLoginReward.rewardCount >= this.model.rewardId) {
  66. this.isSigned = true;
  67. } else {
  68. this.isSigned = false;
  69. }
  70. }
  71. // update (dt) {},
  72. });