const BridgeWindow = require( "bridge.window" ); const ItemBase = require( "cmp.item.base" ); const TipsController = require( "tips_controller" ); const HeroController = require( "hero_controller" ); const BackpackController = require( "backpack_controller" ); const HeroEvent = require( "hero_event" ); cc.Class({ extends: BridgeWindow, properties: { nodItem: { default: null, type: ItemBase }, nodProps: { default: null, type: cc.Node }, nodNow: { default: null, type: cc.Node }, nodNext: { default: null, type: cc.Node }, nodCheck: { default: null, type: cc.Node }, nodMats: { default: null, type: cc.Node }, nodOps: { default: null, type: cc.Node }, }, onLoad: function(){ this.bindGEvent( EventId.MODIFY_GOODS_NUM, this.onUpdateGoods.bind( this ) ); this.bindGEvent( HeroEvent.Artifact_Update_Event, this.onUpdateInfo.bind( this ) ); }, onUpdateInfo: function( _data ){ let art = _data.artifacts; art.forEach( _art =>{ if( this.pos ){ if( _art.base_id == this.item.base_id && this.pos == _art.artifact_pos ){ this.freshR( _art, true ); this.nodItem.setData( _art.base_id ); } }else{ if( _art.base_id == this.item.base_id ){ this.freshR( _art, true ); this.nodItem.setData( _art.base_id ); } } } ) }, onUpdateGoods: function( _bagCode, _itemList ){ let lst = _itemList; if( lst[this.item.id] ){ if( lst[this.item.id].base_id == this.item.base_id ){ if( this.doid == lst[this.item.id].base_id ){ this.freshR( lst[this.item.id], true ); } } } }, // 重载:参数打开 onOpenConfigs: function( _params ) { this.config = _params.config; this.doid = _params.item.base_id; this.pos = _params.pos; this.item = _params.item; this.partner_id = this.item.partner_id ? this.item.partner_id : 0; // this.fresh(); this.freshR( this.item ); }, freshR: function( _data, _active ){ this.item = _data; let attr = _data.extra_attr; let attr_nod = nx.gui.find( this.nodNext, "props/props" ); let skill = _data.extra; let skills_nod = nx.gui.find( this.nodNext, "cnt/skills" ); let chd = skills_nod.children; let skillr = []; for (let i = 0; i < skill.length; i++) { let item = skill[i]; if( item ){ if( ( item.extra_k == 3 && item.extra_v > 0 ) || ( item.extra_k == 4 && item.extra_v > 0 ) ){ skillr.push( item ); } } // if( i == 1 || i == ) } this.fresh(); let achd = attr_nod.children; for (let O = 0; O < achd.length; O++) { let nod = achd[O]; let atr = attr[O]; if( !atr ){ nx.gui.setActive( nod, "" , false ); continue; } nx.gui.setActive( nod, "" , true ); let atr_key = game.configs.attr_data.data_id_to_key[atr.attr_id]; nx.bridge.attrs.setAttribute( nod, [ atr_key, ( atr.attr_val / 1000 ) ] ); } for (let i = 0; i < chd.length; i++) { let nod = chd[i]; let item = skillr[i]; let cmp = nod.getComponent( "cmp.skill.base" ); if( !item || item.extra_v == 0 ){ if( cmp ){ cmp.setData( 0 ); } continue; } if( cmp ){ cmp.setData( item.extra_v ); } } let lucky_art = game.configs.partner_artifact_data.data_artifact_const.lucky_artifact_ids.val; let cfg = game.configs.partner_artifact_data.data_artifact_data; let info = {}; if( cfg ){ info = cfg[ this.item.base_id ]; } if( _active ){ this.freshMat( lucky_art, info ); } nx.gui.setActive( this.nodOps, "yr/save", !nx.dt.arrEmpty( this.item.extra_attr ) ); }, fresh: function(){ this.nodItem.setData( this.item.base_id ); let item_id = this.item.base_id; let cfg = game.configs.partner_artifact_data.data_artifact_data; let info = {}; let skills = []; let skill = this.item.extra; let lucky_art = game.configs.partner_artifact_data.data_artifact_const.lucky_artifact_ids.val; for (let i = 0; i < skill.length; i++) { let sk = skill[i]; if( ( sk.extra_k == 1 && sk.extra_v > 0 ) || ( sk.extra_k == 2 && sk.extra_v > 0 ) ){ skills.push( sk.extra_v ); } } if( cfg ){ info = cfg[item_id]; } let attr = this.item.attr; let attr_nod = nx.gui.find( this.nodNow, "props/props" ); let achd = attr_nod.children; for (let O = 0; O < achd.length; O++) { let nod = achd[O]; let atr = attr[O]; if( !atr ){ nx.gui.setActive( nod, "" , false ); continue; } nx.gui.setActive( nod, "" , true ); let atr_key = game.configs.attr_data.data_id_to_key[atr.attr_id]; nx.bridge.attrs.setAttribute( nod, [ atr_key, ( atr.attr_val / 1000 ) ] ); } let skills_nod = nx.gui.find( this.nodNow, "cnt/skills" ); let chd = skills_nod.children; for (let j = 0; j < chd.length; j++) { let nod = chd[j]; let item = skills[j]; if( !item ){ nx.gui.setActive( nod, "" , false ); continue; } nx.gui.setActive( nod, "" , true ); let cmp = nod.getComponent( "cmp.skill.base" ); if( cmp ){ cmp.setData( item ); } } this.freshMat( lucky_art, info ); nx.gui.setActive( this.nodOps, "lucky", this.item.base_id == lucky_art[0][0] ); }, freshMat: function( _luck ,_info ){ let lucky_art = _luck; let info = _info; let luck_item = game.configs.partner_artifact_data.data_artifact_const.lucky_item_id2.val; let luck_use = [ luck_item, 1 ]; let model = BackpackController.getInstance().getModel(); let have = model.getItemNumByBid(luck_item); this.enough = have >= lucky_art[0][1]; let use = nx.dt.objClone( info.ref_expend ); let check = this.nodCheck.getComponent( cc.Toggle ).isChecked; // info.ref_expend = info.ref_expend; this.item.base_id == lucky_art[0][0] && check == true ? use.push( luck_use ) : info.ref_expend; let mchd = this.nodMats.children; for (let I = 0; I < mchd.length; I++) { let mat = use[I]; let mnod = mchd[I]; if( !mat ){ nx.gui.setActive( mnod, "" , false ); continue; } nx.bridge.setIconS( mnod, "icon",mat[0] ); let haves = model.getItemNumByBid( mat[ 0 ] ); let str = nx.dt.shortCount( mat[ 1 ] ) + "/" + nx.dt.shortCount( haves ); let clr = ( haves >= mat[ 1 ] ) ? cc.Color.WHITE : cc.Color.RED; nx.gui.setColor( mnod, "txt", clr ); nx.gui.setActive( mnod, "" , true ); nx.gui.setString( mnod, "txt", str ); } }, freshCheck: function(){ let lucky_art = game.configs.partner_artifact_data.data_artifact_const.lucky_artifact_ids.val; let cfg = game.configs.partner_artifact_data.data_artifact_data; let info = {}; if( cfg ){ info = cfg[ this.item.base_id ]; } this.freshMat( lucky_art, info ); }, onTouchHelp: function(){ let dfg = game.configs.partner_artifact_data.data_artifact_const.lucky_artifact_desc; let desc = dfg.desc; let TC = TipsController.getInstance(); if( TC ){ TC.showTextPanel( "Rule", desc ); } }, onTouchHelpN: function(){ let dfg = game.configs.partner_artifact_data.data_artifact_const.recast_rule; let desc = dfg.desc; let TC = TipsController.getInstance(); if( TC ){ TC.showTextPanel( "Rule", desc ); } }, onTouchForgot: function(){ let HC = HeroController.getInstance(); let artifact_id = this.item.id; let skills = {}; let check = this.nodCheck.getComponent( cc.Toggle ).isChecked; let luck_item = this.enough && check == true && nx.gui.find( this.nodOps, "lucky" ).active == true ? 2 : 0; if( check == true && !this.enough && nx.gui.find( this.nodOps, "lucky" ).active == true ){ nx.tbox( "tip_noEnoughMaterial" ); return; } HC.sender11033( this.partner_id, artifact_id, skills, luck_item ); }, onTouchSave: function(){ let HC = HeroController.getInstance(); HC.sender11034( this.partner_id, this.item.id, 1); }, });