/****************************************************************** * * 英雄限購 * ******************************************************************/ const ActPage = require( "act.page.base" ); const BCT = require("battle_controller"); const NxSpine = require("nx.fx.spine"); const PathTool = require("pathtool"); const ItemLay = require("cmp.common.itemlayout"); const HeroConst = require("hero_const"); const Payment = require( "payment.mod" ); const TxtColor = [new cc.Color(187,7,7),new cc.Color(29,107,1),new cc.Color(33,60,225)]; cc.Class( { extends: ActPage, properties: { roleSp:{ default:null, type:NxSpine }, ndTi:{//標題圖片 default:null, type:cc.Node }, ndTi2:{//標題圖片2 default:null, type:cc.Node }, ndSmod:{ default:null, type:cc.Node }, fabSmod:{ default:null, type:cc.Prefab }, cdTime:{ default:null, type:cc.Node }, giftLay1:{ default:null, type:ItemLay }, giftLay2:{ default:null, type:ItemLay }, oldTxt:{ default:[], type:[cc.Node] }, priceTxt:{ default:[], type:[cc.Node] }, buyNds:{ default:[], type:[cc.Node] }, playBtn:{ default:null, type:cc.Node }, giftTxts:{ default:[], type:[cc.Node] }, attrNd:{ default:null, type:cc.Node }, attrPersons: { default: null, type: cc.Node }, attrTeam: { default: null, type: cc.Node }, }, // 初始化 build: function( _data ) { this._super( _data ); this.quota_data = game.configs.activity_set_quota_data; this.payId = []; // 活动监听 this.mod.vbind( this, [ [ "buyLimitCamp", this.setCampId.bind( this ) ], [ "buyLimitInfos", this.freshInfos.bind( this ) ], ] ); }, onEnable(){ this.camp_id = this.data.camp_id; this.mod.reqLimitData(this.data.camp_id); }, onDisable(){ this.giftLay1.rebuild([]); this.giftLay2.rebuild([]); }, // 销毁 onDestroy: function() { // 活动监听解除 if( this.mod ) { this.mod.vunbind( this ); } this._super(); }, setCampId(camp_id){ this.cur_camp_id = camp_id; }, freshInfos(data){ this.payId = []; if(nx.dt.objEmpty(data))return; let info = data[this.data.camp_id]; if(info.bid!=this.cur_camp_id)return; if(nx.dt.objEmpty(info))return; let resInfo = this.quota_data.data_holiday_res[info.bid]; if(resInfo){ this.pv_id = resInfo.fake_battle_id; if(this.pv_id == null || this.pv_id == ""){ this.playBtn.active = false; } nx.gui.setActive(this.attrNd,"",resInfo.is_skin == 1); let tiicon = cc.js.formatStr("locals/%s/images/acts/%s",nx.getLocLanguage(),resInfo.interface_art); nx.gui.setSpriteFrame(this.ndTi,"",tiicon); let skin_info = null; let h_config = null; if(resInfo.is_skin == 1){ skin_info = game.configs.partner_skin_data.data_skin_info[resInfo.skin_id]; if(skin_info){ // let tiicon3 = cc.js.formatStr("locals/%s/images/acts/%s",nx.getLocLanguage(),resInfo.skin_title); // nx.gui.setSpriteFrame(this.ndTi2,"",tiicon3); let skin_path = PathTool.getSpinePath(skin_info.res_id,"show",false); this.roleSp.node.x = -300; this.roleSp.load(skin_path,(_e)=>{ if(_e){ this.roleSp.stop(); }else{ this.roleSp.action("action1",true); } }); // 个人属性加成 let attrs = skin_info.skin_attr || []; let chds = this.attrPersons.children; nx.gui.gocChildren( this.attrPersons, "", attrs.length, chds[ 0 ] ); for( let i = 0; i < attrs.length; ++i ) { for(let v in chds[i].children){ chds[i].children[v].color = TxtColor[i]; } nx.bridge.attrs.setAttribute( chds[ i ], attrs[ i ] ); } // 团体属性加成 let allattrs = skin_info.skin_attr_all || []; if(nx.dt.arrEmpty(allattrs)){ this.attrTeam.active = false; nx.gui.setActive(this.attrNd,"ti2",false); }else{ this.attrTeam.active = true; nx.gui.setActive(this.attrNd,"ti2",true); let chds2 = this.attrTeam.children; nx.gui.gocChildren( this.attrTeam, "", allattrs.length, chds2[ 0 ] ); for( let i = 0; i < allattrs.length; ++i ) { for(let v in chds2[i].children){ chds2[i].children[v].color = TxtColor[i]; } nx.bridge.attrs.setAttribute( chds2[ i ], allattrs[ i ] ); } } } }else{ h_config = game.configs.partner_data.data_partner_base[resInfo.partner_id]; if(h_config){ let tiicon2 = cc.js.formatStr("locals/%s/images/acts/%s",nx.getLocLanguage(),resInfo.title); let res_path = PathTool.getSpinePath(h_config.bustid,"show",false); nx.gui.setSpriteFrame(this.ndTi2,"",tiicon2); this.roleSp.load(res_path,(_e)=>{ if(_e){ this.roleSp.stop(); }else{ this.roleSp.action("action1",true); } }); } } //小模型 if(!this.sHero){ this.sHero = cc.instantiate(this.fabSmod); this.sHero.parent = this.ndSmod; this.sHero.y += 25; } let scmp = nx.gui.getComponent(this.sHero,"","cmp.partner.smod"); if(scmp){ if(resInfo.is_skin == 1){ scmp.setData({use_skin:skin_info.skin_id},true,false); }else{ scmp.setData(h_config,true,false); } } } //倒计时cd nx.gui.setCdTxt( this.cdTime, "", info.remain_sec ); for(let i in info.aim_list){ let aim_data = info.aim_list[i]; if(aim_data){ nx.gui.setString(this.giftTxts[i],"",aim_data.aim_str); for(let arg_k in aim_data.aim_args){ let arg = aim_data.aim_args[arg_k]; if(arg.aim_args_key == 35){ //設置原價 nx.gui.setString( this.oldTxt[i], "", cc.js.formatStr("-%s%",arg.aim_args_val) ); } if(arg.aim_args_key == 26){ //設置現價 let xprice = Payment.getInstance().fmtPrice( arg.aim_args_val ); nx.gui.setString( this.priceTxt[i], "", xprice ); } if(arg.aim_args_key == 33){ //獲取支付id this.payId.push(arg.aim_args_val); } //是否购买完成 if(arg.aim_args_key == 6){ if(arg.aim_args_val == 1){ let btn = nx.gui.getComponent(this.buyNds[i],"",cc.Button); if(btn){ btn.interactable = false; } nx.gui.setString(this.buyNds[i], "price", nx.text.getKey("Charged")); } // nx.gui.setActive(this.buyNds[i],"",arg.aim_args_val == 0); } } } } this.giftLay1.rebuild(info.aim_list[0].item_list); this.giftLay2.rebuild(info.aim_list[1].item_list); }, onBuyGift(_id){ let charge_id = this.payId[_id]; if(charge_id){ Payment.getInstance().reqPayment( charge_id ); } }, onTryBat(){ if(!this.pv_id)return; BCT.getInstance().requestUseHeroBattle(1,this.pv_id); } } );