189 lines
4.7 KiB
JavaScript
189 lines
4.7 KiB
JavaScript
|
|
/******************************************************************
|
||
|
|
*
|
||
|
|
* 同步中心 卡槽
|
||
|
|
*
|
||
|
|
******************************************************************/
|
||
|
|
|
||
|
|
const SVCItem = require( "nx.fx.sv.expand.item" );
|
||
|
|
const HeroController = require( "hero_controller" );
|
||
|
|
const RootWnd = require( "cmp.sync.center.wnd" );
|
||
|
|
const TimeTool = require( "timetool" );
|
||
|
|
|
||
|
|
cc.Class( {
|
||
|
|
|
||
|
|
extends: SVCItem,
|
||
|
|
|
||
|
|
properties: {
|
||
|
|
cmpRoot: { default: null, type: RootWnd },
|
||
|
|
},
|
||
|
|
|
||
|
|
// 数据重置
|
||
|
|
rebind: function( _idx, _data, _key ) {
|
||
|
|
|
||
|
|
this._super( _idx, _data, _key );
|
||
|
|
|
||
|
|
// 刷新
|
||
|
|
this.setData( _data );
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 显示
|
||
|
|
onEnable: function() {
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 关闭
|
||
|
|
onDisable: function() {
|
||
|
|
|
||
|
|
this.unscheduleAllCallbacks();
|
||
|
|
},
|
||
|
|
|
||
|
|
// 置空
|
||
|
|
setEmpty: function() {
|
||
|
|
|
||
|
|
this.unscheduleAllCallbacks();
|
||
|
|
nx.gui.setActive( this, "partner", false );
|
||
|
|
nx.gui.setActive( this, "add", false );
|
||
|
|
nx.gui.setActive( this, "cd", false );
|
||
|
|
nx.gui.setActive( this, "lock", false );
|
||
|
|
nx.gui.setActive( this, "locked", true );
|
||
|
|
},
|
||
|
|
|
||
|
|
// 重置
|
||
|
|
setData: function( _data ) {
|
||
|
|
|
||
|
|
// 无效锁定
|
||
|
|
if( nx.dt.objEmpty( _data ) ) {
|
||
|
|
this.setEmpty();
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 有伙伴
|
||
|
|
if( nx.dt.numPositive( _data.id, false ) ) {
|
||
|
|
this.setPartner( _data.id );
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 倒计时
|
||
|
|
this.unscheduleAllCallbacks();
|
||
|
|
if( nx.dt.numPositive( _data.cool_time, false ) ) {
|
||
|
|
this.setCD( _data.cool_time );
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 可添加
|
||
|
|
if( nx.dt.numPositive( _data.pos, false ) ) {
|
||
|
|
nx.gui.setActive( this, "partner", false );
|
||
|
|
nx.gui.setActive( this, "add", true );
|
||
|
|
nx.gui.setActive( this, "cd", false );
|
||
|
|
nx.gui.setActive( this, "lock", false );
|
||
|
|
nx.gui.setActive( this, "locked", false );
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 置空
|
||
|
|
nx.gui.setActive( this, "partner", false );
|
||
|
|
nx.gui.setActive( this, "add", false );
|
||
|
|
nx.gui.setActive( this, "cd", false );
|
||
|
|
nx.gui.setActive( this, "lock", _data.canUnlock );
|
||
|
|
nx.gui.setActive( this, "locked", !_data.canUnlock );
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 设置伙伴
|
||
|
|
setPartner: function( _pid ) {
|
||
|
|
|
||
|
|
nx.gui.setActive( this, "add", false );
|
||
|
|
nx.gui.setActive( this, "cd", false );
|
||
|
|
nx.gui.setActive( this, "lock", false );
|
||
|
|
nx.gui.setActive( this, "locked", false );
|
||
|
|
nx.gui.setActive( this, "partner", true );
|
||
|
|
|
||
|
|
const HC = HeroController.getInstance();
|
||
|
|
let role = HC.getModel().getHeroById( _pid );
|
||
|
|
let item = nx.gui.getComponent( this, "partner", "cmp.partner.inbag" );
|
||
|
|
if( !item || !role ) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 基本信息
|
||
|
|
item.setData( role );
|
||
|
|
},
|
||
|
|
|
||
|
|
// 设置倒计时
|
||
|
|
setCD: function( _time ) {
|
||
|
|
|
||
|
|
nx.gui.setActive( this, "partner", false );
|
||
|
|
nx.gui.setActive( this, "add", false );
|
||
|
|
nx.gui.setActive( this, "lock", false );
|
||
|
|
nx.gui.setActive( this, "locked", false );
|
||
|
|
nx.gui.setActive( this, "cd", false );
|
||
|
|
|
||
|
|
if( !nx.dt.numPositive( _time, false ) ) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
nx.gui.setActive( this, "cd", true );
|
||
|
|
|
||
|
|
let self = this;
|
||
|
|
let tick = function() {
|
||
|
|
|
||
|
|
let time = self.mdata.cool_time - client.socket.getTime();
|
||
|
|
if( time > 0 ) {
|
||
|
|
let txt = TimeTool.getTimeFormat( time );
|
||
|
|
nx.gui.setString( self, "cd/txt", txt );
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
self.setData( {
|
||
|
|
pos: self.mdata.pos,
|
||
|
|
id: 0,
|
||
|
|
cool_time: 0,
|
||
|
|
canUnlock: self.mdata.canUnlock,
|
||
|
|
} );
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
this.unscheduleAllCallbacks();
|
||
|
|
this.schedule( tick, 1, cc.macro.REPEAT_FOREVER );
|
||
|
|
tick();
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 点击下阵
|
||
|
|
onTouchFree: function() {
|
||
|
|
|
||
|
|
if( this.cmpRoot &&
|
||
|
|
nx.dt.objNEmpty( this.mdata ) ) {
|
||
|
|
this.cmpRoot.onFreePartner( this.mdata );
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
// 点击添加
|
||
|
|
onTouchJoin: function() {
|
||
|
|
|
||
|
|
if( this.cmpRoot &&
|
||
|
|
nx.dt.objNEmpty( this.mdata ) ) {
|
||
|
|
this.cmpRoot.onJoinPartner( this.mdata.pos );
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
// 点击冷却
|
||
|
|
onTouchCD: function() {
|
||
|
|
|
||
|
|
if( this.cmpRoot &&
|
||
|
|
nx.dt.objNEmpty( this.mdata ) ) {
|
||
|
|
this.cmpRoot.onTouchCD( this.mdata.pos );
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
// 点击解锁
|
||
|
|
onTouchUnlock: function() {
|
||
|
|
|
||
|
|
if( this.cmpRoot &&
|
||
|
|
nx.dt.objNEmpty( this.mdata ) ) {
|
||
|
|
this.cmpRoot.onTouchExpand( this.mdata );
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
} );
|