InviteMissionItem.js 2.8 KB

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