251 lines
9.9 KiB
JavaScript
251 lines
9.9 KiB
JavaScript
"use strict";
|
||
cc._RF.push(module, '5e5a2e6ExdNW7oLJU1XbJgd', 'cmp.shop.black.market.wnd');
|
||
// Scripts/mod/shop/cmp.shop.black.market.wnd.js
|
||
|
||
"use strict";
|
||
|
||
var BridgeWindow = require("bridge.window");
|
||
var FxSVC = require("nx.fx.sv.expand");
|
||
var ShopController = require("mall_controller");
|
||
var MallEvent = require("mall_event");
|
||
var MallController = require("mall_controller");
|
||
var ElfinController = require("tips_controller");
|
||
var PathTool = require("pathtool");
|
||
var BackPackController = require("backpack_controller");
|
||
var NxSpine = require("nx.fx.spine");
|
||
cc.Class({
|
||
"extends": BridgeWindow,
|
||
properties: {
|
||
svcshopLst: {
|
||
"default": null,
|
||
type: FxSVC,
|
||
displayName: "商城列表"
|
||
},
|
||
nodEmpty: {
|
||
"default": null,
|
||
type: cc.Node
|
||
},
|
||
nodOp: {
|
||
"default": null,
|
||
type: cc.Node
|
||
},
|
||
spRole: {
|
||
"default": null,
|
||
type: NxSpine
|
||
}
|
||
},
|
||
onLoad: function onLoad() {
|
||
var _this = this;
|
||
this.bindGEvent(MallEvent.Get_Buy_list, this.freshShowLst.bind(this));
|
||
this.bindGEvent(MallEvent.Buy_Success_Event, this.freshShopItem.bind(this));
|
||
this.bindGEvent(MallEvent.Buy_One_Success, this.freshShopItem.bind(this));
|
||
this.spRole.load("resDB/models/H30103/show", function (_e) {
|
||
if (!_e) {
|
||
_this.spRole.action("drama1", true);
|
||
} else {
|
||
_this.spRole.stop();
|
||
}
|
||
});
|
||
// nx.gui.setSpriteFrame( this, "panel/role", "resDB/models/H30099/full_show" );
|
||
},
|
||
|
||
// 重载:参数打开
|
||
onOpenConfigs: function onOpenConfigs(_params) {
|
||
if (!nx.dt.objEmpty(_params)) {
|
||
this.shopLst = _params;
|
||
this.shopType = 4;
|
||
this.freshShop();
|
||
} else {
|
||
this.scheduleOnce(function () {
|
||
var MC = MallController.getInstance();
|
||
MC.sender13403(4);
|
||
}, 0.3);
|
||
}
|
||
|
||
// 通过外部接口调用的参数
|
||
// this.svcshopLst.rebuild( [] );
|
||
// console.log( "商城数据相关" + JSON.stringify( _params ) );
|
||
},
|
||
|
||
// 重载:关闭前
|
||
onPreClosed: function onPreClosed() {
|
||
// this.svcschemeList.rebuild( [] );
|
||
this.svcshopLst.rebuild([]);
|
||
},
|
||
// 物品列表 读取的本地json 钻石
|
||
freshShop: function freshShop(_data) {
|
||
var lst = this.shopLst.item_list;
|
||
nx.gui.setActive(this.nodEmpty, "", nx.dt.arrEmpty(lst));
|
||
this.svcshopLst.rebuild(lst);
|
||
this.opfreshShopItems();
|
||
},
|
||
// 刷新按钮显示 处理刷新按钮所需要的材料 以及免费刷新的次数等信息, 以及赋予相关的方法
|
||
opfreshShopItems: function opfreshShopItems() {
|
||
var _this2 = this;
|
||
var efg = game.configs.exchange_data;
|
||
var rfsg = efg.data_shop_exchage_cost;
|
||
// let cfg = rfsg.soul_reset_cost;
|
||
var ecfg = efg.data_shop_list;
|
||
var EC = ElfinController.getInstance();
|
||
var MC = MallController.getInstance();
|
||
var time = this.shopLst.refresh_time;
|
||
var need = ecfg[this.shopType].cost_list[0][1];
|
||
var icon = ecfg[this.shopType].cost_list[0][0];
|
||
var chance = this.shopLst.free_count > 0 ? this.shopLst.free_count : this.shopLst.count;
|
||
var free_chance = this.shopLst.free_count > 0 ? rfsg.max_free_times.val : rfsg.maximum_number.val;
|
||
var freshCount = this.shopLst.free_count == 0 ? nx.text.getKey("Refresh Count") : nx.text.getKey("Free Refresh Count");
|
||
var need_txt = this.shopLst.free_count > 0 ? nx.text.getKey("Free") : nx.text.format("lab_mall_window_tip4", need);
|
||
var path = "";
|
||
path = PathTool.querySmallIconPath(icon);
|
||
nx.gui.setSpriteFrame(this.nodOp, "fresh/cost/icon", path);
|
||
nx.gui.setActive(this.nodOp, "fresh/cost/icon", !this.shopLst.free_count > 0);
|
||
// nx.gui.setString( this.nodOp, "fresh/cost/txt", need_txt );
|
||
nx.gui.setString(this.nodOp, "fresh/cost/txt", !this.shopLst.free_count > 0 ? need_txt : nx.text.getKey("Refresh") + "(" + chance + "/" + free_chance + ")");
|
||
nx.gui.setActive(this.nodOp, "time", false);
|
||
nx.gui.setString(this.nodOp, "fresh_count/desc", freshCount);
|
||
nx.gui.setString(this.nodOp, "fresh_count/txt", chance + "/" + free_chance);
|
||
|
||
// nx.gui.setString( );
|
||
nx.gui.setActive(this.nodOp, "bg", time > 0);
|
||
if (time > 0) {
|
||
this.setFreeCD(time);
|
||
}
|
||
if (this.shopLst.free_count > 0) {
|
||
this.cb = function () {
|
||
MC.sender13405(_this2.shopType);
|
||
};
|
||
} else {
|
||
var txt = nx.text.format("lab_mall_window_tip4d", [need]);
|
||
this.cb = function () {
|
||
MC.sender13405(_this2.shopType);
|
||
};
|
||
}
|
||
|
||
// 技能商城刷新相关
|
||
// nx.gui.setActive( this.nodOp, "", );
|
||
},
|
||
|
||
// 刷新单个商品信息
|
||
freshShopItem: function freshShopItem(_shopitem) {
|
||
/*****
|
||
*{"code":1,"type":1,"eid":1013,"is_half":0,"ext":[{"key":1,"val":10}],"msg":""}
|
||
[13407]:{"code":1,"msg":"","order":5,"num":1,"type":2}
|
||
*/
|
||
var lst = _shopitem;
|
||
var SC = ShopController.getInstance();
|
||
var model = SC.getModel();
|
||
var data_ol = nx.dt.objClone(this.shopLst.item_list);
|
||
// console.log( "刷新商城信息wwww" + JSON.stringify( data_json ) );
|
||
var nodes = nx.gui.find(this.svcshopLst.bindSCV, "view/content").children;
|
||
// if( )
|
||
// for (let j = 0; j < lst.length; j++) {
|
||
// let item = lst[j];
|
||
for (var i = 0; i < nodes.length; i++) {
|
||
var sitem = nodes[i];
|
||
if (sitem) {
|
||
var cmp = sitem.svItem;
|
||
if (cmp) {
|
||
if (lst) {
|
||
if (cmp.mdata.order == lst.order) {
|
||
var data = nx.dt.objClone(cmp.mdata);
|
||
if (lst.num > 0) {
|
||
data.has_buy = data_ol[i].has_buy + lst.num;
|
||
// console.log( JSON.stringify( datas ) + "刷新属性顶顶顶顶" + JSON.stringify( data ) );
|
||
cmp.rebind(cmp.index, data);
|
||
break;
|
||
}
|
||
// console.log( JSON.stringify( datas ) + "当前的方案处理wwwsss" + JSON.stringify( data ) );
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
// }
|
||
|
||
// {"code":1,"type":1,"eid":1008,"is_half":0,"ext":[{"key":1,"val":1}],"msg":""}
|
||
// console.log();
|
||
},
|
||
|
||
onTouchBuy: function onTouchBuy(_item) {
|
||
var _this3 = this;
|
||
var EC = ElfinController.getInstance();
|
||
var Bag = BackPackController.getInstance().getModel();
|
||
var MC = MallController.getInstance();
|
||
var have = Bag.getItemNumByBid(_item.info.pay_type);
|
||
// console.log( "当前的商品数据" + JSON.stringify( _item.info ) );
|
||
// 购买
|
||
var discount = _item.info.discount;
|
||
var cmpPrice = discount > 0 ? discount : _item.info.price;
|
||
if (have < cmpPrice) {
|
||
nx.tbox(gdata("item_data", "data_unit1", _item.info.pay_type).name + nx.text.getKey("StepUpStepUpTimeNoEnough"));
|
||
return;
|
||
}
|
||
if (_item.info.can_buy > 0) {
|
||
nx.tbox(nx.text.getKey("lab_guildsecretarea_tips_15"));
|
||
return;
|
||
} else {
|
||
if (_item.mdata.has_buy == 0 || _item.mdata.has_buy > 0) {
|
||
// [13407]:{"order":2,"type":2,"buy_type":1,"num":1}
|
||
if (EC) {
|
||
var type = 2;
|
||
EC.openBuyPanel(true, _item.info, this.shopType, function (_data) {
|
||
MC.sender13407(_data.order, _this3.shopType, _data.buy_type, _data.num);
|
||
EC.openBuyPanel(false);
|
||
});
|
||
// this.scheduleOnce( ()=> {
|
||
// ElfinController.getInstance().openElfSelectItemWindow( false );
|
||
// }, 0.1 );
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
|
||
// console.log( "当前的商品数据w" + JSON.stringify( _item.mdata ) );
|
||
},
|
||
|
||
freshShowLst: function freshShowLst(_lst) {
|
||
this.shopType = 4;
|
||
this.shopLst = _lst;
|
||
this.freshShop();
|
||
},
|
||
onTouchFresh: function onTouchFresh() {
|
||
nx.dt.fnInvoke(this.cb);
|
||
},
|
||
// 免费倒计时
|
||
setFreeCD: function setFreeCD(_dtFree) {
|
||
this.unscheduleAllCallbacks();
|
||
if (!nx.dt.numPositive(_dtFree, false)) {
|
||
return;
|
||
}
|
||
nx.gui.setActive(this.nodOp, "time", true);
|
||
var self = this;
|
||
// let rate = game.configs.sprite_data.data_const.hatch_rate.val;
|
||
var tick = function tick() {
|
||
var interval = Utils.getTimeInterval(_dtFree);
|
||
// console.log( "当前的倒计时" + interval );
|
||
if (interval <= 0) {
|
||
self.unscheduleAllCallbacks();
|
||
nx.gui.setString(self.nodOp, "time/txt", "");
|
||
return;
|
||
}
|
||
var time = Utils.changeIntevalToDate(interval);
|
||
var txt = time.H + ":" + time.M + ":" + time.S;
|
||
nx.gui.setString(self.nodOp, "time/txt", txt);
|
||
};
|
||
this.schedule(tick, 1, cc.macro.REPEAT_FOREVER);
|
||
tick();
|
||
}
|
||
});
|
||
/**********
|
||
*
|
||
* [13403]:{"type":4,"code":1,"msg":"","count":0,"free_count":5,"num":6,"refresh_time":0,
|
||
* "item_list":[{"item_id":10001,"item_num":1000,"order":1,"price":1000,"type":3,"pay_type":3,"has_buy":0,"limit_count":1,"limit_day":0,"limit_week":0,"limit_month":0,"discount_type":5,"discount":500,"main_attr":[],"pay_type2":0,"price2":0,"score":0,"item_desc":""},
|
||
* {"item_id":10001,"item_num":300,"order":2,"price":300,"type":3,"pay_type":3,"has_buy":0,"limit_count":1,"limit_day":0,"limit_week":0,"limit_month":0,"discount_type":7,"discount":210,"main_attr":[],"pay_type2":0,"price2":0,"score":0,"item_desc":""},
|
||
* {"item_id":10001,"item_num":100,"order":3,"price":100,"type":3,"pay_type":3,"has_buy":0,"limit_count":1,"limit_day":0,"limit_week":0,"limit_month":0,"discount_type":0,"discount":0,"main_attr":[],"pay_type2":0,"price2":0,"score":0,"item_desc":""},
|
||
* {"item_id":11403,"item_num":1,"order":4,"price":250,"type":3,"pay_type":3,"has_buy":0,"limit_count":1,"limit_day":0,"limit_week":0,"limit_month":0,"discount_type":6,"discount":150,"main_attr":[],"pay_type2":0,"price2":0,"score":0,"item_desc":""},
|
||
* {"item_id":10103,"item_num":1,"order":5,"price":100000,"type":3,"pay_type":1,"has_buy":0,"limit_count":1,"limit_day":0,"limit_week":0,"limit_month":0,"discount_type":1,"discount":10000,"main_attr":[],"pay_type2":0,"price2":0,"score":0,"item_desc":""},
|
||
* {"item_id":10451,"item_num":1,"order":6,"price":200,"type":3,"pay_type":3,"has_buy":0,"limit_count":1,"limit_day":0,"limit_week":0,"limit_month":0,"discount_type":0,"discount":0,"main_attr":[],"pay_type2":0,"price2":0,"score":0,"item_desc":""}]}
|
||
*
|
||
*/
|
||
|
||
cc._RF.pop(); |