| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- /**
- * 积分兑换种子
- */
- cc.Class({
- extends: cc.Component,
- properties: {
- inputValue: {
- default: 1,
- visible: false
- },
- //输入节点
- inputContainer: {
- default: null,
- type: cc.Node,
- serializable: true
- },
- //1 对应第一个种子,2对应第二个种子,3对应第三个种子
- toggleInputValue: {
- default: '0',
- visible: false,
- serializable:false
- },
- seeds: {
- default: [],
- visible: false
- },
- seedsIcon: {
- default: [],
- type: [cc.Sprite]
- },
- buildingView: cc.Node,
- availableCNT: {
- default: null,
- type: cc.Label
- },
- consumeCNT: {
- default: null,
- type: cc.Label
- }
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad() {
- this.buildingViewScript = this.buildingView.getComponent('BuildingView');
- //获取一个随机种子
- GlobalD.GameData.onGetPlayerSeeds((value) => {
- // console.log("onGetPlayerSeeds:", value);
- if (0 === value.code && value.flag) {
- this.availableCNT.string = value.data.score.oldTotalCnt + "/" + value.data.score.totalCount;
- this.seeds = value.data.seeds;
- for (let i = 0; i < 3; i++) {
- if (i >= this.seeds.length) return;
- switch (this.seeds[i].picture) {
- case 'Cabbage':
- this.seedsIcon[i].spriteFrame = this.buildingViewScript.seedIconSpriteFrame[0];
- break
- case 'Potato':
- this.seedsIcon[i].spriteFrame = this.buildingViewScript.seedIconSpriteFrame[1];
- break
- case 'Carrot':
- this.seedsIcon[i].spriteFrame = this.buildingViewScript.seedIconSpriteFrame[2];
- break
- case 'Broccoli':
- this.seedsIcon[i].spriteFrame = this.buildingViewScript.seedIconSpriteFrame[3];
- break
- case 'Tomato':
- this.seedsIcon[i].spriteFrame = this.buildingViewScript.seedIconSpriteFrame[4];
- break
- case 'Squash':
- this.seedsIcon[i].spriteFrame = this.buildingViewScript.seedIconSpriteFrame[5];
- break
- case 'Eggplant':
- this.seedsIcon[i].spriteFrame = this.buildingViewScript.seedIconSpriteFrame[6];
- break
- case 'Pepper':
- this.seedsIcon[i].spriteFrame = this.buildingViewScript.seedIconSpriteFrame[7];
- break
- case 'Lentil':
- this.seedsIcon[i].spriteFrame = this.buildingViewScript.seedIconSpriteFrame[8];
- break
- default:
- console.error("兑换种子信息错误?");
- break
- }
- }
- this._updatePrice();
- }
- })
- },
- // start() {
- // },
- onToggleInput(value, evnentData) {
- // console.log(value.isChecked, evnentData);
- this.toggleInputValue = evnentData;
- this._updatePrice();
- },
- onOpenInfo() {
- this.node.active = true;
- },
- onClose() {
- this.node.active = false;
- },
- inputEditValue(value, e) {
- var numberTemp = new RegExp("^[A-Za-z0-9]+$");
- let limitValue = 10;
- if (numberTemp.test(value)) {
- if (Number(value) >= 1 && Number(value) <= limitValue) {
- this.inputValue = Number(value);
- } else if (Number(value) > limitValue) {
- //限制只能输入100
- this.inputValue = limitValue;
- this.inputContainer.getComponent(cc.EditBox).string = this.inputValue;
- } else {
- this.inputValue = 1;
- this.inputContainer.getComponent(cc.EditBox).string = this.inputValue;
- }
- } else {
- this.inputValue = 1;
- this.inputContainer.getComponent(cc.EditBox).string = this.inputValue;
- // console.log("请输入整数的倍数", this.inputValue);
- }
- this._updatePrice();
- },
- _updatePrice() {
- let currtSeed = this.seeds[Number(this.toggleInputValue)];
- this.consumeCNT.string = '消耗积分:' + this.inputValue * currtSeed.priceCnt;
- },
- onExchangeSeed() {
- let data = { amount: this.inputValue, seedId: this.seeds[Number(this.toggleInputValue)].id }
- GlobalD.GameData.onGetPlayerScore(data, (value) => {
- // console.log("onGetPlayerScore:", value);
- if (0 === value.code && value.flag) {
- // this.seeds = value;
- this.availableCNT.string = value.data.score.oldTotalCnt + "/" + value.data.score.totalCount;
- //更新仓库
- this.buildingViewScript.onUpdateList();
- GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), value.msg, 2);
- } else {
- GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), value.msg, 2);
- }
- });
- }
- });
|