/****************************************************************** * * 派遣界面 * ******************************************************************/ const BridgeWindow = require( "bridge.window" ); const FxSVC = require( "nx.fx.sv.expand" ); const RoleController = require( "role_controller" ); const HeroController = require( "hero_controller" ); const TipsController = require( "tips_controller" ); const DispatchConst = require( "dispatch.const" ); const DispatchMod = require( "dispatch.mod" ); // 订单状态 const DSOS = DispatchConst.Order_Status; cc.Class( { extends: BridgeWindow, properties: { nodCoin: { default: null, type: cc.Node }, nodOps: { default: null, type: cc.Node }, svcList: { default: null, type: FxSVC }, }, // 显示 onEnable: function() { let DC = DispatchMod.getInstance(); DC.reqData(); // 事件监听 this.bindGEvent( DispatchConst.FreshData, this.onFreshTaskList.bind( this ) ); this.bindGEvent( DispatchConst.DeleteOrder, this.onFreshTaskList.bind( this ) ); // 基础更新 this.freshBase(); // 数据更新 this.onFreshTaskList(); }, // 关闭 onDisable: function() { // 事件监听释放 this.unbindGEvents(); }, // 置空 setEmpty: function() { // 文本置空 nx.gui.setString( this.nodLevel, "txt", "Lv.--" ); nx.gui.setString( this.nodVolume, "txt", "0/0" ); // 伙伴置空 this.svcList.rebuild( [] ); // 目标置空 this.nodTars.children.forEach( _tar => { nx.gui.setActive( _tar, "normal", false ); nx.gui.setActive( _tar, "empty", true ); } ); this.data = null; this.tarTag = ""; }, // 基础更新 freshBase: function() { // 最大体力值更新 this.role = RoleController.getInstance().getRoleVo(); nx.gui.setString( this.nodCoin, "value/max", this.role.energy_max ); }, // 全刷新 onFreshTaskList: function() { let DM = DispatchMod.getInstance().getModel(); this.orders = DM.getAllOrderList(); // 排序规则 已完成>可接取>进行中 const SORT_TAGS = { [ DSOS.Finish ]: 1, [ DSOS.Unget ]: 2, [ DSOS.Underway ]: 3, } // 排序方法 const sortFunc = function( objA, objB ) { let sort_index_a = SORT_TAGS[ objA.status ]; let sort_index_b = SORT_TAGS[ objB.status ]; //引导需要订单号为1的放在最前面 if( objA.order_id == 1 && objA.status == DSOS.Unget && objB.order_id != 1 ) { return -1; } if( objA.order_id != 1 && objB.order_id == 1 && objB.status == DSOS.Unget ) { return 1; } //未接取的按照品质排序,已接取和已完成的按照完成时间排序 if( sort_index_a == sort_index_b ) { if( objA.status == DSOS.Unget ) { return objB.config.quality - objA.config.quality; } else { return objA.end_time - objB.end_time; } } else { return sort_index_a - sort_index_b; } } this.orders.sort( sortFunc ); nx.gui.setActive( this.svcList, "empty", nx.dt.arrEmpty( this.orders ) ); this.svcList.rebuild( this.orders ); // 引导辅助 if( nx.bridge.plot && nx.bridge.plot.isDoing() ) { this.scheduleOnce( () => { this.positionFirstOrder(); }, 0.1 ); } // 操作更新 this.freshOps(); }, // 操作更新 freshOps: function() { nx.gui.hideAllChildren( this.nodOps, "" ); let DATA = game.configs.shipping_data.data_refresh[ this.role.vip_lev ]; if( !DATA ) { return; } // 一键领取 nx.gui.setActive( this.nodOps, "once", true ); // 免费刷新 let model = DispatchMod.getInstance().getModel(); let times = model.getFreeTimes(); let total = DATA.free_times; if( times < total ) { nx.gui.setActive( this.nodOps, "free", true ); nx.gui.setString( this.nodOps, "free/times", nx.text.format( "RangeTimes", times, total ) ); return; } // 钻石刷新(次数不封顶) nx.gui.setActive( this.nodOps, "fresh", true ); let expend = DATA.expend[ 0 ]; let info = gitemdata( expend[ 0 ] ); nx.bridge.setIconS( this.nodOps, "fresh/cost/icon", info.icon ); nx.gui.setString( this.nodOps, "fresh/cost/txt", expend[ 1 ] ); }, // 同步标的单刷 freshTarget: function( _node, _data ) { // 置空 if( nx.dt.objEmpty( _data ) || !nx.dt.numPositive( _data.id, false ) ) { nx.gui.setActive( _node, "normal", false ); nx.gui.setActive( _node, "empty", true ); return; } // 更新 const HC = HeroController.getInstance(); let partner = HC.getModel().getHeroById( _data.id ); if( !partner ) { nx.error( "同步目标无效:", _data.id ); nx.gui.setActive( _node, "normal", false ); nx.gui.setActive( _node, "empty", true ); return; } // 获取配置 let key = partner.bid + "_" + partner.star; let cfgs = gdata( "partner_data", "data_partner_star", key ); if( !cfgs ) { nx.error( "同步目标配置无效:", _data.id, key ); nx.gui.setActive( _node, "normal", false ); nx.gui.setActive( _node, "empty", true ); return; } nx.gui.setActive( _node, "empty", false ); nx.gui.setActive( _node, "normal", true ); // 等级 nx.gui.setString( _node, "normal/level", partner.lev ); // 角色 let path = cc.path.join( "resDB/models", cfgs.res_id, "half_show2" ); nx.gui.setSpriteFrame( _node, "normal/avatar/img", path, ( _ret ) => { if( !_ret ) { nx.gui.setSpriteFrame( _node, "normal/avatar/img", "resDB/empty/half_show2" ); } } ); }, // 点击说明 onTouchHelp: function() { let DATA = game.configs.shipping_data.data_explain; let txt = ""; for( let i in DATA ) { txt += nx.text.getKey( DATA[ i ].desc ); txt += '
'; } const TC = TipsController.getInstance(); TC.showTextPanel( "tip", txt ); }, // 点击刷新 onTouchFresh: function() { let count = 0; this.orders.forEach( _order =>{ if( _order.config.quality >= 3 && _order.status == 1 ){ count++; } } ); let DC = DispatchMod.getInstance(); if( count > 0 ){ nx.mbox( nx.text.getKey( "HomeDispatchTip" ), [ 'cancel', 'confirm' ], ( _key, _box ) => { _box.close(); if( _key == "confirm" ) { // this.reqSummon( _args.type, _times, _args ); DC.requestRefreshOrder(); } } ); }else{ DC.requestRefreshOrder(); } }, // 点击免费刷新 onTouchFreshFree: function() { this.onTouchFresh(); }, // 点击一键领取 onTouchGetOnce: function() { let DC = DispatchMod.getInstance(); DC.requestQuickReceiveOrder( ( _ret, _data ) => { if( !_ret ) { nx.tbox( _data ); return; } } ); }, // ============================================ // 引导辅助 // ============================================ // 定位第一个派遣订单 positionFirstOrder: function() { let children = this.svcList.bindSCV.content.children; let node = children[ 0 ]; if( !node ) { nx.error( "$Dispatch:定位第一个派遣订单失败!" ); node = children[ 0 ]; if( !node ) { return; } } let cell = nx.gui.find( this, "panel/plotCell" ); let btn = nx.gui.find( node.svItem, "ops/dispatch" ); let pos = btn.convertToWorldSpaceAR( cc.Vec2.ZERO ); cell.position = cell.parent.convertToNodeSpaceAR( pos ); cell.width = btn.width; cell.height = btn.height; cell.svItem = node.svItem; }, // 点击第一个订单派遣 onTouchFirstOrder: function() { let cell = nx.gui.find( this, "panel/plotCell" ); if( cell && cell.svItem ) { cell.svItem.onTouchDispatch(); } }, } );