Files
fc/dev/project/assets/Scripts/mod/backpack/backpack_controller.js
T
2026-05-23 22:10:14 +08:00

415 lines
12 KiB
JavaScript

// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
// 背包内出售物品的面板
// <br/>Create: 2018-12-24 16:50:14
// --------------------------------------------------------------------
const BridgeController = require( "bridge.controller" );
const BackPackConst = require( "backpack_const" );
const MainuiController = require( "mainui_controller" );
const MainuiConst = require( "mainui_const" );
const BackpackEvent = require( "backpack_event" );
const TipsController = require( "tips_controller" )
// 桥接替换的界面
const BackpackController = cc.Class( {
extends: BridgeController,
ctor: function() {
},
// 初始化配置数据
initConfig: function() {
var BackpackModel = require( "backpack_model" );
this.model = new BackpackModel();
this.model.initConfig();
},
// 返回当前的model
getModel: function() {
return this.model;
},
// 注册监听事件
registerEvents: function() {
},
// 注册协议接受事件
registerProtocals: function() {
this.RegisterProtocal( 10500, this.on10500 );
this.RegisterProtocal( 10501, this.on10501 );
this.RegisterProtocal( 10510, this.on10510 ); //增加物品通知
this.RegisterProtocal( 10511, this.on10511 ); //删除物品通知
this.RegisterProtocal( 10512, this.on10512 ); //刷新物品通知
this.RegisterProtocal( 10515, this.handle10515 );//使用物品
this.RegisterProtocal( 10522, this.handle10522 );//出售背包物品
this.RegisterProtocal( 10523, this.handle10523 );
this.RegisterProtocal( 11008, this.handle11008 );
this.RegisterProtocal( 11018, this.handle11018.bind( this ) );
},
// 从服务器初始化数据
reqBaseFromServer: function( _cb ) {
// 配置加载
let cfgs = [
"item_data", // 道具
"package_data", // 背包
"color_data", // 色码表
"gift_data", // 礼包
"attr_data", // 属性表
"sprite_data", // 僚机相关数据显示
];
this.loadConfigs( cfgs, ( _ret, _data ) => {
this.sender10500();
this.sender10501( _cb );
} );
},
// 初始化道具背包
sender10500: function( _cb ) {
this.SendProtocal( 10500, {}, _cb );
},
// 初始化装备背包
sender10501: function( _cb ) {
this.SendProtocal( 10501, {}, _cb );
},
// 初始化道具背包
on10500: function( data ) {
data.bag_code = BackPackConst.Bag_Code.BACKPACK
this.model.initItemList( data )
},
// 初始化装备背包
on10501: function( data ) {
data.bag_code = BackPackConst.Bag_Code.EQUIPS
this.model.initItemList( data )
},
// 增加一个物品
on10510: function( data ) {
cc.log( "增加一个物品", data )
this.model.updateBagItemsNum( data )
},
// 删除一个物品
on10511: function( data ) {
cc.log( "删除一个物品", data )
this.model.deleteBagItems( data )
},
// 刷新一个物品
on10512: function( data ) {
this.model.updateBagItemsNum( data, true )
},
// ==============================
// desc:出售物品
// @storage:
// @args:
// @return
// ==============================
sender10522: function( storage, args ) {
var protocal = {};
protocal.storage = storage;
protocal.args = args;
this.SendProtocal( 10522, protocal );
},
handle10522: function( data ) {
nx.tbox( data.msg )
if( this.batch_use ) {
this.openBatchUseItemView( false );
}
if( this.sell_window ) {//出售成功之后关闭出售面板
this.openSellWindow( false );
}
this.closeGiftSelectPanel();
gcore.GlobalEvent.fire( BackpackEvent.Sell_Goods_Success );
},
// ==============================
// desc:使用物品
// @id:
// @quantity:
// @args:
// @return
// ==============================
sender10515: function( id, quantity, args ) {
var protocal = {}
protocal.id = id
protocal.quantity = quantity
protocal.args = args || {};
this.SendProtocal( 10515, protocal )
},
handle10515: function( data ) {
nx.tbox( data.msg );
if( data.flag == 1 ) {
this.openBatchUseItemView( false );
this.closeGiftSelectPanel();
}
},
sender10523: function( id, num ) {
var protocal = {};
protocal.id = id;
protocal.num = num;
this.SendProtocal( 10523, protocal );
},
handle10523: function( data ) {
nx.tbox( data.msg );
if( data.flag == 1 ) {
gcore.GlobalEvent.fire( BackpackEvent.Compose_Goods_Success );
TipsController.getInstance().showBackPackCompTips( false );
}
},
//背包碎片合成
sender11008: function( bid, num ) {
var proto = {};
proto.bid = bid;
proto.num = num;
this.SendProtocal( 11008, proto );
},
handle11008: function( data ) {
gcore.GlobalEvent.fire( BackpackEvent.Compose_BackPack_Success );
nx.tbox( data.msg );
TipsController.getInstance().showBackPackCompTips( false );
TipsController.getInstance().showCompChooseTips( false );
if( data.result == 1 ) {
var items = [];
for( var i in data.partners ) {
var v = data.partners[ i ];
var info = game.configs.partner_data.data_partner_base[ v.partner_bid ];
items[ parseInt( i ) ] = {};
items[ parseInt( i ) ].bid = v.partner_bid;
items[ parseInt( i ) ].star = info.init_star;
items[ parseInt( i ) ].camp_type = info.camp_type;
// items[ parseInt( i ) ].show_type = MainuiConst.item_exhibition_type.partner_type;
}
MainuiController.getInstance().openGetItemView( true, items, 0 )
}
},
/**
* 打开背包主入口
* @param {*} status
* @param {*} params
*/
openMainWindow: function( status, params ) {
if( !status ) {
nx.bridge.closePanel( "WndBag" );
} else {
nx.bridge.createPanel( "WndBag", { fromOther : params } );
}
},
/**
* 显示道具提示信息
* @author zhanghuxing 2019-01-21
* @param {[type]} status [description]
* @param {[type]} data 可以是bid, 或者配置表条目
* @param {[type]} extend_data [description]
* @param {[type]} item_list 需要的物品列表
* @return {[type]} [description]
*/
openTipsSource: function( status, data, extend_data, item_list ) {
if( status ) {
if( typeof ( data ) == "number" ) {
data = Utils.getItemConfig( data )
}
if( data == null ) return;
if( !this.tips_source ) {
// 调用统一的物品弹出窗
this.tips_source = TipsController.getInstance().showItemTips( data );
}
} else {
if( this.tips_source ) {
this.tips_source.close();
this.tips_source = null;
}
}
},
/**
* desc:出售物品
*/
openItemSellPanel: function( status, goods_vo, bag_code ) {
if( status == false ) {
nx.bridge.closePanel( "WndItemSell" );
} else {
nx.bridge.createPanel( "WndItemSell", [ goods_vo, bag_code ] );
}
},
/**
* desc:合成
*/
openItemMergePanel: function( status, goods_vo, bag_code ) {
if( status == false ) {
nx.bridge.closePanel( "WndItemMerge" );
} else {
nx.bridge.createPanel( "WndItemMerge",[ goods_vo, bag_code ] );
}
},
/**
* desc:分解
*/
openItemDecomposePanel: function( status, goods_vo, bag_code ) {
if( status == false ) {
nx.bridge.closePanel( "WndItemDecompose" );
} else {
nx.bridge.createPanel( "WndItemDecompose", [ goods_vo, bag_code ] );
}
},
// --==============================--
// --desc:打开批量使用物品窗口
// --@item:必须是物品真是数据
// --@type:出售或者使用
// --@select_vo :自选礼包点击批量使用要传选中的物品id列表过来
// --@return
// --==============================--
openBatchUseItemView: function( status, item, type, select_vo ) {
if( status == false ) {
nx.bridge.closePanel( "WndItemBatchUse" );
} else {
nx.bridge.createPanel( "WndItemBatchUse", [ item, type, select_vo ] );
}
},
/**
* 打开出售物品界面展示
* author:{author}
* @status:
* @list:
* return
*/
openSellWindow: function( status, bag_code, list ) {
if( status == false ) {
if( this.sell_window != null ) {
this.sell_window.close();
this.sell_window = null;
}
} else {
bag_code = bag_code || BackPackConst.Bag_Code.BACKPACK;
if( list == null || Utils.next( list ) == null ) return;
if( this.sell_window == null ) {
this.sell_window = Utils.createClass( "backpack_sell_window", this );
}
this.sell_window.open( bag_code, list );
}
},
openGiftSelectPanel: function( gift_vo ) {
// 无效礼包
if( nx.dt.objEmpty( gift_vo ) || !nx.dt.numGood( gift_vo.base_id ) ) {
nx.error( "无效礼包,无法打开!" );
return;
}
nx.bridge.createPanel( "WndGiftChoose", gift_vo );
},
openGiftSelectMorePanel: function( gift_vo ) {
// 无效礼包
if( nx.dt.objEmpty( gift_vo ) || !nx.dt.numGood( gift_vo.base_id ) ) {
nx.error( "无效礼包,无法打开!" );
return;
}
nx.bridge.createPanel( "WndGiftMoreChoose", gift_vo );
},
closeGiftSelectPanel: function() {
if( this.gift_panel != null ) {
this.gift_panel.close();
this.gift_panel = null;
}
},
//跳转物品来源的
gotoItemSources: function( evt_type, extend, bid, need_item_list ) {
nx.bridge.jumper.jump2WindowByKey( evt_type, {
bid: bid,
extend: extend,
} );
},
getBackpackRoot: function() {
if( this.backpack_win )
return this.backpack_win.root_wnd;
},
// ================
/**
* 选物品
* @param {*} _open
* @param {*} _args : {
* items: 列表,
* count: 选择上限,
* selects: 已选择,
* fixed: 是否固定选择上限数(默认false)
* flag: 特殊标记 1: 符文合成 }
* @param {*} _cb : 返回
*/
openItemSelector: function( _open, _args, _cb ) {
if( _open ) {
nx.bridge.createPanel( "WndItemSelectPanel", {
params: _args,
cb: _cb,
} )
} else {
nx.bridge.closePanel( "WndItemSelectPanel" );
}
},
// ============================================================
// 皮肤碎片相关
// ============================================================
// 碎片合成
reqSkinCombine: function( _id, _cb ) {
this.SendProtocal( 11018, {
bid: _id,
}, _cb );
},
handle11018: function( _data ) {
if( !this.isGoodData( _data ) ) {
return;
}
},
} );
module.exports = BackpackController;