UserInsertCardItem.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. var {GameNotificationKey} = require('../utils/GameEnum');
  2. const PackApi = require('../net/PackApi');
  3. var DWTool = require('../utils/DWTool');
  4. const itemInfo = require('../data/item');
  5. cc.Class({
  6. extends: cc.Component,
  7. properties: {
  8. isHasCard: {
  9. get: function() {
  10. if (!this._isHasCard) {
  11. this._isHasCard = false;
  12. }
  13. return this._isHasCard;
  14. },
  15. set: function(value) {
  16. this._isHasCard = value;
  17. if (this._isHasCard) {
  18. this.cardInfoNode.active = true;
  19. this.noCardNode.active = false;
  20. this.cardLight.runAction(cc.rotateBy(5,360).repeatForever());
  21. } else {
  22. this.cardInfoNode.active = false;
  23. this.noCardNode.active = true;
  24. this.cardLight.stopAllActions();
  25. }
  26. }
  27. },
  28. noCardNode: cc.Node,
  29. cardInfoNode: cc.Node,
  30. timeNode: cc.Node,
  31. timeLabel: cc.Label,
  32. cardLight: cc.Node,
  33. cardSprite: cc.Sprite,
  34. cardTitleLabel: cc.Label,
  35. cardDescRichText: cc.RichText,
  36. unloadButton: cc.Button,
  37. },
  38. // LIFE-CYCLE CALLBACKS:
  39. // onLoad () {},
  40. start () {
  41. },
  42. update (dt) {
  43. if (this.cardInfo && this.isHasCard == true && this.cardInfo.validTime > 0) {
  44. this.cardInfo.validTime -= (dt * 1000);
  45. if (this.cardInfo.validTime > 0) {
  46. this.timeLabel.string = DWTool.calculateTime(this.cardInfo.validTime / 1000);
  47. } else {
  48. this.isHasCard = false;
  49. GameEvent.fire(GameNotificationKey.RefreshInsertCardsInfo,this.cardInfo,false);
  50. }
  51. }
  52. },
  53. onDisable() {
  54. this.cardLight.stopAllActions();
  55. },
  56. cardOpenPack() {
  57. if (this.isHasCard === true) {
  58. return
  59. }
  60. GameEvent.fire(GameNotificationKey.OpenPack,false);
  61. },
  62. configCardInfo(cardInfo,uid) {
  63. this.isHasCard = true;
  64. this.cardInfo = cardInfo;
  65. if (uid != undefined) {
  66. this.uid = uid;
  67. }
  68. var validTime = '永久';
  69. if (cardInfo.validTime > 0) {
  70. this.timeNode.active = true;
  71. this.timeLabel.string = DWTool.calculateTime(cardInfo.validTime / 1000);
  72. this.unloadButton.active = false;
  73. } else {
  74. this.timeNode.active = false;
  75. this.unloadButton.active = true;
  76. }
  77. this.cardTitleLabel.string = cardInfo.name;
  78. cc.loader.loadRes('item/'+this.cardInfo.picId, cc.SpriteFrame, (err, spriteFrame) => {
  79. this.cardSprite.spriteFrame = spriteFrame;
  80. });
  81. this.cardDescRichText.string = '<color=#238310>+'+ cardInfo.defend + '%</color>防守成功率';
  82. },
  83. unloadCard() {
  84. this.unloadButton.enabled = false;
  85. this.postUnloadCard();
  86. },
  87. postUnloadCard() {
  88. if (this.cardInfo != undefined && this.cardInfo.id > 0) {
  89. PackApi.postUnloadCard(this.uid, this.cardInfo.id, (responseData) => {
  90. // console.log("unload card: " + JSON.stringify(responseData));
  91. this.unloadCardSuccess();
  92. }, (error) => {
  93. console.log('unload card error' + error);
  94. this.unloadButton.enabled = true;
  95. });
  96. } else {
  97. this.unloadButton.enabled = true;
  98. }
  99. },
  100. unloadCardSuccess() {
  101. this.unloadButton.enabled = true;
  102. this.isHasCard = false;
  103. GameEvent.fire(GameNotificationKey.RefreshInsertCardsInfo,this.cardInfo,false);
  104. // GameEvent.fire(GameNotificationKey.RefreshPackInfo,this.cardInfo.id,true);
  105. },
  106. });