InviteMissionItem.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. const DWTool = require("../utils/DWTool");
  2. const {GameNotificationKey, GameRedDot} = require('../utils/GameEnum');
  3. const InviteApi = require('../net/InviteApi');
  4. const TapTapTool = require("../utils/TapTapTool");
  5. const GameModule = require("../utils/GameModule");
  6. //任务状态[0 : 完成可领取, 1 : 未完成, 2 : 完成已领取]
  7. var InviteMissionItemType = cc.Enum({
  8. Gain: 0,
  9. NoFinished: 1,
  10. Finished: 2
  11. });
  12. cc.Class({
  13. extends: cc.Component,
  14. properties: {
  15. awardNode1: cc.Node,
  16. awardItemNode1: cc.Node,
  17. countLabel1: cc.Label,
  18. awardRichText: cc.RichText,
  19. noButton: cc.Button,
  20. gainButton: cc.Button,
  21. finishButton: cc.Button,
  22. },
  23. // LIFE-CYCLE CALLBACKS:
  24. // onLoad () {},
  25. start () {
  26. },
  27. hideAllButton() {
  28. this.noButton.node.active = false;
  29. this.gainButton.node.active = false;
  30. this.finishButton.node.active = false;
  31. },
  32. onDisable() {
  33. },
  34. configData(model, invitedCount) {
  35. this.model = model;
  36. this.hideAllButton();
  37. switch (model.state) {
  38. case InviteMissionItemType.NoFinished:
  39. this.noButton.node.active = true;
  40. break;
  41. case InviteMissionItemType.Finished:
  42. this.finishButton.node.active = true;
  43. break;
  44. case InviteMissionItemType.Gain:
  45. this.gainButton.node.active = true;
  46. break;
  47. }
  48. let diamond = model.diamond;
  49. if (diamond > 0) {
  50. this.awardNode1.active = true;
  51. cc.loader.loadRes("/textures/invite/talent_invite_diamond", cc.SpriteFrame, (err, spriteFrame) => {
  52. if (err) {
  53. } else {
  54. this.awardItemNode1.getComponent('cc.Sprite').spriteFrame = spriteFrame;
  55. }
  56. });
  57. this.countLabel1.string = DWTool.coinParse(diamond);
  58. }
  59. if (invitedCount >= model.count) {
  60. this.awardRichText.string = `<color=#362E2B>邀请奖励</c>\n<color=#AF7434>(好友:${model.count}/${model.count}名)</c>`;
  61. } else {
  62. this.awardRichText.string = `<color=#362E2B>邀请奖励</c>\n<color=#AF7434>(好友:${invitedCount}/${model.count}名)</c>`;
  63. }
  64. },
  65. gainAward() {
  66. InviteApi.postGainAward(this.model.id, (responseData) => {
  67. if (responseData.isCancel) {
  68. TapTapTool.removeRedDot(GameRedDot.inviteFriend);
  69. }
  70. this.refreshButtonState();
  71. }, (error) => {
  72. GameGlobal.commonAlert.showCommonErrorAlert("领取失败");
  73. });
  74. },
  75. refreshButtonState() {
  76. GameModule.audioMng.playGetAward();
  77. this.model.state = InviteMissionItemType.Finished;
  78. this.hideAllButton();
  79. this.finishButton.node.active = true;
  80. GameEvent.fire(GameNotificationKey.InviteGainAward, this.model);
  81. },
  82. // update (dt) {},
  83. });