const BridgeWindow = require( "bridge.window" ); const BackPackController = require( "backpack_controller" ); const PrayMod = require( "pray.mod" ); const TipsController = require( "tips_controller" ); cc.Class({ extends: BridgeWindow, properties: { luckyHolys:{ default: [], type: cc.Node }, nodRewards:{ default: null, type: cc.Node }, // :{ default: [], type: cc.Node }, rewards:{ default: [], type: cc.Node }, nodScore:{ default: null, type: cc.Node }, nameLen : 0, }, onEnable: function() { // 视图监听 this.vbind( [ [ "HolyPray", this.dealPray.bind( this ) ] ] ); }, // 隐藏 onDisable: function() { // 视图监听解除 this.vunbind(); // 事件监听释放 }, // 重载:参数打开 onOpenConfigs: function( _params ) { let pray = PrayMod.getInstance(); let score = pray.getScore(); nx.gui.setString( this.nodScore, "txt", nx.text.format( "ScoreMax", score ) ); this.score = score; }, // 重载:关闭前 onPreClosed: function() { }, // 重载:参数打开 dealPray: function( _data ) { this.prayInfos = _data; this.prayInfos.forEach( _pray =>{ if( _pray.is_open == 1 ){ this.nowPrayInfos = _pray; } } ) this.nowPrayInfos.lucky_holy_eqm.sort( Utils.tableUpperSorter( "pos" ) ); //刷新 许愿战斗义肢神装相关 this.freshLuckyHoly(); //刷新 许愿战斗义肢/神装 奖励相关 this.freshLuckyHolyRewards(); }, freshLuckyHoly: function(){ // 刷新 祈禱相關 this.showRewards = []; let cfgs = game.configs.holy_eqm_lottery_data.data_wish_show; let wishes = this.nowPrayInfos.lucky_holy_eqm; if( nx.dt.arrEmpty( wishes ) ){ this.luckyHolys.forEach( _nod => { nx.gui.setActive( _nod, "holy", false ); nx.gui.setActive( _nod, "name", false ); nx.gui.setActive( _nod, "empty", true ); } ) }else{ for (let i = 0; i < wishes.length; i++) { let wish = wishes[i]; nx.gui.setActive( this.luckyHolys[wish.pos], "holy", wish.lucky_holy_eqm != 0 ); nx.gui.setActive( this.luckyHolys[wish.pos], "empty", wish.lucky_holy_eqm == 0 ); nx.gui.setActive( this.luckyHolys[wish.pos], "name", wish.lucky_holy_eqm != 0 ); let cfg = cfgs[wish.lucky_holy_eqm]; if( cfg ){ let set = parseInt( cfg.group_id / 100 ); let path = cc.path.join( "coms/images/eqm_set" + set ); nx.gui.setSpriteFrame( this.luckyHolys[wish.pos], "holy/ico_set", path ); nx.bridge.setIcon( this.luckyHolys[wish.pos], "holy/icon", cfg.icon ); nx.gui.setString( this.luckyHolys[wish.pos], "name/txt", nx.dt.strCut( cfg.name, this.nameLen ) ); } } } nx.gui.setString( this, "panel/sid", this.nowPrayInfos.lev ); nx.gui.setString( this, "panel/desc/time", nx.text.format( "lab_heaven_tips_8", this.nowPrayInfos.baodi_count ) ); }, freshLuckyHolyRewards: function(){ let BC = BackPackController.getInstance(); let limit = game.configs.holy_eqm_lottery_data.data_group[this.nowPrayInfos.group_id] ; let one = nx.gui.find( this.nodRewards, "op/once" ); let ten = nx.gui.find( this.nodRewards, "op/ten" ); let prog = nx.gui.getComponent( this.nodRewards, "awards/prog", cc.ProgressBar ); let count = Object.keys( game.configs.holy_eqm_lottery_data.data_award[this.nowPrayInfos.group_id] ).length; let total = game.configs.holy_eqm_lottery_data.data_award[this.nowPrayInfos.group_id][count]; if( prog ){ prog.progress = parseFloat( this.nowPrayInfos.all_award_count/ total.times ); } nx.gui.setStringRich( this, "panel/times", nx.text.format( "lab_heaven_tips", this.nowPrayInfos.day_count, limit.day_limit_count ) ); this.mat = limit.loss_item_once[0][0]; // let nodRewards = nx.gui.find( this.nodRewards, ) // 設置寶箱可領取 nx.gui.setString( this.nodRewards, "awards/count/txt", this.nowPrayInfos.all_award_count ); let rewards = game.configs.holy_eqm_lottery_data.data_award[this.nowPrayInfos.group_id]; for (let i in rewards ) { let award = rewards[i]; let nod = this.rewards[ i-1 ]; if( nod ){ nx.gui.setString( nod, "txt", award.times ); let lay = nx.gui.getComponent( nod, "show", "cmp.item.layout" ); if( lay ){ lay.rebuild( award.reward ); } let data = { "award_id" : i } nx.gui.setActive( nod, "get", award.times <= this.nowPrayInfos.all_award_count ); } } this.nowPrayInfos.do_awards.forEach( _ard =>{ let nod = this.rewards[ _ard.award_id - 1 ]; nx.gui.setActive( nod, "get", false ); } ) let cost = 0 ; let canBuyTen = false; let have = BC.getModel().getItemNumByBid( this.mat ); nx.gui.setActive( one, "cost/info/icon", false ); if( this.nowPrayInfos.free_times == 1 ){ cost = nx.text.getKey( "btn_battle_fast_fight_free" ); }else{ if( have >= limit.loss_item_once[0][1] ){ cost = limit.loss_item_once[0][1]; nx.bridge.setIconS( one, "cost/info/icon", this.mat ); }else{ nx.bridge.setIconS( one, "cost/info/icon", 3 ); cost = limit.loss_gold_once; } nx.gui.setActive( one, "cost/info/icon", true ); // nx.bridge.setIconS( one, "cost/icon", this.mat ); } if( have >= limit.loss_item_ten[0][1] ){ canBuyTen = true; } nx.gui.setString( one, "cost/info/txt", cost ); nx.bridge.setIconS( ten, "cost/icon", canBuyTen ? this.mat : 3 ); nx.gui.setString( ten, "cost/txt", canBuyTen ? limit.loss_item_ten[0][1] : limit.loss_gold_ten ); }, // 添加許願戰鬥義肢 onTouchAddWish: function( _idx ){ nx.bridge.createPanel( "WndHolyPrayWish", { group_id: this.nowPrayInfos.group_id, select : this.nowPrayInfos.lucky_holy_eqm, focus : parseInt( _idx ) } ) }, onTouchShow: function( _idx ){ for (let i = 0; i < this.rewards.length; i++) { let nod = this.rewards[i]; if( i != _idx ){ nx.gui.setActive( nod, "show", false ); } } let nod = nx.gui.find( this.rewards[_idx], "show" ); nx.gui.setActive( nod, "", !nod.active ); }, onTouchGet: function( _idx ){ let pray = PrayMod.getInstance(); pray.sender25231( this.nowPrayInfos.group_id, _idx ); }, onTouchPray: function( _times ){ let BC = BackPackController.getInstance(); let pray = PrayMod.getInstance(); let have = BC.getModel().getItemNumByBid( this.mat ); let haveDiam = BC.getModel().getItemNumByBid( 3 ); let canBuyOne = false; let canBuyTen = false; let type = 0; let cfg = game.configs.holy_eqm_lottery_data.data_group[this.nowPrayInfos.group_id] ; if( have > 0 ){ if( have >= cfg.loss_item_once[0][1] && have < cfg.loss_item_ten[0][1] ){ canBuyOne = true; canBuyTen = false; type = 4; }else if( have >= cfg.loss_item_ten[0][1] ){ canBuyTen = true; canBuyOne = true; type = 4; } }else{ if( haveDiam >= cfg.loss_gold_once && haveDiam < cfg.loss_gold_ten ){ canBuyOne = true; canBuyTen = false; type = 3; }else if( haveDiam >= cfg.loss_gold_ten ){ canBuyTen = true; canBuyOne = true; type = 3; } } // console.log( haveDiam + "sss" + type + "是否可以祈禱單次" + canBuyOne + "是否可以祈禱ss" + canBuyTen + have ); if( _times <= cfg.loss_item_once[0][1] ){ if( this.nowPrayInfos.free_times == 1 ){ pray.sender25217( this.nowPrayInfos.group_id, _times, 1 ); return; }else{ if( !canBuyOne ){ nx.tbox( "SummonItemNotEnough" ); return; } } } else{ if( !canBuyTen ){ nx.tbox( "SummonItemNotEnough" ); return; } } pray.sender25217( this.nowPrayInfos.group_id, _times, type ); }, onTouchUplev: function(){ nx.bridge.createPanel( "WndHolyStatueUplev", this.nowPrayInfos ); }, onTouchRate: function(){ nx.bridge.createPanel( "WndHolyPrayRate", this.nowPrayInfos ); }, onTouchEqmAutoSell: function(){ nx.bridge.createPanel( "WndHolyEqmAutoSell", this.nowPrayInfos ); }, onTouchShop: function(){ nx.bridge.createPanel( "WndHolyPrayShop", { score : this.score } ); }, // 规则说明 onTouchTip: function() { let desc = game.configs.holy_eqm_lottery_data.data_const.salvage_rule; let TC = TipsController.getInstance(); if( TC ) { TC.showTextPanel( desc.title, desc.desc ); } }, });