BookItem.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import { HTTP_TYPE } from "../../datas/CommonData";
  2. import { RichData } from "../../datas/RichData";
  3. import AdM from "../../manager/AdM";
  4. import GameM, { AUDIO_TYPE } from "../../manager/GameM";
  5. import HttpM from "../../manager/HttpM";
  6. import EffectNode from "../../ui/EffectNode";
  7. const { ccclass, property } = cc._decorator;
  8. @ccclass
  9. export default class BookItem extends cc.Component {
  10. @property(cc.Label)
  11. txtNum: cc.Label = null;
  12. @property(cc.Label)
  13. txtTitle: cc.Label = null;
  14. @property(cc.Sprite)
  15. slider: cc.Sprite = null;
  16. @property(cc.Label)
  17. txtSlider: cc.Label = null;
  18. @property(cc.Node)
  19. btnGet: cc.Node = null;
  20. @property(cc.Node)
  21. btnNo: cc.Node = null;
  22. id = 0;
  23. jadeNum = 0;
  24. needBook = 1000;
  25. isInit: boolean = false;
  26. onEnable() {
  27. if (this.isInit) {
  28. this.slider.fillRange = RichData.Ins.scriptureNum / this.needBook;
  29. this.txtSlider.string = RichData.Ins.scriptureNum + "/" + this.needBook;
  30. this.btnGet.active = RichData.Ins.scriptureNum >= this.needBook;
  31. this.btnNo.active = RichData.Ins.scriptureNum < this.needBook;
  32. }
  33. }
  34. Init(id: number, jade: number, book: number) {
  35. this.id = id;
  36. this.jadeNum = jade;
  37. this.needBook = book;
  38. this.txtTitle.string = "收集兵书x" + book;
  39. this.txtNum.string = jade + "";
  40. this.slider.fillRange = RichData.Ins.scriptureNum / book;
  41. this.txtSlider.string = RichData.Ins.scriptureNum + "/" + book;
  42. this.btnGet.active = RichData.Ins.scriptureNum >= book;
  43. this.btnNo.active = RichData.Ins.scriptureNum < book;
  44. this.isInit = true;
  45. }
  46. // update (dt) {}
  47. isCanClick: boolean = true;
  48. Click_GetBtn() {
  49. if (!this.isCanClick) return;
  50. this.isCanClick = false;
  51. HttpM.Instance.SendData(HTTP_TYPE.richManJadeCash, { id: this.id }, (res) => {
  52. console.log("--->jade cash:", res);
  53. if (res.data && res.data.code == 1) {
  54. if (res.data.code == 1) {
  55. GameM.commonData.updateRedMoney(this.jadeNum);
  56. //EffectNode.instance.PlayCoinAnim(1, 20, cc.v2(0, -300));
  57. RichData.Ins.PlayParticleEft(10002,1, this.node);
  58. RichData.Ins.CheckCanCollectBook();
  59. cc.tween(this.node)
  60. .to(0.3, { opacity: 0 })
  61. .call(() => {
  62. this.destroy();
  63. this.node.destroy();
  64. })
  65. .start();
  66. } else {
  67. EffectNode.instance.PlayTip(res.data.msg);
  68. }
  69. }
  70. this.isCanClick = true;
  71. }, null, () => {
  72. this.isCanClick = true;
  73. }, null, false);
  74. //HttpM.Instance.SendData(HTTP_TYPE.richManUpdateLattice, { lattice: this.curPageIndex + 1, pageIndex: this.latticePage }, (res) => {
  75. // console.log("--->update lattice:", res);
  76. //}, null, null, null, false);
  77. GameM.audioM.playEffect(AUDIO_TYPE.button);
  78. AdM.onSendEvent('Qujing_Exchange_Book', '取经经书奖励兑换', "qujing");
  79. }
  80. Click_NoBtn() {
  81. console.log("book not enough");
  82. EffectNode.instance.PlayTip("兵书不足");
  83. //HttpM.Instance.SendData(HTTP_TYPE.richManJadeCash, { id: this.id }, (res) => {
  84. // console.log("--->jade cash:", res);
  85. //
  86. // cc.tween(this.node)
  87. // .to(0.3, { opacity: 0 })
  88. // .call(() => {
  89. // this.destroy();
  90. // this.node.destroy();
  91. // })
  92. // .start();
  93. //}, null, null, null, false);
  94. GameM.audioM.playEffect(AUDIO_TYPE.button);
  95. }
  96. }