|
@@ -2,7 +2,7 @@ cc.Class({
|
|
|
extends: cc.Component,
|
|
extends: cc.Component,
|
|
|
|
|
|
|
|
properties: {
|
|
properties: {
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
Seed: {
|
|
Seed: {
|
|
|
default: null,
|
|
default: null,
|
|
|
type: cc.Node,
|
|
type: cc.Node,
|
|
@@ -19,9 +19,9 @@ cc.Class({
|
|
|
default: null,
|
|
default: null,
|
|
|
type: cc.Node,
|
|
type: cc.Node,
|
|
|
},
|
|
},
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
SelectedFrame: cc.Node,
|
|
SelectedFrame: cc.Node,
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
//Building40: cc.Node,
|
|
//Building40: cc.Node,
|
|
|
ManageUI: cc.Node,
|
|
ManageUI: cc.Node,
|
|
|
//四个按钮对应的sprite
|
|
//四个按钮对应的sprite
|
|
@@ -36,7 +36,7 @@ cc.Class({
|
|
|
|
|
|
|
|
//商城的列表
|
|
//商城的列表
|
|
|
mySeedList: [],
|
|
mySeedList: [],
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
seedPrefab: cc.Prefab,
|
|
seedPrefab: cc.Prefab,
|
|
|
|
|
|
|
|
seedSpriteFrame: {
|
|
seedSpriteFrame: {
|
|
@@ -48,8 +48,8 @@ cc.Class({
|
|
|
default: [],
|
|
default: [],
|
|
|
type: [cc.Node]
|
|
type: [cc.Node]
|
|
|
},
|
|
},
|
|
|
- snbAmount:0,
|
|
|
|
|
- cntAmount:0,
|
|
|
|
|
|
|
+ snbAmount: 0,
|
|
|
|
|
+ cntAmount: 0,
|
|
|
ExchangePopView: {
|
|
ExchangePopView: {
|
|
|
default: null,
|
|
default: null,
|
|
|
type: cc.Node,
|
|
type: cc.Node,
|
|
@@ -58,12 +58,25 @@ cc.Class({
|
|
|
default: null,
|
|
default: null,
|
|
|
type: cc.Node,
|
|
type: cc.Node,
|
|
|
},
|
|
},
|
|
|
- buySeedIndex:-1,
|
|
|
|
|
-
|
|
|
|
|
|
|
+ buySeedIndex: -1,
|
|
|
|
|
+
|
|
|
snbAmountLabel: {
|
|
snbAmountLabel: {
|
|
|
- default: null,
|
|
|
|
|
|
|
+ default: [],
|
|
|
type: [cc.Label]
|
|
type: [cc.Label]
|
|
|
},
|
|
},
|
|
|
|
|
+ //拿到仓库列表的节点
|
|
|
|
|
+ buildingView: {
|
|
|
|
|
+ default: null,
|
|
|
|
|
+ type: cc.Node,
|
|
|
|
|
+ },
|
|
|
|
|
+ myWareHouseSeedList: null,
|
|
|
|
|
+ //轮询种子列表状态
|
|
|
|
|
+ AutoGetSeedsData: null,
|
|
|
|
|
+
|
|
|
|
|
+ bottomLabel: {
|
|
|
|
|
+ default: null,
|
|
|
|
|
+ type: cc.Node,
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
HiddenAll() {
|
|
HiddenAll() {
|
|
|
if (this.Seed.active)
|
|
if (this.Seed.active)
|
|
@@ -72,26 +85,31 @@ cc.Class({
|
|
|
this.Exchange.active = false;
|
|
this.Exchange.active = false;
|
|
|
},
|
|
},
|
|
|
start() {
|
|
start() {
|
|
|
|
|
+ //获取到仓库列表的脚本
|
|
|
|
|
+ this.buildingViewScript = this.buildingView.getComponent("BuildingView");
|
|
|
//默认设置第一个节点为 最上面
|
|
//默认设置第一个节点为 最上面
|
|
|
this.SeedBtn.setSiblingIndex(10);
|
|
this.SeedBtn.setSiblingIndex(10);
|
|
|
- console.log('SNB=======',GlobalD.GameData.SNB)
|
|
|
|
|
|
|
+ console.log('SNB=======', GlobalD.GameData.SNB)
|
|
|
this.snbAmountLabel.string = GlobalD.GameData.SNB;
|
|
this.snbAmountLabel.string = GlobalD.GameData.SNB;
|
|
|
-
|
|
|
|
|
|
|
+ //这里也初始化获取一个数据
|
|
|
|
|
+ GlobalD.GameData.getWarehouseSeedAndFruit((res, vaule) => {
|
|
|
|
|
+ this.myWareHouseSeedList = vaule.data.seed;
|
|
|
|
|
+ });
|
|
|
//获取种子和果实
|
|
//获取种子和果实
|
|
|
GlobalD.GameData.getMallSeed((res, vaule) => {
|
|
GlobalD.GameData.getMallSeed((res, vaule) => {
|
|
|
- console.log('vaule111111111=',vaule)
|
|
|
|
|
|
|
+ console.log('vaule111111111=', vaule)
|
|
|
this.mySeedList = vaule.data;
|
|
this.mySeedList = vaule.data;
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
for (let i = 0; i < this.mySeedList.length; i++) {
|
|
for (let i = 0; i < this.mySeedList.length; i++) {
|
|
|
//没有种子数量不显示 todo 看看后续需不需要处理删除
|
|
//没有种子数量不显示 todo 看看后续需不需要处理删除
|
|
|
if (this.mySeedList[i].amount < 1) continue;
|
|
if (this.mySeedList[i].amount < 1) continue;
|
|
|
|
|
|
|
|
let _seed = cc.instantiate(this.seedPrefab);
|
|
let _seed = cc.instantiate(this.seedPrefab);
|
|
|
|
|
|
|
|
- // _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;
|
|
|
|
|
|
|
+ // _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);
|
|
this.seedNodeArry.push(_seed);
|
|
|
_seed.parent = this.Seed;
|
|
_seed.parent = this.Seed;
|
|
@@ -150,25 +168,25 @@ cc.Class({
|
|
|
|
|
|
|
|
this.HiddenAll();
|
|
this.HiddenAll();
|
|
|
//面板设置index
|
|
//面板设置index
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
//种子
|
|
//种子
|
|
|
if ('0' == index) {
|
|
if ('0' == index) {
|
|
|
this.SeedBtn.y = -20;
|
|
this.SeedBtn.y = -20;
|
|
|
this.SeedBtn.getComponent(cc.Sprite).spriteFrame = this.Selecteded_Seed_Sprite;
|
|
this.SeedBtn.getComponent(cc.Sprite).spriteFrame = this.Selecteded_Seed_Sprite;
|
|
|
this.Seed.active = true;
|
|
this.Seed.active = true;
|
|
|
|
|
|
|
|
- if(this.seedNodeArry.length!=0)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ if (this.seedNodeArry.length != 0) {
|
|
|
this.SelectedFrame.parent = this.seedNodeArry[0];
|
|
this.SelectedFrame.parent = this.seedNodeArry[0];
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
//if (this.mySeedList.length > 0) {
|
|
//if (this.mySeedList.length > 0) {
|
|
|
// let Synopsis = "成熟期:" + this.mySeedList[0].maturity;
|
|
// let Synopsis = "成熟期:" + this.mySeedList[0].maturity;
|
|
|
// this.ManageUI.getComponent('ManageUI').onSetButtonInfo(this.mySeedList[0].name, this.mySeedList[0].priceSnb, Synopsis);
|
|
// this.ManageUI.getComponent('ManageUI').onSetButtonInfo(this.mySeedList[0].name, this.mySeedList[0].priceSnb, Synopsis);
|
|
|
//}
|
|
//}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
this.SeedBtn.setSiblingIndex(10);
|
|
this.SeedBtn.setSiblingIndex(10);
|
|
|
this.SeedBtn.setContentSize(86, 88);
|
|
this.SeedBtn.setContentSize(86, 88);
|
|
|
|
|
+ this.bottomLabel.active = false;
|
|
|
}
|
|
}
|
|
|
//兑换
|
|
//兑换
|
|
|
else if ('1' == index) {
|
|
else if ('1' == index) {
|
|
@@ -178,6 +196,8 @@ cc.Class({
|
|
|
|
|
|
|
|
this.ExchangeBtn.setSiblingIndex(10);
|
|
this.ExchangeBtn.setSiblingIndex(10);
|
|
|
this.ExchangeBtn.setContentSize(86, 88);
|
|
this.ExchangeBtn.setContentSize(86, 88);
|
|
|
|
|
+
|
|
|
|
|
+ this.bottomLabel.active = true;
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
switch: function () {
|
|
switch: function () {
|
|
@@ -190,66 +210,110 @@ cc.Class({
|
|
|
node.setSiblingIndex(dst);
|
|
node.setSiblingIndex(dst);
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
- SNBExchangeToCNT()
|
|
|
|
|
- {
|
|
|
|
|
- GlobalD.GameData.onSnbToCnt(this.snbAmount, (res, vaule) => {
|
|
|
|
|
- this.ExchangePopView.active = false;
|
|
|
|
|
- console.log('vaulet=',vaule)
|
|
|
|
|
- console.log('res=',res)
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ SNBExchangeToCNT() {
|
|
|
|
|
+ GlobalD.GameData.onSnbToCnt(this.snbAmount, (data) => {
|
|
|
|
|
+ this.ExchangePopView.active = false;
|
|
|
|
|
+ console.log('data=', data)
|
|
|
|
|
+ // console.log('res=', res)
|
|
|
|
|
+ });
|
|
|
},
|
|
},
|
|
|
- onPayCNTPopView(myIndex)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ onPayCNTPopView(myIndex) {
|
|
|
this.buySeedIndex = myIndex;
|
|
this.buySeedIndex = myIndex;
|
|
|
this.PayCNTPopView.active = true;
|
|
this.PayCNTPopView.active = true;
|
|
|
- // console.log('this.mySeedList[this.buySeedIndex] =',this.mySeedList[this.buySeedIndex])
|
|
|
|
|
|
|
+ // console.log('this.mySeedList[this.buySeedIndex] =',this.mySeedList[this.buySeedIndex])
|
|
|
this.PayCNTPopView.getChildByName("BG").getChildByName("BG1_sprite_splash").getChildByName("NameLabel").getChildByName("label").getComponent(cc.Label).string = this.mySeedList[this.buySeedIndex].name;
|
|
this.PayCNTPopView.getChildByName("BG").getChildByName("BG1_sprite_splash").getChildByName("NameLabel").getChildByName("label").getComponent(cc.Label).string = this.mySeedList[this.buySeedIndex].name;
|
|
|
this.PayCNTPopView.getChildByName("BG").getChildByName("BG1_sprite_splash").getChildByName("PriceLabel").getChildByName("label").getComponent(cc.Label).string = this.mySeedList[this.buySeedIndex].priceCnt + ' CNT';
|
|
this.PayCNTPopView.getChildByName("BG").getChildByName("BG1_sprite_splash").getChildByName("PriceLabel").getChildByName("label").getComponent(cc.Label).string = this.mySeedList[this.buySeedIndex].priceCnt + ' CNT';
|
|
|
this.PayCNTPopView.getChildByName("BG").getChildByName("BG1_sprite_splash").getChildByName("MutureDurLabel").getChildByName("label").getComponent(cc.Label).string = this.mySeedList[this.buySeedIndex].maturity;
|
|
this.PayCNTPopView.getChildByName("BG").getChildByName("BG1_sprite_splash").getChildByName("MutureDurLabel").getChildByName("label").getComponent(cc.Label).string = this.mySeedList[this.buySeedIndex].maturity;
|
|
|
},
|
|
},
|
|
|
- PayCNT()
|
|
|
|
|
- {
|
|
|
|
|
- console.log('this.cntAmount=',this.cntAmount)
|
|
|
|
|
- console.log('this.cntAmount price=', this.cntAmount*parseInt(this.mySeedList[this.buySeedIndex].priceCnt))
|
|
|
|
|
-
|
|
|
|
|
- GlobalD.GameData.payCNT(this.cntAmount*parseInt(this.mySeedList[this.buySeedIndex].priceCnt), 4, this.mySeedList[this.buySeedIndex].id, (res, vaule) => {
|
|
|
|
|
- console.log('PayCNT1 res= ',res);
|
|
|
|
|
- console.log('PayCNT2 vaule= ',vaule);
|
|
|
|
|
-
|
|
|
|
|
- this.PayCNTPopView.active = false;
|
|
|
|
|
|
|
+ PayCNT() {
|
|
|
|
|
+ console.log('this.cntAmount=', this.cntAmount)
|
|
|
|
|
+ console.log('this.cntAmount price=', this.cntAmount * 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 //把当前背包的数据传进去
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ GlobalD.GameData.payCNT(this.cntAmount * parseInt(this.mySeedList[this.buySeedIndex].priceCnt), 4, this.mySeedList[this.buySeedIndex].id + "", (data) => {
|
|
|
|
|
+ const [err, tx] = data;
|
|
|
|
|
+ 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 //把当前背包的数据传进去
|
|
|
|
|
+ },
|
|
|
|
|
+ (res, value) => {
|
|
|
|
|
+ console.log("轮询种子:" + JSON.stringify(value));
|
|
|
|
|
+ if (0 === value.code) {
|
|
|
|
|
+ this.unschedule(this.AutoGetSeedsData);
|
|
|
|
|
+ console.log("轮询种子购买成功");
|
|
|
|
|
+ GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "种子购买成功!", 5);
|
|
|
|
|
+
|
|
|
|
|
+ this.PayCNTPopView.active = false;
|
|
|
|
|
+
|
|
|
|
|
+ //直接重新初始化一下列表,
|
|
|
|
|
+ this.buildingViewScript.onUpdateList();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ };
|
|
|
|
|
+ this.schedule(this.AutoGetSeedsData, 5);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.log(err)
|
|
|
|
|
+ GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), err, 5);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
});
|
|
});
|
|
|
},
|
|
},
|
|
|
- //onEditDidBegan: function(editbox, customEventData) {
|
|
|
|
|
- // // 这里 editbox 是一个 cc.EditBox 对象
|
|
|
|
|
- // // 这里的 customEventData 参数就等于你之前设置的 "foobar"
|
|
|
|
|
- //},
|
|
|
|
|
- //// 假设这个回调是给 editingDidEnded 事件的
|
|
|
|
|
- //onEditDidEnded: function(editbox, customEventData) {
|
|
|
|
|
- // // 这里 editbox 是一个 cc.EditBox 对象
|
|
|
|
|
- // // 这里的 customEventData 参数就等于你之前设置的 "foobar"
|
|
|
|
|
- //},
|
|
|
|
|
- //// 假设这个回调是给 textChanged 事件的
|
|
|
|
|
- //onTextChanged: function(text, editbox, customEventData) {
|
|
|
|
|
- // // 这里的 text 表示 修改完后的 EditBox 的文本内容
|
|
|
|
|
- // // 这里 editbox 是一个 cc.EditBox 对象
|
|
|
|
|
- // // 这里的 customEventData 参数就等于你之前设置的 "foobar"
|
|
|
|
|
- // this.snbAmount = parseInt(text);
|
|
|
|
|
- //},
|
|
|
|
|
- //// 假设这个回调是给 editingReturn 事件的
|
|
|
|
|
- //onEditingReturn: function(editbox, customEventData) {
|
|
|
|
|
- // // 这里 editbox 是一个 cc.EditBox 对象
|
|
|
|
|
- // // 这里的 customEventData 参数就等于你之前设置的 "foobar"
|
|
|
|
|
- //}
|
|
|
|
|
|
|
+ //onEditDidBegan: function(editbox, customEventData) {
|
|
|
|
|
+ // // 这里 editbox 是一个 cc.EditBox 对象
|
|
|
|
|
+ // // 这里的 customEventData 参数就等于你之前设置的 "foobar"
|
|
|
|
|
+ //},
|
|
|
|
|
+ //// 假设这个回调是给 editingDidEnded 事件的
|
|
|
|
|
+ //onEditDidEnded: function(editbox, customEventData) {
|
|
|
|
|
+ // // 这里 editbox 是一个 cc.EditBox 对象
|
|
|
|
|
+ // // 这里的 customEventData 参数就等于你之前设置的 "foobar"
|
|
|
|
|
+ //},
|
|
|
|
|
+ //// 假设这个回调是给 textChanged 事件的
|
|
|
|
|
+ //onTextChanged: function(text, editbox, customEventData) {
|
|
|
|
|
+ // // 这里的 text 表示 修改完后的 EditBox 的文本内容
|
|
|
|
|
+ // // 这里 editbox 是一个 cc.EditBox 对象
|
|
|
|
|
+ // // 这里的 customEventData 参数就等于你之前设置的 "foobar"
|
|
|
|
|
+ // this.snbAmount = parseInt(text);
|
|
|
|
|
+ //},
|
|
|
|
|
+ //// 假设这个回调是给 editingReturn 事件的
|
|
|
|
|
+ //onEditingReturn: function(editbox, customEventData) {
|
|
|
|
|
+ // // 这里 editbox 是一个 cc.EditBox 对象
|
|
|
|
|
+ // // 这里的 customEventData 参数就等于你之前设置的 "foobar"
|
|
|
|
|
+ //}
|
|
|
// 假设这个回调是给 textChanged 事件的
|
|
// 假设这个回调是给 textChanged 事件的
|
|
|
- onTextChanged1: function(text, editbox, customEventData) {
|
|
|
|
|
|
|
+ onTextChanged1: function (text, editbox, customEventData) {
|
|
|
// 这里的 text 表示 修改完后的 EditBox 的文本内容
|
|
// 这里的 text 表示 修改完后的 EditBox 的文本内容
|
|
|
// 这里 editbox 是一个 cc.EditBox 对象
|
|
// 这里 editbox 是一个 cc.EditBox 对象
|
|
|
// 这里的 customEventData 参数就等于你之前设置的 "foobar"
|
|
// 这里的 customEventData 参数就等于你之前设置的 "foobar"
|
|
|
this.cntAmount = parseInt(text);
|
|
this.cntAmount = parseInt(text);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
},
|
|
},
|
|
|
// 假设这个回调是给 textChanged 事件的
|
|
// 假设这个回调是给 textChanged 事件的
|
|
|
- onTextChanged2: function(text, editbox, customEventData) {
|
|
|
|
|
|
|
+ onTextChanged2: function (text, editbox, customEventData) {
|
|
|
// 这里的 text 表示 修改完后的 EditBox 的文本内容
|
|
// 这里的 text 表示 修改完后的 EditBox 的文本内容
|
|
|
// 这里 editbox 是一个 cc.EditBox 对象
|
|
// 这里 editbox 是一个 cc.EditBox 对象
|
|
|
// 这里的 customEventData 参数就等于你之前设置的 "foobar"
|
|
// 这里的 customEventData 参数就等于你之前设置的 "foobar"
|