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" ); const HeroController = require("hero_controller"); const HeroConst = require( "hero_const" ); const BackPackConst = require( "backpack_const" ); const HEHY = HeroConst.HolyequipmentPosList; /********** * * 僚机方案 单项 */ cc.Class({ extends: SVCItem, properties: { sname : { default: null, type : cc.Node, displayName : "方案名", }, nodfocus : { default: null, type : cc.Node, displayName : "聚焦", }, nodUser: { default: null, type : cc.Node, displayName : "使用者", }, nodAddnew :{ default: null, type : cc.Node, displayName : "新增", }, nodItem :{ default: null, type : cc.Node, displayName : "方案", }, nodId:{ default: null, type : cc.Node, displayName : "编号", }, }, // 数据重置 rebind: function (_idx, _data, _key) { this._super(_idx, _data, _key); this.freshInfo(); }, // 刷新具体信息 freshInfo:function(){ let HC = HeroController.getInstance(); if( this.mdata ){ // console.log( "当前的方案数据信息"+ this.mdata.id + JSON.stringify( this.mdata ) ); // {"id":1,"name":"Scheme1","is_open":1,"open_cost":[]} if( this.nodId ){ nx.gui.setString( this.nodId, "", this.mdata.id ); } nx.gui.setString( this.sname, "", this.mdata.name ); if( this.nodUser ) { nx.gui.setString( this.nodUser, "", "" ); } if( !nx.dt.arrEmpty( this.mdata.open_cost ) ){ if( this.nodAddnew ){ let anode = nx.gui.find( this.nodAddnew, "add/icon" ); let nnode = nx.gui.find( this.nodAddnew, "add/cost/num" ); nx.bridge.setIconS( anode, "", this.mdata.open_cost[0][0] ); nx.gui.setString( nnode, "", this.mdata.open_cost[0][1]); } } let slots = nx.gui.find( this.nodItem, "slots" ); let descs = nx.gui.find( this.nodItem, "desc" ); // 如果当前的list配置数据不为空 if( !nx.dt.arrEmpty( this.mdata.list ) ){ let allEqm = {}; allEqm = this.getAllHolyLst( this.mdata.list ); // 套装说明 // let nod_desc = nx.gui.find( descs, "desc" ); let lst = HC.getModel().getHolyEquipSuitDes( allEqm ); nx.gui.setActive( descs, "", !nx.dt.arrEmpty( lst ) ); if( !nx.dt.arrEmpty( lst ) && descs ){ for (let i = 0; i < lst.length; i++) { let desc = lst[i].name; let nod = descs.children[i]; if( nod ){ nx.gui.setString( nod, "txt", desc ); let path = cc.path.join( "coms/images/eqm_set" + Math.floor( lst[i].id / 100 ) ); nx.gui.setSpriteFrame( nod, "ticon", path ); } } } // 取当前列表中伙伴穿戴 holy数据 let partner = HC.getModel().getHeroById( this.mdata.partner_id ); let name = partner ? partner.name : "None"; nx.gui.setString( this.nodUser, "", name ); let p_num = 0; for (let i = 0; i < this.mdata.list.length; i++) { let item = this.mdata.list[i]; let idata = {}; if( !nx.dt.objEmpty( allEqm ) ){ for (let pos in HEHY ) { let eqm = allEqm[pos]; let slot = nx.gui.find( slots, "slot"+ pos ); let emt = nx.dt.objEmpty( eqm ); nx.gui.setActive( slot, "empty", emt ); nx.gui.setActive( slot, "tip", false ); nx.gui.setActive( slot, "item", !emt ); let cmp = nx.gui.getComponent( slot, "item", "cmp.item.base" ); if( cmp ){ if( !emt ){ cmp.setData( eqm ); }else{ cmp.setData( null ); } } } } } }else{ for (let pos in HEHY ) { let slot = nx.gui.find( slots, "slot"+ pos ); nx.gui.setActive( slot, "empty", true ); nx.gui.setActive( slot, "tip", false ); nx.gui.setActive( slot, "item", false); let cmp = nx.gui.getComponent( slot, "item", "cmp.item.base" ); if( cmp ){ cmp.setData( null ); } } } nx.gui.setActive( this, "sch_info", this.mdata.is_open != 0 ); if( this.nodAddnew ){ nx.gui.setActive( this.nodAddnew, "", this.mdata.is_open == 0 ); } if( this.nodItem ){ nx.gui.setActive( this.nodItem, "", this.mdata.is_open == 1 ); } } }, getAllHolyLst: function( _list ){ if (!_list) { return }; if ( _list.length == 0 ) { return {} }; let holy_list = {} //神装数据 for ( const k in _list) { const v = _list[k]; if (v.item_id) { let item_vo = {}; if (v.partner_id == 0) { //在装备背包中 item_vo = BackpackController.getInstance().getModel().getBagItemById(BackPackConst.Bag_Code.EQUIPS, v.item_id); } else { //英雄已穿戴 item_vo = HeroController.getInstance().getModel().getHolyEquipById(v.item_id); } if (item_vo && item_vo.config) { holy_list[item_vo.config.type] = item_vo; } } } return holy_list; }, 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 HC = HeroController.getInstance(); let self = this; let modify = function( _name ) { HC.sender25221( self.mdata.id, self.mdata.partner_id, _name, self.mdata.list ); }; 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 HC = HeroController.getInstance(); // let pfg = game.configs.sprite_data.data_elfin_plan[this.index + 1]; let have = BackpackController.getInstance().getModel().getItemNumByBid( this.mdata.open_cost[0][0] ); let need = this.mdata.open_cost[0][1]; // 不足弹出提示 if( have < need ){ nx.tbox( nx.text.getKey( "elfin_hatch_unlock_5" ) ); return; } let mat0 = this.mdata.open_cost[0][0]; // let txt = nx.text.format( "lab_heaven_msg_tips_19n", need, this.index + 1 ); let buy_ori = nx.text.format( "lab_heaven_msg_tips_19", String( mat0 ), need, this.index + 1 ); let des_str = buy_ori; nx.mbox( des_str, [ 'cancel', 'confirm' ], ( _key, _box ) => { _box.close(); if( _key == "confirm" ) { HC.sender25223(); } } ); }, onTouchSlot: function( _partId ){ let stype = parseInt( _partId ); let slots = nx.gui.find( this.nodItem, "slots" ); // 取相关的战斗义肢 // 点击装备槽 const self = this; let eqm = {}; const HC = HeroController.getInstance(); let nod = nx.gui.find( slots, "slot"+ stype ); let cmp = nx.gui.getComponent( nod, "item", "cmp.item.base" ); if( cmp ){ eqm = cmp.mdata; } let partner = HC.getModel().getHeroById( this.mdata.partner_id ); // 脱下 const takeoff = function() { HC.sender25221( self.mdata.id, self.mdata.partner_id, self.mdata.name, {} ); }; // 洗炼 const refinement = function() { if( self.mdata.partner_id == 0 ){ nx.tbox( "HolyAttachNoUser" ); return; }else{ HC.openHolyequipmentRefreshAttPanel( true, eqm, partner ); } // }; // 更换 const change = function() { let slt = []; slt = nx.dt.objClone( self.mdata.list ); let show = partner ? partner : 0; HC.openHolyChangePanel( true, stype, show, self.mdata.list, ( _id, _panel ) => { let data = { "partner_id": _id.mdata.partner_id, "item_id": _id.eqm, } let hero_lst = self.getAllHolyLst( slt ); // let dataL = self.getAllHolyLst( [data] ); let tch = BackpackController.getInstance().getModel().getBagItemById(BackPackConst.Bag_Code.EQUIPS, _id.eqm); // console.log( "处理所有的holy数据-------->>>>" + JSON.stringify( hero_lst ) ); let sls = []; let allPlan = HC.getModel().getHolyEquipmentPlanData(); for (let i in allPlan ) { let plan = allPlan[i]; if( plan.id == _id.mdata.id ){ sls = plan.list; } } // 判断是否是同类型替换 for (let i in hero_lst ) { let item = hero_lst[i]; if( item.config.type == tch.config.type ){ item = tch; } if ( nx.dt.arrEmpty( sls )) { sls.push({ "partner_id": _id.mdata.partner_id, "item_id": item.id, }) }else{ for (let i = 0; i < sls.length; i++) { if( !(sls[i].item_id == item.item_id ) ){ sls.push( item ); break } } } } if( nx.dt.arrEmpty( sls ) ){ sls.push( data ); }else{ for (let i = 0; i < sls.length; i++) { if( !(sls[i].item_id == data.item_id ) ){ sls.push( data ); break } } } HC.sender25221( _id.mdata.id, _id.mdata.partner_id, _id.mdata.name, sls ); },( _id, _panel ) => { let allPlan = HC.getModel().getHolyEquipmentPlanData(); for (let i in allPlan ) { let plan = allPlan[i]; if( plan.id == _id.mdata.id ){ slt = plan.list; } } for (let i = 0; i < slt.length; i++) { let s = slt[i]; if( s.item_id == _id.eqm ){ slt.splice( i, 1 ); } } HC.sender25221( _id.mdata.id, _id.mdata.partner_id, _id.mdata.name, slt ); }, self.mdata ); }; // 当前装备操作 if( !nx.dt.objEmpty( eqm ) ) { HC.openEquipChangePanel( true, eqm, ( _op, _panel ) => { _panel.close(); if( _op == "takeoff" ) { takeoff(); } if( _op == "change" ) { change(); } if( _op == "refinement" ) { refinement(); } } ); } // 新装备穿戴 else { change(); } }, onTouchSelect: function(){ // 返回 let HC = HeroController.getInstance(); let pid = 0; if( HC ){ pid = this.mdata.dif_id ? this.mdata.dif_id : this.mdata.partner_id; const eqms = HC.getModel().getHeroHolyEquipList( pid ); let holy_eqm = []; for (let i in eqms ) { let holy = eqms[i]; holy_eqm.push( { partner_id: pid, item_id: holy.id, } ) } HC.sender25221( this.mdata.id, pid, this.mdata.name, holy_eqm ); } }, onTouchUse: function(){ let HC = HeroController.getInstance(); HC.sender25224( this.mdata.dif_id, this.mdata.id ); }, onTouchClean: function( ){ let HC = HeroController.getInstance(); HC.sender25221( this.mdata.id, this.mdata.partner_id, this.mdata.name, {} ); }, });