334 lines
9.8 KiB
JavaScript
334 lines
9.8 KiB
JavaScript
|
|
const SVCItem = require("nx.fx.sv.expand.item");
|
||
|
|
const TipController = require( "tips_controller" );
|
||
|
|
const ElfinController = require( "elfin_controller" );
|
||
|
|
const ItemBase = require( "cmp.item.base" );
|
||
|
|
const BackpackController = require( "backpack_controller" );
|
||
|
|
|
||
|
|
/**********
|
||
|
|
*
|
||
|
|
* 僚机方案 单项
|
||
|
|
*/
|
||
|
|
|
||
|
|
cc.Class({
|
||
|
|
|
||
|
|
extends: SVCItem,
|
||
|
|
|
||
|
|
properties: {
|
||
|
|
|
||
|
|
sname : {
|
||
|
|
default: null,
|
||
|
|
type : cc.Node,
|
||
|
|
displayName : "方案名",
|
||
|
|
},
|
||
|
|
|
||
|
|
sinfo : {
|
||
|
|
default: [],
|
||
|
|
type : cc.Node,
|
||
|
|
displayName : "僚机装配方案组",
|
||
|
|
},
|
||
|
|
|
||
|
|
nodfocus : {
|
||
|
|
default: null,
|
||
|
|
type : cc.Node,
|
||
|
|
displayName : "聚焦",
|
||
|
|
},
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 数据重置
|
||
|
|
rebind: function (_idx, _data, _key) {
|
||
|
|
this._super(_idx, _data, _key);
|
||
|
|
|
||
|
|
this.freshInfo();
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 刷新具体信息
|
||
|
|
freshInfo:function(){
|
||
|
|
|
||
|
|
if(!this.mdata){
|
||
|
|
this.setEmpty();
|
||
|
|
nx.bridge.vset( "ShowWingPos", null );
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
let maxCount = game.configs.sprite_data.data_elfin_plan_length;
|
||
|
|
|
||
|
|
nx.gui.setString( this.sname, "", nx.text.getKey( this.mdata.name ) );
|
||
|
|
let sprites = this.mdata.plan_sprites;
|
||
|
|
|
||
|
|
sprites.sort( Utils.tableLowerSorter( [ "pos" ] ) );
|
||
|
|
|
||
|
|
let chd = this.sinfo;
|
||
|
|
let count = 0;
|
||
|
|
for (let i = 0; i < sprites.length; i++) {
|
||
|
|
let cmp = chd[i].getComponent( ItemBase );
|
||
|
|
if( cmp ){
|
||
|
|
cmp.setLocked( false );
|
||
|
|
cmp.setData( sprites[i].item_bid );
|
||
|
|
if( sprites[i].item_bid != 0 ){
|
||
|
|
count++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
nx.gui.setActive( this, "ico_do", count != 0 );
|
||
|
|
nx.gui.setActive( this, "ico", count == 0 );
|
||
|
|
nx.gui.setActive( this, "item", this.mdata.id <= maxCount );
|
||
|
|
nx.gui.setActive( this, "add", this.mdata.id > maxCount );
|
||
|
|
|
||
|
|
//{"id":9,"name":"新增","plan_sprites":[{"pos":5,"item_bid":0}]}
|
||
|
|
/***{"id":1,"name":"464646",
|
||
|
|
* "plan_sprites":[{"pos":1,"item_bid":113408},{"pos":2,"item_bid":113407},{"pos":3,"item_bid":0},{"pos":4,"item_bid":0}]} */
|
||
|
|
},
|
||
|
|
|
||
|
|
setEmpty: function(){
|
||
|
|
|
||
|
|
let chd = this.sinfo;
|
||
|
|
for (let i = 0; i < chd.length; i++) {
|
||
|
|
let cmp = chd[i].getComponent( ItemBase );
|
||
|
|
if( cmp ){
|
||
|
|
cmp.setLocked( true );
|
||
|
|
this.focus = false;
|
||
|
|
cmp.setData( 0 );
|
||
|
|
}
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
|
||
|
|
onTouchRename : function(){
|
||
|
|
|
||
|
|
let TC = TipController.getInstance();
|
||
|
|
let EC = ElfinController.getInstance();
|
||
|
|
let id = this.index + 1;
|
||
|
|
let modify = function( _name ) {
|
||
|
|
EC.send26558( id, _name );
|
||
|
|
};
|
||
|
|
|
||
|
|
TC.showInputString( { tip: "", limit: [1,12], cb: ( _box, _str ) => {
|
||
|
|
_box.close();
|
||
|
|
modify( _str );
|
||
|
|
} });
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 聚焦获得
|
||
|
|
onFocus: function(){
|
||
|
|
|
||
|
|
this.focus = true;
|
||
|
|
if( this.nodfocus ){
|
||
|
|
nx.gui.setActive( this.nodfocus, "" , true );
|
||
|
|
nx.gui.setActive( this, "item/tip", false );
|
||
|
|
|
||
|
|
}
|
||
|
|
// this.onTouchPos( 0 );
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 聚焦获得
|
||
|
|
outFocus: function(){
|
||
|
|
|
||
|
|
|
||
|
|
// this.onTouchPos( -1 );
|
||
|
|
this.focus = false;
|
||
|
|
if( this.nodfocus ){
|
||
|
|
nx.gui.setActive( this.nodfocus, "" , false );
|
||
|
|
nx.gui.setActive( this, "item/tip", true );
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
onTouchAdd : function(){
|
||
|
|
|
||
|
|
let EC = ElfinController.getInstance();
|
||
|
|
|
||
|
|
let pfg = game.configs.sprite_data.data_elfin_plan[this.index + 1];
|
||
|
|
let have = BackpackController.getInstance().getModel().getItemNumByBid( pfg.expend[0][0] );
|
||
|
|
let need = pfg.expend[0][1];
|
||
|
|
// 不足弹出提示
|
||
|
|
if( have < need ){
|
||
|
|
nx.tbox( nx.text.getKey( "elfin_hatch_unlock_5" ) );
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
let mat0 = pfg.expend[0][0];
|
||
|
|
let txt = nx.text.format( "lab_heaven_msg_tips_19n", need, this.index + 1 );
|
||
|
|
EC.openElfUseTipsWindow( true , txt, [mat0], [ need ], ( _deal =>{
|
||
|
|
EC.send26562( this.index + 1 );
|
||
|
|
EC.openElfUseTipsWindow( false );
|
||
|
|
} ) );
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
onTouchPos: function( _index ){
|
||
|
|
|
||
|
|
return;
|
||
|
|
let nodParent = this.node.parent.parent;
|
||
|
|
// console.log( "节点" + nodParent.name );
|
||
|
|
for (let i = 0; i < nodParent.children.length; i++) {
|
||
|
|
let item = nodParent.children[i];
|
||
|
|
// console.log( "节点s" + Object.keys( item.svItem ) );
|
||
|
|
if( item.svItem ){
|
||
|
|
let chd = item.svItem.sinfo;
|
||
|
|
|
||
|
|
// let smp = item.getComponent( SVCItem );
|
||
|
|
if( chd ){
|
||
|
|
|
||
|
|
for (let j = 0; j < chd.length; j++) {
|
||
|
|
// console.log("取消选择状态");
|
||
|
|
let sch = chd[j];
|
||
|
|
let cmp = sch.getComponent( ItemBase );
|
||
|
|
if( cmp ){
|
||
|
|
cmp.outFocus();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
// console.log( "当前的方案" + this.index + "当前点击" + _index + "状态" + this.focus );
|
||
|
|
for (let i = 0; i < this.sinfo.length; i++) {
|
||
|
|
|
||
|
|
let selectNode = this.sinfo[i];
|
||
|
|
let cmp = selectNode.getComponent( ItemBase );
|
||
|
|
if( cmp ){
|
||
|
|
if( _index == i ){
|
||
|
|
cmp.onFocus();
|
||
|
|
// console.log( "当前的方案" );
|
||
|
|
if( !nx.dt.objGood( cmp.mdata ) ){
|
||
|
|
let data = {};
|
||
|
|
data.index = this.select_wing;
|
||
|
|
data.mdata = nx.dt.objClone( cmp.mdata );
|
||
|
|
nx.bridge.vset( "ShowWingPos", data );
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
nx.bridge.vset( "ShowWingPos", i );
|
||
|
|
|
||
|
|
}else{
|
||
|
|
cmp.outFocus();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
onTouchSave: function( _type,_team ){
|
||
|
|
|
||
|
|
let EC = ElfinController.getInstance();
|
||
|
|
let choice = [];
|
||
|
|
|
||
|
|
|
||
|
|
for (let i = 0; i < this.sinfo.length; i++) {
|
||
|
|
|
||
|
|
let selectNode = this.sinfo[i];
|
||
|
|
let cmp = selectNode.getComponent( ItemBase );
|
||
|
|
if( cmp ){
|
||
|
|
if( !nx.dt.objGood( cmp.mdata ) ){
|
||
|
|
let data = {};
|
||
|
|
data.pos = i + 1;
|
||
|
|
data.item_bid = nx.dt.objClone( cmp.mdata || -1 );
|
||
|
|
choice.push( data );
|
||
|
|
}else{
|
||
|
|
let data = {};
|
||
|
|
|
||
|
|
data.pos = i + 1;
|
||
|
|
data.item_bid = 0;
|
||
|
|
// console.log( "当前的pos2" + JSON.stringify( data ) );
|
||
|
|
choice.push( data );
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
for (let i = 0; i < choice.length; i++) {
|
||
|
|
if ( choice[i].item_bid < 0 ) {
|
||
|
|
choice.splice(i, 1); // 将使后面的元素依次前移,数组长度减1
|
||
|
|
i--; // 如果不减,将漏掉一个元素
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
let id = this.index + 1;
|
||
|
|
EC.send26557( id, choice, _type, _team );
|
||
|
|
},
|
||
|
|
|
||
|
|
//使用预设方案
|
||
|
|
UsePreSet: function(){
|
||
|
|
|
||
|
|
// 获取当前的默认方案配置
|
||
|
|
let ElfinCtl = ElfinController.getInstance();
|
||
|
|
let model = ElfinCtl.getModel();
|
||
|
|
let defaultSchemeInfo = model.getDedefaultElfinInfo();
|
||
|
|
let schemes = model.getAllPlanData() ;
|
||
|
|
let schemesid = [];
|
||
|
|
// let num = 0;
|
||
|
|
for (let i = 0; i < defaultSchemeInfo.length; i++) {
|
||
|
|
let item = defaultSchemeInfo[i];
|
||
|
|
if( item.item_bid >= 0 ){
|
||
|
|
schemesid.push( item.item_bid );
|
||
|
|
}
|
||
|
|
// if( item.item_bid == 0 ){
|
||
|
|
// num++;
|
||
|
|
// }
|
||
|
|
|
||
|
|
}
|
||
|
|
// if( num >= 4 ){
|
||
|
|
// nx.tbox( nx.text.getKey( "tips_assemble_none" ) );
|
||
|
|
// return;
|
||
|
|
// }
|
||
|
|
|
||
|
|
// console.log( JSON.stringify( schemes ) + "当前的默认方案配置" + JSON.stringify( defaultSchemeInfo ) );
|
||
|
|
|
||
|
|
if( schemes[this.index] ){
|
||
|
|
schemes[this.index].plan_sprites = defaultSchemeInfo;
|
||
|
|
|
||
|
|
this.rebind( this.index, schemes[this.index] );
|
||
|
|
|
||
|
|
}
|
||
|
|
let data = {
|
||
|
|
lst : schemesid,
|
||
|
|
index : this.index,
|
||
|
|
}
|
||
|
|
nx.bridge.vset( "ShowWingPos", data );
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
onTouchSaveBtn: function(){
|
||
|
|
|
||
|
|
let EC = ElfinController.getInstance();
|
||
|
|
let choice = [];
|
||
|
|
|
||
|
|
|
||
|
|
for (let i = 0; i < this.sinfo.length; i++) {
|
||
|
|
|
||
|
|
let selectNode = this.sinfo[i];
|
||
|
|
let cmp = selectNode.getComponent( ItemBase );
|
||
|
|
if( cmp ){
|
||
|
|
if( !nx.dt.objGood( cmp.mdata ) ){
|
||
|
|
let data = {};
|
||
|
|
data.pos = i + 1;
|
||
|
|
data.item_bid = nx.dt.objClone( cmp.mdata || -1 );
|
||
|
|
choice.push( data );
|
||
|
|
}else{
|
||
|
|
let data = {};
|
||
|
|
|
||
|
|
data.pos = i + 1;
|
||
|
|
data.item_bid = 0;
|
||
|
|
// console.log( "当前的pos2" + JSON.stringify( data ) );
|
||
|
|
choice.push( data );
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
for (let i = 0; i < choice.length; i++) {
|
||
|
|
if ( choice[i].item_bid < 0 ) {
|
||
|
|
choice.splice(i, 1); // 将使后面的元素依次前移,数组长度减1
|
||
|
|
i--; // 如果不减,将漏掉一个元素
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
EC.sender26514( choice );
|
||
|
|
},
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
});
|