|
|
@@ -63,7 +63,10 @@ cc.Class({
|
|
|
ConfigLand: {
|
|
|
default: null,
|
|
|
visible: false
|
|
|
- }
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ toast: null,
|
|
|
|
|
|
},
|
|
|
onLoad() {
|
|
|
@@ -1098,11 +1101,18 @@ cc.Class({
|
|
|
})
|
|
|
},
|
|
|
|
|
|
+ //神农呗购买种子
|
|
|
+ onBuySeedsWithSNB(snbAmount,seedId,callback){
|
|
|
+ utils.post(utils.api.snbBuySeeds, {payAmount:snbAmount,seedId:seedId}, (res, vaule) => {
|
|
|
+ callback(res, vaule);
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
//用cnt购买种子,种子的payType类型是 4
|
|
|
- onBuySeedsWithCNT(cntAmount,seedId,callback){
|
|
|
+ onBuySeedsWithCNT(cntAmount, seedId, callback) {
|
|
|
this.payCNT(cntAmount, 4, seedId, callback);
|
|
|
},
|
|
|
-
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 支付cnt操作
|
|
|
@@ -1111,21 +1121,22 @@ cc.Class({
|
|
|
* @param {*} itemType 操作物品的id
|
|
|
*/
|
|
|
payCNT(cntAmount, payType, itemType, callback) {
|
|
|
+ console.log("购买金额:"+cntAmount+"购买类型PlayType:"+payType+"购买物品的id:"+itemType);
|
|
|
if (!GlobalD.dapp) {
|
|
|
console.warn("GlobalD.dapp未初始化,不能payCNT!");
|
|
|
return;
|
|
|
}
|
|
|
//
|
|
|
if (GlobalD.GameData.GetCNT() < cntAmount) {
|
|
|
- console.log("cnt 不足,GetCNT:", GlobalD.GameData.GetCNT(), "消费的cntAmount", cntAmount);
|
|
|
- gameToast.getInstance().show(cc.find("Canvas/UICamera"), "CNT不足!", 2, () => {
|
|
|
+ console.log("cnt 不足,GetCNT:"+ GlobalD.GameData.GetCNT()+"消费的cntAmount"+cntAmount);
|
|
|
+ GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "CNT不足!", 2, () => {
|
|
|
console.log("finish toast!");
|
|
|
- }, this);
|
|
|
+ });
|
|
|
return;
|
|
|
}
|
|
|
- gameToast.getInstance().show(cc.find("Canvas/UICamera"), "支付处理中...", 10, () => {
|
|
|
+ GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "支付处理中...", 10, () => {
|
|
|
console.log("finish toast!");
|
|
|
- }, this);
|
|
|
+ });
|
|
|
|
|
|
GlobalD.dapp.payCnt(cntAmount, payType, itemType).then((data) => {
|
|
|
const [err, tx] = data;
|
|
|
@@ -1133,12 +1144,20 @@ cc.Class({
|
|
|
// TODO 成功, 支付为链上操作,需要提供回调接口给这边服务端确认交易成功后修改购买订单结果
|
|
|
console.log(tx) // 交易hash,唯一标识符
|
|
|
|
|
|
- gameToast.getInstance().hide(this);
|
|
|
- gameToast.getInstance().show(cc.find("Canvas/UICamera"), "支付成功!", 10, () => {
|
|
|
+ GlobalD.dapp.cntBalance().then((cntBalance) => {
|
|
|
+ //会延迟返回
|
|
|
+ console.log("更新cnt:" + cntBalance) // string, 精度18,需要自行处理省略几位小数
|
|
|
+ GlobalD.GameData.SetCNT(cntBalance);
|
|
|
+ });
|
|
|
+
|
|
|
+ GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "支付成功!", 2, () => {
|
|
|
console.log("finish toast!");
|
|
|
- }, this);
|
|
|
+ });
|
|
|
} else {
|
|
|
console.log(err)
|
|
|
+ GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), err, 2, () => {
|
|
|
+ console.log("finish toast!");
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
if (callback) {
|
|
|
@@ -1160,9 +1179,9 @@ cc.Class({
|
|
|
}
|
|
|
if (GlobalD.GameData.GetSNB() <= 0) {
|
|
|
console.log("神农呗数量GetSNB:", GlobalD.GameData.GetSNB(), "替换snbAmount:", snbAmount);
|
|
|
- gameToast.getInstance().show(cc.find("Canvas/UICamera"), "神农呗数量不足!", 2, () => {
|
|
|
+ GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "神农呗数量不足!", 2, () => {
|
|
|
console.log("finish toast!");
|
|
|
- }, this);
|
|
|
+ });
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -1174,6 +1193,12 @@ cc.Class({
|
|
|
//扣除对应的神农呗,本地修改显示
|
|
|
GlobalD.GameData.SetSNB(GlobalD.GameData.GetSNB() - snbAmount);
|
|
|
|
|
|
+ GlobalD.dapp.cntBalance().then((cntBalance) => {
|
|
|
+ //会延迟返回
|
|
|
+ console.log("更新cnt:" + cntBalance) // string, 精度18,需要自行处理省略几位小数
|
|
|
+ GlobalD.GameData.SetCNT(cntBalance);
|
|
|
+ });
|
|
|
+
|
|
|
} else {
|
|
|
console.log(err)
|
|
|
}
|
|
|
@@ -1184,20 +1209,52 @@ cc.Class({
|
|
|
});
|
|
|
},
|
|
|
//获取 神农呗转 CNT 日志
|
|
|
- onGetSnbToCntInfo(page,limit,callback) {
|
|
|
+ onGetSnbToCntInfo(page, limit, callback) {
|
|
|
if (!GlobalD.dapp) {
|
|
|
console.warn("GlobalD.dapp未初始化,不能onGetSnbToCntInfo!");
|
|
|
return;
|
|
|
}
|
|
|
GlobalD.dapp.swapLog(page, limit).then((data) => {
|
|
|
const { err, res } = data;
|
|
|
- if (err ===null) {
|
|
|
+ if (err === null) {
|
|
|
console.log(res) //
|
|
|
}
|
|
|
if (callback) {
|
|
|
callback(data);
|
|
|
}
|
|
|
});
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ showToast(parent, content, time, callback) {
|
|
|
+ if (this.toast) {
|
|
|
+ this.toast.active = true;
|
|
|
+ let DetailLabel = this.toast.getChildByName('DetailLabel');
|
|
|
+ DetailLabel.getComponent(cc.Label).string = content;
|
|
|
+ this.unschedule(this.scheduleObj);
|
|
|
+ this.scheduleObj = null;
|
|
|
+
|
|
|
+ this.scheduleObj = this.scheduleOnce(() => {
|
|
|
+ if (callback) {
|
|
|
+ callback();
|
|
|
+ }
|
|
|
+ this.toast.active = false;
|
|
|
+ }, time);
|
|
|
+ } else {
|
|
|
+ cc.loader.loadRes("prefab/gameToast", function (err, texture) {
|
|
|
+ this.toast = cc.instantiate(texture);
|
|
|
+ this.toast.parent = parent;
|
|
|
+ let DetailLabel = this.toast.getChildByName('DetailLabel');
|
|
|
+ DetailLabel.getComponent(cc.Label).string = content;
|
|
|
+
|
|
|
+ this.scheduleObj = this.scheduleOnce(() => {
|
|
|
+ if (callback) {
|
|
|
+ callback();
|
|
|
+ }
|
|
|
+ this.toast.active = false;
|
|
|
+ }, time);
|
|
|
+ }.bind(this));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|