| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- import { HTTP_TYPE } from "../../datas/CommonData";
- import { RichData } from "../../datas/RichData";
- import AdM from "../../manager/AdM";
- import GameM, { AUDIO_TYPE } from "../../manager/GameM";
- import HttpM from "../../manager/HttpM";
- import EffectNode from "../../ui/EffectNode";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class BookItem extends cc.Component {
- @property(cc.Label)
- txtNum: cc.Label = null;
- @property(cc.Label)
- txtTitle: cc.Label = null;
- @property(cc.Sprite)
- slider: cc.Sprite = null;
- @property(cc.Label)
- txtSlider: cc.Label = null;
- @property(cc.Node)
- btnGet: cc.Node = null;
- @property(cc.Node)
- btnNo: cc.Node = null;
- id = 0;
- jadeNum = 0;
- needBook = 1000;
- isInit: boolean = false;
- onEnable() {
- if (this.isInit) {
- this.slider.fillRange = RichData.Ins.scriptureNum / this.needBook;
- this.txtSlider.string = RichData.Ins.scriptureNum + "/" + this.needBook;
- this.btnGet.active = RichData.Ins.scriptureNum >= this.needBook;
- this.btnNo.active = RichData.Ins.scriptureNum < this.needBook;
- }
- }
- Init(id: number, jade: number, book: number) {
- this.id = id;
- this.jadeNum = jade;
- this.needBook = book;
- this.txtTitle.string = "收集兵书x" + book;
- this.txtNum.string = jade + "";
- this.slider.fillRange = RichData.Ins.scriptureNum / book;
- this.txtSlider.string = RichData.Ins.scriptureNum + "/" + book;
- this.btnGet.active = RichData.Ins.scriptureNum >= book;
- this.btnNo.active = RichData.Ins.scriptureNum < book;
- this.isInit = true;
- }
- // update (dt) {}
- isCanClick: boolean = true;
- Click_GetBtn() {
- if (!this.isCanClick) return;
- this.isCanClick = false;
- HttpM.Instance.SendData(HTTP_TYPE.richManJadeCash, { id: this.id }, (res) => {
- console.log("--->jade cash:", res);
- if (res.data && res.data.code == 1) {
- if (res.data.code == 1) {
- GameM.commonData.updateRedMoney(this.jadeNum);
- //EffectNode.instance.PlayCoinAnim(1, 20, cc.v2(0, -300));
- RichData.Ins.PlayParticleEft(10002,1, this.node);
- RichData.Ins.CheckCanCollectBook();
- cc.tween(this.node)
- .to(0.3, { opacity: 0 })
- .call(() => {
- this.destroy();
- this.node.destroy();
- })
- .start();
- } else {
- EffectNode.instance.PlayTip(res.data.msg);
- }
- }
- this.isCanClick = true;
- }, null, () => {
- this.isCanClick = true;
- }, null, false);
- //HttpM.Instance.SendData(HTTP_TYPE.richManUpdateLattice, { lattice: this.curPageIndex + 1, pageIndex: this.latticePage }, (res) => {
- // console.log("--->update lattice:", res);
- //}, null, null, null, false);
- GameM.audioM.playEffect(AUDIO_TYPE.button);
- AdM.onSendEvent('Qujing_Exchange_Book', '取经经书奖励兑换', "qujing");
- }
- Click_NoBtn() {
- console.log("book not enough");
- EffectNode.instance.PlayTip("兵书不足");
- //HttpM.Instance.SendData(HTTP_TYPE.richManJadeCash, { id: this.id }, (res) => {
- // console.log("--->jade cash:", res);
- //
- // cc.tween(this.node)
- // .to(0.3, { opacity: 0 })
- // .call(() => {
- // this.destroy();
- // this.node.destroy();
- // })
- // .start();
- //}, null, null, null, false);
- GameM.audioM.playEffect(AUDIO_TYPE.button);
- }
- }
|