322 lines
8.0 KiB
JavaScript
322 lines
8.0 KiB
JavaScript
|
|
/******************************************************************
|
||
|
|
*
|
||
|
|
* 背包
|
||
|
|
*
|
||
|
|
******************************************************************/
|
||
|
|
|
||
|
|
const BridgeWindow = require( "bridge.window" );
|
||
|
|
const FxTogs = require( "nx.fx.togs" );
|
||
|
|
const FxSVC = require( "nx.fx.sv.expand" );
|
||
|
|
const ItemDesc = require( "cmp.item.detail" );
|
||
|
|
const BackPackConst = require( "backpack_const" );
|
||
|
|
const BackPackController = require( "backpack_controller" );
|
||
|
|
|
||
|
|
const BBC = BackPackConst.Bag_Code;
|
||
|
|
const BTT = BackPackConst.item_sub_type;
|
||
|
|
|
||
|
|
// 排序类型
|
||
|
|
const SortType = cc.Enum( {
|
||
|
|
Quality: 0, // 品质
|
||
|
|
Type: 1, // 类型
|
||
|
|
Power: 2, // 战力
|
||
|
|
} );
|
||
|
|
|
||
|
|
// 标签页对应关系
|
||
|
|
const TabPage = [
|
||
|
|
{ key: "EQUIPS", tab: BTT.EQUIPS, goto: 1 },
|
||
|
|
{ key: "PROPS", tab: BTT.PROPS, goto: 0 },
|
||
|
|
{ key: "HERO", tab: BTT.HERO, goto: 2 },
|
||
|
|
{ key: "SPECIAL", tab: BTT.SPECIAL, goto: 3 },
|
||
|
|
{ key: "HOLYEQUIPMENT", tab: BTT.HOLYEQUIPMENT, goto: 4 },
|
||
|
|
{ key: "ELFIN", tab: BTT.ELFIN, goto: 5 },
|
||
|
|
];
|
||
|
|
|
||
|
|
// 各类型排序支持
|
||
|
|
const BagTypeSorts = [
|
||
|
|
[ 0 ], // 其他
|
||
|
|
[ 0, 1, 2 ], // 装备
|
||
|
|
[ 0, 1 ], // 道具
|
||
|
|
[ 0 ], // 英雄碎片
|
||
|
|
[ 0 ], // 特殊
|
||
|
|
[ 0, 1 ], // 神装
|
||
|
|
[ 0 ], // 精灵
|
||
|
|
];
|
||
|
|
|
||
|
|
cc.Class( {
|
||
|
|
|
||
|
|
extends: BridgeWindow,
|
||
|
|
|
||
|
|
properties: {
|
||
|
|
|
||
|
|
togMenu: {
|
||
|
|
default: null,
|
||
|
|
type: FxTogs,
|
||
|
|
},
|
||
|
|
|
||
|
|
svcList: {
|
||
|
|
default: null,
|
||
|
|
type: FxSVC,
|
||
|
|
},
|
||
|
|
|
||
|
|
itemDesc: {
|
||
|
|
default: null,
|
||
|
|
type: ItemDesc,
|
||
|
|
displayName: "道具详情"
|
||
|
|
},
|
||
|
|
|
||
|
|
nodFliter: {
|
||
|
|
default: null,
|
||
|
|
type: cc.Node,
|
||
|
|
},
|
||
|
|
|
||
|
|
nodBagNum: {
|
||
|
|
default: null,
|
||
|
|
type: cc.Node,
|
||
|
|
}
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
onLoad: function() {
|
||
|
|
|
||
|
|
// 事件监听
|
||
|
|
this.bindGEvent( EventId.ADD_GOODS, this.onUpdateGoods.bind( this ) );
|
||
|
|
this.bindGEvent( EventId.DELETE_GOODS, this.onUpdateGoods.bind( this ) );
|
||
|
|
this.bindGEvent( EventId.MODIFY_GOODS_NUM, this.onUpdateGoods.bind( this ) );
|
||
|
|
|
||
|
|
// 排序关闭
|
||
|
|
nx.gui.setActive( this.nodFliter, "popup", false );
|
||
|
|
|
||
|
|
// Tog监听
|
||
|
|
this.togMenu.posTog = this.onTogMenu.bind( this );
|
||
|
|
|
||
|
|
nx.gui.setActive( this.nodBagNum, "" );
|
||
|
|
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 重载:参数打开
|
||
|
|
onOpenConfigs: function( _params ) {
|
||
|
|
if( _params.fromOther ){
|
||
|
|
let from = _params.fromOther;
|
||
|
|
let tab = from;
|
||
|
|
let goto = 0;
|
||
|
|
let tabs = 0;
|
||
|
|
TabPage.forEach( _tab => {
|
||
|
|
if( tab == _tab.tab ){
|
||
|
|
goto = _tab.goto;
|
||
|
|
tabs = _tab.tab;
|
||
|
|
}
|
||
|
|
} )
|
||
|
|
this.togMenu.togTo( goto );
|
||
|
|
this.activeMenu( tabs );
|
||
|
|
}else{
|
||
|
|
this.togMenu.togTo( 0 );
|
||
|
|
this.scheduleOnce( () => {
|
||
|
|
this.activeMenu( BTT.PROPS );
|
||
|
|
}, 0.01 );
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
onDestroy: function() {
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 重载:关闭前
|
||
|
|
onPreClosed: function() {
|
||
|
|
|
||
|
|
this.svcList.rebuild( [] );
|
||
|
|
},
|
||
|
|
|
||
|
|
// 更新
|
||
|
|
onUpdateGoods: function( _bagCode, _itemList ) {
|
||
|
|
|
||
|
|
|
||
|
|
// 不处理: 参数无效
|
||
|
|
if( _bagCode != BBC.BACKPACK && _bagCode != BBC.EQUIPS ) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 不处理: 列表为空
|
||
|
|
if( nx.dt.objEmpty( _itemList ) ) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 不处理: 非装备类型显示
|
||
|
|
if( ( this.curType == BTT.EQUIPS || this.curType == BTT.HOLYEQUIPMENT ) && _bagCode != BBC.EQUIPS ) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 不处理: 非装备类型显示
|
||
|
|
if( this.curType != BTT.EQUIPS && this.curType != BTT.HOLYEQUIPMENT && _bagCode == BBC.EQUIPS ) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
// 当前页有改变
|
||
|
|
let upd = false;
|
||
|
|
for( let k in _itemList ) {
|
||
|
|
let tm = _itemList[ k ];
|
||
|
|
if( tm && tm.sub_type == this.curType ) {
|
||
|
|
upd = true;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 强刷
|
||
|
|
if( upd ) {
|
||
|
|
this.freshItemList();
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 背包更新
|
||
|
|
freshItemList: function() {
|
||
|
|
|
||
|
|
let model = BackPackController.getInstance().getModel();
|
||
|
|
let list = model.getAllBackPackArray( this.curType );
|
||
|
|
|
||
|
|
let focus = !nx.dt.arrEmpty( this.svcList.focusList ) ? this.svcList.focusList[0] : 0;
|
||
|
|
let cnt1 = Object.keys( model.item_list[ 1 ] || {} ).length;
|
||
|
|
let cnt2 = Object.keys( model.item_list[ 3 ] || {} ).length;
|
||
|
|
let dataNum = cnt1 + cnt2;
|
||
|
|
nx.gui.setString( this.nodBagNum, "num", dataNum + "" );
|
||
|
|
if( nx.dt.arrEmpty( list ) ) {
|
||
|
|
this.svcList.rebuild( [] );
|
||
|
|
this.svcList.cleanFocus();
|
||
|
|
this.itemDesc.setData();
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 排序
|
||
|
|
switch( this.curST ) {
|
||
|
|
case SortType.Type: {
|
||
|
|
let compare = Utils.tableUpperSorter( [ "sub_type", "type", "base_id" ] )
|
||
|
|
list.sort( compare );
|
||
|
|
} break;
|
||
|
|
case SortType.Power: {
|
||
|
|
let compare = Utils.tableUpperSorter( [ "all_score", "base_id" ] )
|
||
|
|
list.sort( compare );
|
||
|
|
} break;
|
||
|
|
default: {
|
||
|
|
|
||
|
|
} break;
|
||
|
|
}
|
||
|
|
this.svcList.rebuild( list );
|
||
|
|
let show = list[ 0 ];
|
||
|
|
let showIdx = 0;
|
||
|
|
if( this.curType == BTT.HOLYEQUIPMENT ){
|
||
|
|
showIdx = nx.dt.objEmpty( list[ focus ] ) ? 0 : focus;
|
||
|
|
show = nx.dt.objEmpty( list[ focus ] ) ? list[ 0 ] : list[ focus ]
|
||
|
|
}
|
||
|
|
|
||
|
|
// 设置默认
|
||
|
|
this.scheduleOnce( () => {
|
||
|
|
this.svcList.cleanFocus();
|
||
|
|
this.svcList.addFocus( showIdx );
|
||
|
|
this.itemDesc.setData( show, "bag" );
|
||
|
|
}, 0.1 );
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 激活菜单
|
||
|
|
activeMenu: function( _bagCode ) {
|
||
|
|
|
||
|
|
if( this.curType == _bagCode ) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
this.curType = _bagCode;
|
||
|
|
let scv = nx.gui.getComponent( this.svcList.bindSCV, "", cc.ScrollView );
|
||
|
|
if( scv ) {
|
||
|
|
scv.scrollToTop( 0.001 );
|
||
|
|
}
|
||
|
|
this.changeSort( SortType.Quality, true );
|
||
|
|
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 背包切换
|
||
|
|
onTogMenu: function( _index ) {
|
||
|
|
|
||
|
|
let tab = 0;
|
||
|
|
TabPage.forEach( _tab => {
|
||
|
|
if( ( _index ) == _tab.goto ){
|
||
|
|
tab = _tab.tab;
|
||
|
|
}
|
||
|
|
} )
|
||
|
|
this.activeMenu( tab );
|
||
|
|
},
|
||
|
|
|
||
|
|
// 选中切换
|
||
|
|
onFocusChanged: function( _item ) {
|
||
|
|
|
||
|
|
// 空
|
||
|
|
if( nx.dt.objEmpty( _item ) ||
|
||
|
|
nx.dt.objEmpty( _item.mdata ) ) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 聚焦
|
||
|
|
this.svcList.cleanFocus();
|
||
|
|
this.svcList.addFocus( _item.index );
|
||
|
|
this.itemDesc.setData( _item.mdata, "bag" );
|
||
|
|
|
||
|
|
nx.audio.playSFX( "audios/effects/touchitem" );
|
||
|
|
|
||
|
|
// 介绍
|
||
|
|
if( this.nodInfos ) {
|
||
|
|
this.nodInfos.setItem( _item.mdata );
|
||
|
|
}
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 打开排序列表
|
||
|
|
onOpenSortList: function() {
|
||
|
|
|
||
|
|
// 排序选项
|
||
|
|
let ts = BagTypeSorts[ this.curType ];
|
||
|
|
if( nx.dt.arrEmpty( ts ) || ts.length <= 1 ) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
for( let i = 0; i < 3; ++i ) {
|
||
|
|
let node = nx.gui.find( this.nodFliter, "popup/list/t" + i );
|
||
|
|
node.active = nx.dt.arrMember( ts, i );
|
||
|
|
}
|
||
|
|
|
||
|
|
nx.gui.setActive( this.nodFliter, "popup", true );
|
||
|
|
},
|
||
|
|
|
||
|
|
// 关闭排序列表
|
||
|
|
onCloseSortList: function() {
|
||
|
|
|
||
|
|
nx.gui.setActive( this.nodFliter, "popup", false );
|
||
|
|
},
|
||
|
|
|
||
|
|
// 选择排序方式
|
||
|
|
onSelectSortType: function( _st ) {
|
||
|
|
|
||
|
|
nx.debug( "SORT:" + _st );
|
||
|
|
nx.gui.setActive( this.nodFliter, "popup", false );
|
||
|
|
|
||
|
|
this.changeSort( parseInt( _st ) || SortType.Quality );
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 更改排序方式
|
||
|
|
changeSort: function( _type, _force = false ) {
|
||
|
|
|
||
|
|
if( !_force && this.curST == _type ) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
this.curST = _type;
|
||
|
|
nx.gui.setString( this.nodFliter, "cur/txt", nx.text.getKey( "SortName" + _type ) );
|
||
|
|
|
||
|
|
this.freshItemList();
|
||
|
|
},
|
||
|
|
|
||
|
|
} );
|