| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002 |
- import date from "../Unit/date.js"
- cc.Class({
- extends: cc.Component,
- properties: {
- StoreScrollView: {
- default: null,
- type: cc.ScrollView
- },
- Seed: {
- default: null,
- type: cc.Node,
- },
- Exchange: {
- default: null,
- type: cc.Node,
- },
- SeedBtn: {
- default: null,
- type: cc.Node,
- },
- ExchangeBtn: {
- default: null,
- type: cc.Node,
- },
- EquipmentCotainer: {
- default: null,
- type: cc.Node,
- },
- EquipmentBtn: {
- default: null,
- type: cc.Node,
- },
- SelectedFrame: cc.Node,
- ManageUI: cc.Node,
- //四个按钮对应的sprite
- Normal_Seed_Sprite: cc.SpriteFrame,
- Selecteded_Seed_Sprite: cc.SpriteFrame,
- Normal_Exchange_Sprite: cc.SpriteFrame,
- Selecteded_Exchange_Sprite: cc.SpriteFrame,
- Normal_EquipmentBtn_Sprite: cc.SpriteFrame,
- Selecteded_EquipmentBtn_Sprite: cc.SpriteFrame,
- //需要切换节点顺序的父节点
- container: cc.Node,
- //商城的列表
- mySeedList: [],
- seedPrefab: cc.Prefab,
- seedSpriteFrame: {
- default: [],
- type: [cc.SpriteFrame],
- },
- //商城的图标列表
- mySeedIconList: {
- default: [],
- type: [cc.SpriteFrame],
- },
- seedNodeArry: {
- default: [],
- type: [cc.Node],
- serializable: false,
- visible: false,
- },
- //装备start---
- equipmentList: [],
- equipPrefab: cc.Prefab,
- equipNodeArry: {
- default: [],
- type: [cc.Node],
- serializable: false,
- visible: false,
- },
- equipSpriteFrame: {
- default: [],
- type: [cc.SpriteFrame],
- },
- equipIconList: {
- default: [],
- type: [cc.SpriteFrame],
- },
- buyEquipIndex: -1,
- PayEquipPopView: {
- default: null,
- type: cc.Node,
- },
- //装备end---
- snbAmount: 0,
- luckyAmount: 0,
- playAmount: 0,
- ExchangePopView: {
- default: null,
- type: cc.Node,
- },
- ExchangeLuckyPopView: {
- default: null,
- type: cc.Node,
- },
- PayCNTPopView: {
- default: null,
- type: cc.Node,
- },
- PaySNBPopView: {
- default: null,
- type: cc.Node,
- },
- buySeedIndex: -1,
- snbAmountLabel: {
- default: null,
- type: cc.Label,
- },
- luckyAmountLabel: {
- default: null,
- type: cc.Label,
- },
- //拿到仓库列表的节点
- buildingView: {
- default: null,
- type: cc.Node,
- },
- myWareHouseSeedList: null,
- //轮询种子列表状态
- AutoGetSeedsData: null,
- //轮询防护包装备等
- AutoGetEquipsData: null,
- seedsView: {
- default: null,
- type: cc.Node,
- },
- // ExchangeView: {
- // default: null,
- // type: cc.Node,
- // },
- seedBottomLabel: {
- default: null,
- type: cc.Node,
- },
- scrollViewNode: {
- default: null,
- type: cc.Node,
- },
- //购买种类数值
- toggleInputValue: {
- default: '1',
- visible: false,
- },
- PayCNTPopViewNameLabel: {
- default: null,
- type: cc.Label,
- },
- PayCNTPopViewCNTLabel: {
- default: null,
- type: cc.Label,
- },
- PayCNTPopViewSNBLabel: {
- default: null,
- type: cc.Label,
- },
- PayCNTPopViewMutureDurLabel: {
- default: null,
- type: cc.Label,
- },
- PopViewSeed: {
- default: null,
- type: cc.Sprite,
- },
- isPlaying: false,
- //拿到申请列表的节点
- applySnbView: {
- default: null,
- type: cc.Node,
- },
- },
- HiddenAll() {
- if (this.Seed.active) this.Seed.active = false
- if (this.Exchange.active) this.Exchange.active = false
- if (this.EquipmentCotainer.active) this.EquipmentCotainer.active = false;
- if (this.StoreScrollView) {
- this.StoreScrollView.stopAutoScroll();
- this.StoreScrollView.scrollToTop();
- }
- },
- start() {
- //获取到仓库列表的脚本
- this.buildingViewScript = this.buildingView.getComponent('BuildingView')
- //默认设置第一个节点为 最上面
- this.SeedBtn.setSiblingIndex(10)
- // console.log('SNB=======', GlobalD.GameData.SNB)
- this.snbAmountLabel.string = GlobalD.GameData.SNB
- this.luckyAmountLabel.string = GlobalD.GameData.GetLucky();
- //这里也初始化获取一个数据
- GlobalD.GameData.getWarehouseSeedAndFruit((vaule) => {
- this.myWareHouseSeedList = vaule.data.seed
- })
- //获取种子和果实
- GlobalD.GameData.getMallSeed((vaule) => {
- this.mySeedList = vaule.data
- // console.log('this.mySeedList[i]=', this.mySeedList);
- for (let i = 0; i < this.mySeedList.length; i++) {
- //没有种子数量不显示 todo 看看后续需不需要处理删除
- //if (this.mySeedList[i].amount < 1) continue;
- let _seed = cc.instantiate(this.seedPrefab)
- //if (this.mySeedList[i].amount < 1)
- if (this.mySeedList[i].amount < 1) {
- _seed.getChildByName("Sell").active = false;
- _seed.getChildByName("SellOut").active = true;
- } else {
- _seed.getChildByName("Sell").active = true;
- _seed.getChildByName('SellOut').active = false
- }
- // _seed.getChildByName("buy_button").active = true;
- // _seed.getChildByName("Name").active = false;
- // _seed.getChildByName("Name").getChildByName("Num").getComponent(cc.Label).strng = '';//'x'+this.mySeedList[i].amount;
- this.seedNodeArry.push(_seed)
- _seed.parent = this.Seed
- let _seedScript = _seed.getComponent('Content_Button')
- _seedScript.Name = this.mySeedList[i].name
- _seedScript.Price = ''
- _seedScript.CNT = this.mySeedList[i].priceCnt
- _seedScript.SNB = this.mySeedList[i].priceSnb
- _seedScript.Mature = "成熟期:" + this.mySeedList[i].maturity + '天'
- _seedScript.Synopsis = this.mySeedList[i].seedDescribe
- //设置一个生成点
- let _spawnScript = _seed.getComponent('Content_seed')
- _spawnScript.myIndex = i
- _spawnScript.SpawnPoint = cc.find('Canvas/SpawnParent/SpawnPoint')
- _seedScript.NumLabel.string = this.mySeedList[i].amount
- _seedScript.NameLabel.string = this.mySeedList[i].name
- switch (this.mySeedList[i].picture) {
- case 'Cabbage':
- _seedScript.bgSprite.spriteFrame = this.mySeedIconList[0] //this.seedSpriteFrame[0];
- break
- case 'Potato':
- _seedScript.bgSprite.spriteFrame = this.mySeedIconList[1] //this.seedSpriteFrame[1];
- break
- case 'Carrot':
- _seedScript.bgSprite.spriteFrame = this.mySeedIconList[2] //this.seedSpriteFrame[2];
- break
- case 'Broccoli':
- _seedScript.bgSprite.spriteFrame = this.mySeedIconList[3] //this.seedSpriteFrame[3];
- break
- case 'Tomato':
- _seedScript.bgSprite.spriteFrame = this.mySeedIconList[4] //this.seedSpriteFrame[4];
- break
- case 'Squash':
- _seedScript.bgSprite.spriteFrame = this.mySeedIconList[5] //this.seedSpriteFrame[5];
- break
- case 'Eggplant':
- _seedScript.bgSprite.spriteFrame = this.mySeedIconList[6] //this.seedSpriteFrame[6];
- break
- case 'Pepper':
- _seedScript.bgSprite.spriteFrame = this.mySeedIconList[7] //this.seedSpriteFrame[7];
- break
- case 'Lentil':
- _seedScript.bgSprite.spriteFrame = this.mySeedIconList[8] //this.seedSpriteFrame[8];
- break
- default:
- break
- }
- this.mySeedList[i].bgSpriteFrame = _seedScript.bgSprite.spriteFrame;
- }
- })
- //获取装备列表
- GlobalD.GameData.onGetMallEquipmentList((vaule) => {
- this.equipmentList = vaule.data
- console.log('this.equipmentList=', this.equipmentList);
- for (let i = 0; i < this.equipmentList.length; i++) {
- let _equip = cc.instantiate(this.equipPrefab)
- if (this.equipmentList[i].amount < 1) {
- _equip.getChildByName("Sell").active = false;
- _equip.getChildByName("SellOut").active = true;
- } else {
- _equip.getChildByName("Sell").active = true;
- _equip.getChildByName('SellOut').active = false
- }
- this.equipNodeArry.push(_equip)
- _equip.parent = this.EquipmentCotainer;
- let _equipScript = _equip.getComponent('Content_Button')
- _equipScript.Name = this.equipmentList[i].name
- // _equipScript.Price = ''
- _equipScript.CNT = this.equipmentList[i].priceCnt;
- _equipScript.SNB = this.equipmentList[i].priceSnb
- _equipScript.Mature = "有效期:" + this.equipmentList[i].effectiveDay + '天'
- _equipScript.Synopsis = this.equipmentList[i].itemDescribe;
- //设置一个生成点
- let _spawnScript = _equip.getComponent('Content_equip')
- _spawnScript.onSetStoreView(this.node);
- _spawnScript.myIndex = i
- _equipScript.NumLabel.string = this.equipmentList[i].amount
- _equipScript.NameLabel.string = this.equipmentList[i].name
- switch (this.equipmentList[i].picture) {
- case 'dog':
- _equipScript.bgSprite.spriteFrame = this.equipIconList[0];
- _equipScript.showConsumeType = 2;
- break
- case 'beatDogStick':
- _equipScript.bgSprite.spriteFrame = this.equipIconList[1];
- _equipScript.showConsumeType = 2;
- break
- case 'natural':
- _equipScript.bgSprite.spriteFrame = this.equipIconList[2];
- _equipScript.showConsumeType = 1;
- break
- case 'beast':
- _equipScript.bgSprite.spriteFrame = this.equipIconList[3];
- _equipScript.showConsumeType = 1;
- break
- default:
- break
- }
- this.equipmentList[i].bgSpriteFrame = _equipScript.bgSprite.spriteFrame;
- }
- })
- },
- //切换建筑的面板
- onSwitchBuildingContent(event, index) {
- this.SeedBtn.getComponent(cc.Sprite).spriteFrame = this.Normal_Seed_Sprite
- this.ExchangeBtn.getComponent(cc.Sprite).spriteFrame =
- this.Normal_Exchange_Sprite
- this.EquipmentBtn.getComponent(cc.Sprite).spriteFrame = this.Normal_EquipmentBtn_Sprite
- this.HiddenAll()
- //面板设置index
- //种子
- if ('0' == index) {
- this.SeedBtn.getComponent(cc.Sprite).spriteFrame =
- this.Selecteded_Seed_Sprite
- this.Seed.active = true
- if (this.seedNodeArry.length != 0) {
- this.SelectedFrame.parent = this.seedNodeArry[0]
- }
- this.scrollViewNode.active = true
- this.seedBottomLabel.active = true
- this.seedsView.active = true
- this.Exchange.active = false
- }
- //兑换
- else if ('1' == index) {
- this.ExchangeBtn.getComponent(cc.Sprite).spriteFrame =
- this.Selecteded_Exchange_Sprite
- this.scrollViewNode.active = false
- this.seedBottomLabel.active = false
- this.seedsView.active = false
- this.Exchange.active = true
- }
- //装备
- else if ('2' == index) {
- this.EquipmentBtn.getComponent(cc.Sprite).spriteFrame =
- this.Selecteded_EquipmentBtn_Sprite
- this.EquipmentCotainer.active = true;
- this.scrollViewNode.active = true
- this.seedBottomLabel.active = true
- this.seedsView.active = true
- this.Exchange.active = false
- }
- },
- switch: function () {
- var children = this.container.children
- var length = children.length
- if (length > 1) {
- var src = Math.floor(Math.random() * length)
- var node = children[src]
- var dst = src === length - 1 ? 0 : src + 1
- node.setSiblingIndex(dst)
- }
- },
- OpentSNBExchangeToCNT() {
- // GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "转换CNT通道关闭!", 1);
- // return;
- //限制相关人员交易
- if (1 === GlobalD.UserInfo.limitTran) {
- GlobalD.GameData.showToast(
- cc.find('Canvas/UICamera'),
- '转换CNT通道关闭,请联系相关管理人员!',
- 1
- )
- return
- }
- //更新数据
- this.snbAmountLabel.string = GlobalD.GameData.SNB
- this.ExchangePopView.active = true
- },
- SNBExchangeToCNT() {
- //限制相关人员交易
- if (1 === GlobalD.UserInfo.limitTran) {
- GlobalD.GameData.showToast(
- cc.find('Canvas/UICamera'),
- '转换CNT通道关闭,请联系相关管理人员!',
- 1
- )
- return
- }
- if (0 === Number(this.snbAmount) || 0 != Number(this.snbAmount) % 5) {
- GlobalD.GameData.showToast(
- cc.find('Canvas/UICamera'),
- '请输入5的倍数兑换!',
- 1
- )
- return
- }
- console.log('发起兑换:' + Number(this.snbAmount))
- GlobalD.GameData.onSnbToCnt(Number(this.snbAmount), (data) => {
- //更新数据
- this.snbAmountLabel.string = GlobalD.GameData.SNB
- this.ExchangePopView.active = false
- console.log('data=', data)
- // console.log('res=', res)
- })
- },
- /**
- * 提交申请
- */
- onApplyingTran() {
- //限制相关人员交易
- if (1 === GlobalD.UserInfo.limitTran) {
- GlobalD.GameData.showToast(
- cc.find('Canvas/UICamera'),
- '转换CNT通道关闭,请联系相关管理人员!',
- 1
- )
- return
- }
- if (0 === Number(this.snbAmount) || 0 != Number(this.snbAmount) % 5) {
- GlobalD.GameData.showToast(
- cc.find('Canvas/UICamera'),
- '请输入5的倍数兑换!',
- 1
- )
- return
- }
- console.log('申请兑换:' + Number(this.snbAmount))
- GlobalD.GameData.onPostApplySnbToCnt(Number(this.snbAmount), (value) => {
- console.log("兑换", value);
- if (0 === value.code) {
- this.ExchangePopView.active = false
- GlobalD.GameData.showToast(
- cc.find('Canvas/UICamera'),
- '已提交申请,详情见申请列表兑换CNT。',
- 2
- )
- } else {
- GlobalD.GameData.showToast(
- cc.find('Canvas/UICamera'),
- value.msg,
- 2
- )
- }
- });
- },
- /**
- * 幸运值转换snb
- * @returns
- */
- OpenLuckyExchangeToSNB() {
- //限制相关人员交易
- if (1 === GlobalD.UserInfo.limitTran) {
- GlobalD.GameData.showToast(
- cc.find('Canvas/UICamera'),
- '转换SNB通道关闭,请联系相关管理人员!',
- 1
- )
- return
- }
- //更新数据
- this.luckyAmountLabel.string = GlobalD.GameData.GetLucky();
- this.ExchangeLuckyPopView.active = true
- },
- LuckyExchangeToSNB() {
- //限制相关人员交易
- if (1 === GlobalD.UserInfo.limitTran) {
- GlobalD.GameData.showToast(
- cc.find('Canvas/UICamera'),
- '转换SNB通道关闭,请联系相关管理人员!',
- 1
- )
- return
- }
- if (0 >= Number(this.luckyAmount) || 0 != Number(this.luckyAmount) % 50) {
- GlobalD.GameData.showToast(
- cc.find('Canvas/UICamera'),
- '请输入50的倍数兑换!',
- 1
- )
- return
- }
- console.log('发起兑换:' + Number(this.luckyAmount))
- GlobalD.GameData.onPostLuckToSnb({ luckNum: Number(this.luckyAmount) }, (value) => {
- //更新数据
- this.luckyAmountLabel.string = GlobalD.GameData.GetLucky();
- console.log(GlobalD.GameData.GetLucky());
- this.ExchangeLuckyPopView.active = false;
- })
- },
- onTextChangedLucky: function (text, editbox, customEventData) {
- var numberTemp = new RegExp('^[A-Za-z0-9]+$')
- if (numberTemp.test(text)) {
- if (Number(text) >= 1) {
- this.luckyAmount = Number(text)
- } else {
- this.luckyAmount = 0
- editbox.string = this.luckyAmount
- }
- } else {
- this.luckyAmount = 0
- editbox.string = this.luckyAmount
- console.log('请输入50的倍数', this.luckyAmount)
- }
- },
- onPayCNTPopView(myIndex) {
- this.buySeedIndex = myIndex
- this.PayCNTPopView.active = true
- this._updatePrice()
- },
- onPaySNBPopView(myIndex) {
- this.buySeedIndex = myIndex
- this.PaySNBPopView.active = true
- // console.log('this.mySeedList[this.buySeedIndex] =',this.mySeedList[this.buySeedIndex])
- this.PaySNBPopView.getChildByName('BG')
- .getChildByName('BG1_sprite_splash')
- .getChildByName('NameLabel')
- .getChildByName('label')
- .getComponent(cc.Label).string = this.mySeedList[this.buySeedIndex].name
- this.PaySNBPopView.getChildByName('BG')
- .getChildByName('BG1_sprite_splash')
- .getChildByName('PriceLabel')
- .getChildByName('label')
- .getComponent(cc.Label).string =
- this.mySeedList[this.buySeedIndex].priceCnt + ' SNB'
- this.PaySNBPopView.getChildByName('BG')
- .getChildByName('BG1_sprite_splash')
- .getChildByName('MutureDurLabel')
- .getChildByName('label')
- .getComponent(cc.Label).string =
- this.mySeedList[this.buySeedIndex].maturity
- },
- PayCNT() {
- console.log('this.playAmount=', this.playAmount)
- console.log(
- 'this.playAmount price=',
- this.playAmount * parseInt(this.mySeedList[this.buySeedIndex].priceCnt)
- )
- //购买种子也要使用轮询
- let currentAmount = 0
- for (let i = 0; i < this.myWareHouseSeedList.length; i++) {
- if (
- this.myWareHouseSeedList[i].id == this.mySeedList[this.buySeedIndex].id
- ) {
- currentAmount = this.myWareHouseSeedList[i].amount
- }
- }
- //当前背包的数量
- console.log('currentAmount:', {
- seedId: this.mySeedList[this.buySeedIndex].id,
- currentAmount: currentAmount, //把当前背包的数据传进去
- })
- let playAmount =
- this.playAmount * parseInt(this.mySeedList[this.buySeedIndex].priceCnt)
- if (0 === playAmount) {
- GlobalD.GameData.showToast(
- cc.find('Canvas/UICamera'),
- '请输入购买数量',
- 1
- )
- return
- }
- // if (this.isPlaying) {
- // GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "购买过快!", 1);
- // return;
- // }
- // this.isPlaying = true;
- // GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "区块确认中,请耐心等待!", 120);
- GlobalD.GameData.payCNT(
- playAmount,
- 4,
- this.mySeedList[this.buySeedIndex].id + '',
- (data) => {
- const [err, tx] = data
- // this.isPlaying = false;
- if (err === null) {
- // TODO 成功, 支付为链上操作,需要提供回调接口给这边服务端确认交易成功后修改购买订单结果
- console.log(tx) // 交易hash,唯一标识符
- //todo 种子
- if (this.AutoGetSeedsData) {
- this.unschedule(this.AutoGetSeedsData)
- this.AutoGetSeedsData = null
- }
- this.AutoGetSeedsData = () => {
- // getSeedCount ++;
- GlobalD.GameData.onGetSeedState(
- {
- seedId: this.mySeedList[this.buySeedIndex].id,
- currentAmount: currentAmount, //把当前背包的数据传进去
- },
- (value) => {
- console.log('轮询种子:' + JSON.stringify(value))
- if (0 === value.code) {
- this.unschedule(this.AutoGetSeedsData)
- console.log('轮询种子购买成功')
- GlobalD.GameData.showToast(
- cc.find('Canvas/UICamera'),
- '种子购买成功!',
- 1
- )
- // this.PayCNTPopView.active = false;
- //直接重新初始化一下列表,
- this.buildingViewScript.onUpdateList()
- }
- }
- )
- }
- this.schedule(this.AutoGetSeedsData, 5)
- } else {
- console.log(err)
- GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), err, 2)
- }
- }
- )
- },
- PaySNB() {
- console.log('this.playAmount=', this.playAmount)
- console.log('priceSnb price=', this.mySeedList[this.buySeedIndex].priceSnb)
- console.log(
- 'this.playAmount price=',
- this.playAmount * parseInt(this.mySeedList[this.buySeedIndex].priceSnb)
- )
- console.log(
- '支付价格:' +
- this.playAmount * parseInt(this.mySeedList[this.buySeedIndex].priceSnb)
- )
- let playAmount =
- this.playAmount * parseInt(this.mySeedList[this.buySeedIndex].priceSnb)
- if (0 === playAmount) {
- GlobalD.GameData.showToast(
- cc.find('Canvas/UICamera'),
- '请输入购买数量',
- 1
- )
- return
- }
- if (this.isPlaying) {
- GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), '购买过快!', 1)
- return
- }
- GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), '支付处理中...', 10)
- this.isPlaying = true
- GlobalD.GameData.onBuySeedsWithSNB(
- playAmount,
- this.mySeedList[this.buySeedIndex].id,
- (flag, value) => {
- // console.log("SNB购买后", value);
- this.isPlaying = false
- if (flag && 0 === value.code) {
- //todo 种子
- GlobalD.GameData.showToast(
- cc.find('Canvas/UICamera'),
- '种子购买成功!',
- 1
- )
- // this.PayCNTPopView.active = false;
- //重新获取一下snb,会自动更新到面板
- GlobalD.GameData.onGetUserSnb()
- //直接重新初始化一下列表,
- this.buildingViewScript.onUpdateList()
- //更新日志数据
- cc.find('GameNode/ManageDapp')
- .getComponent('ManageDapp')
- .onUpdateSnbList()
- } else {
- GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), value.msg, 2)
- }
- }
- )
- },
- onTextChanged1: function (text, editbox, customEventData) {
- // 这里的 text 表示 修改完后的 EditBox 的文本内容
- // 这里 editbox 是一个 cc.EditBox 对象
- // 这里的 customEventData 参数就等于你之前设置的 "foobar"
- // this.playAmount = parseInt(text)
- var numberTemp = new RegExp('^[A-Za-z0-9]+$')
- if (numberTemp.test(text)) {
- if (Number(text) >= 1) {
- this.playAmount = Number(text)
- } else {
- this.playAmount = 0
- editbox.string = this.playAmount
- }
- } else {
- this.playAmount = 0
- editbox.string = this.playAmount
- // console.log('playAmount', this.snbAmount)
- }
- },
- // 假设这个回调是给 textChanged 事件的
- onTextChanged2: function (text, editbox, customEventData) {
- // 这里的 text 表示 修改完后的 EditBox 的文本内容
- // 这里 editbox 是一个 cc.EditBox 对象
- // 这里的 customEventData 参数就等于你之前设置的 "foobar"
- // this.snbAmount = parseInt(text);
- var numberTemp = new RegExp('^[A-Za-z0-9]+$')
- if (numberTemp.test(text)) {
- if (Number(text) >= 1) {
- this.snbAmount = Number(text)
- } else {
- this.snbAmount = 0
- editbox.string = this.snbAmount
- }
- } else {
- this.snbAmount = 0
- editbox.string = this.snbAmount
- console.log('请输入5的倍数', this.snbAmount)
- }
- },
- _updatePrice() {
- this.PayCNTPopViewNameLabel.string = this.mySeedList[this.buySeedIndex].name;
- this.PayCNTPopViewCNTLabel.string = this.mySeedList[this.buySeedIndex].priceCnt;
- this.PayCNTPopViewSNBLabel.string = this.mySeedList[this.buySeedIndex].priceSnb;
- this.PayCNTPopViewMutureDurLabel.string = this.mySeedList[this.buySeedIndex].maturity;
- this.PopViewSeed.spriteFrame = this.mySeedList[this.buySeedIndex].bgSpriteFrame;
- // switch (this.toggleInputValue) {
- // case '1':
- // this.PayCNTPopViewNameLabel.string =
- // this.mySeedList[this.buySeedIndex].name
- // this.PayCNTPopViewCNTLabel.string =
- // this.mySeedList[this.buySeedIndex].priceCnt + ' CNT'
- // this.PayCNTPopViewMutureDurLabel.string =
- // this.mySeedList[this.buySeedIndex].maturity
- // break
- // case '2':
- // this.PayCNTPopViewNameLabel.string =
- // this.mySeedList[this.buySeedIndex].name
- // this.PayCNTPopViewCNTLabel.string =
- // this.mySeedList[this.buySeedIndex].priceSnb + ' SNB'
- // this.PayCNTPopViewMutureDurLabel.string =
- // this.mySeedList[this.buySeedIndex].maturity
- // break
- // default:
- // console.error(
- // 'this.toggleInputValue 不是1 2 3!',
- // this.toggleInputValue
- // )
- // break
- // }
- },
- //根据状态吊起不同支付
- onSwitchPlayType() {
- switch (this.toggleInputValue) {
- case '1': //cnt 支付
- this.PayCNT()
- break
- case '2': //snb 支付
- this.PaySNB()
- break
- default:
- console.error('状态吊起错误', this.toggleInputValue)
- GlobalD.GameData.showToast(
- cc.find('Canvas/UICamera'),
- '请先选择支付方式',
- 1
- )
- break
- }
- },
- onToggleInput(value, evnentData) {
- this.toggleInputValue = evnentData
- this._updatePrice()
- },
- //购买装备
- onPayEquipPopView(myIndex) {
- this.buyEquipIndex = myIndex
- this.PayEquipPopView.active = true
- this.PayEquipPopView.getComponent("PayEquipPopView").setInfo(this.equipmentList[this.buyEquipIndex]);
- },
- PayEquipSNB() {
- console.log(
- '支付价格Snb:' + this.equipmentList[this.buyEquipIndex].priceSnb
- )
- if (this.isPlaying) {
- GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), '购买过快!', 1)
- return
- }
- GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), '支付处理中...', 10)
- this.isPlaying = true
- GlobalD.GameData.onGetAddEquipment(
- { mallOtherId: this.equipmentList[this.buyEquipIndex].id },
- (flag, value) => {
- console.log("SNB购买后", value);
- this.isPlaying = false
- if (flag && 0 === value.code) {
- let _equip = value.data.equip;
- //todo 装备
- GlobalD.GameData.showToast(
- cc.find('Canvas/UICamera'),
- '购买装备成功',
- 1
- )
- //重新获取一下snb,会自动更新到面板
- GlobalD.GameData.onGetUserSnb()
- if (0 === _equip.otherType) {
- GlobalD.Dog = _equip;
- this.ManageUI.getComponent('ManageUI').onSettingDogAlpha(255);
- //刷新狗状态
- let _dogContainerScript = cc.find("Canvas/DogContainer").getComponent("DogContainer")
- _dogContainerScript.onSetSelfDogState(_equip);
- } else if (1 === _equip.otherType) {
- GlobalD.Stick = _equip;
- this.ManageUI.getComponent('ManageUI').onSettingStickAlpha(255);
- }
- //更新日志数据
- cc.find('GameNode/ManageDapp')
- .getComponent('ManageDapp')
- .onUpdateSnbList()
- } else {
- GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), value.msg, 2)
- }
- }
- )
- },
- //用cnt购买
- PayEquipCNT() {
- console.log(
- '支付价格Cnt:' + this.equipmentList[this.buyEquipIndex].priceCnt + ",购买类型:" + this.equipmentList[this.buyEquipIndex].otherType
- )
- if (!(this.equipmentList[this.buyEquipIndex].otherType == 2 || this.equipmentList[this.buyEquipIndex].otherType == 3)) return;
- if (this.isPlaying) {
- GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), '购买过快!', 1)
- return
- }
- GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), '支付处理中...', 10)
- this.isPlaying = true
- let playAmount = this.equipmentList[this.buyEquipIndex].priceCnt
- if (0 === playAmount) {
- GlobalD.GameData.showToast(
- cc.find('Canvas/UICamera'),
- 'CNT不能为0!',
- 1
- )
- return
- }
- GlobalD.GameData.payCNT(
- playAmount,
- this.equipmentList[this.buyEquipIndex].otherType,// payType
- this.equipmentList[this.buyEquipIndex].id + '',
- (data) => {
- const [err, tx] = data
- this.isPlaying = false;
- if (err === null) {
- // TODO 成功, 支付为链上操作,需要提供回调接口给这边服务端确认交易成功后修改购买订单结果
- console.log(tx) // 交易hash,唯一标识符
- //todo 轮询装备
- if (this.AutoGetEquipsData) {
- this.unschedule(this.AutoGetEquipsData)
- this.AutoGetEquipsData = null
- }
- this.AutoGetEquipsData = () => {
- GlobalD.GameData.onGetDisasterProtected((value) => {
- if (0 === value.code) {
- // console.log('轮询购买防护包:' + JSON.stringify(value))
- let data = value.data;
- if (this.equipmentList[this.buyEquipIndex].otherType == 2) {
- if (GlobalD.NaturalPack == null) {
- if (data.naturalProtected != null) {
- this.unschedule(this.AutoGetEquipsData)
- GlobalD.GameData.showToast(
- cc.find('Canvas/UICamera'),
- '购买自然防护包成功!',
- 1
- )
- this.ManageUI.getComponent('ManageUI').onRunProtected(value);
- }
- } else if (!date.datesIsEqual(data.naturalProtected.protectTime, GlobalD.NaturalPack.protectTime)) {
- this.unschedule(this.AutoGetEquipsData)
- GlobalD.GameData.showToast(
- cc.find('Canvas/UICamera'),
- '增加自然防护包成功!',
- 1
- )
- this.ManageUI.getComponent('ManageUI').onRunProtected(value);
- }
- } else if (this.equipmentList[this.buyEquipIndex].otherType == 3) {
- if (GlobalD.BeastPack == null) {
- if (data.beastProtected != null) {
- this.unschedule(this.AutoGetEquipsData)
- GlobalD.GameData.showToast(
- cc.find('Canvas/UICamera'),
- '购买野兽防护包成功!',
- 1
- )
- this.ManageUI.getComponent('ManageUI').onRunProtected(value);
- }
- } else if (!date.datesIsEqual(data.beastProtected.protectTime, GlobalD.BeastPack.protectTime)) {
- this.unschedule(this.AutoGetEquipsData)
- //如果时间不相等,叠加时间成功
- GlobalD.GameData.showToast(
- cc.find('Canvas/UICamera'),
- '增加野兽防护包成功!',
- 1
- )
- this.ManageUI.getComponent('ManageUI').onRunProtected(value);
- }
- } else {
- this.unschedule(this.AutoGetEquipsData)
- }
- }
- })
- }
- this.schedule(this.AutoGetEquipsData, 5)
- } else {
- console.log(err)
- GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), err, 2)
- }
- }
- )
- },
- onDestory() {
- if (this.AutoGetSeedsData) {
- this.unschedule(this.AutoGetSeedsData)
- this.AutoGetSeedsData = null
- }
- },
- //申请列表
- OpenApplyList() {
- this.applySnbView.active = true;
- }
- })
|