/****************************************************************** * Copyright(C) 2019 - 2020 Nx Studio * * StepUp任务项 * * 2018.05.18 ******************************************************************/ const SVCItem = require( "nx.fx.sv.expand.item" ); const ItemLayout = require( "cmp.item.layout" ); const SummonDefine = require( "summon.define" ); const RoleController = require( "role_controller" ); const BackPackController = require( "backpack_controller" ); const STModel = require( "act.stepup.mod" ); const SCRT = SummonDefine.Status; cc.Class( { extends: SVCItem, properties: { nodStep: { default: null, type: cc.Node }, nodDesc: { default: null, type: cc.Node }, lstRewards: { default: null, type: ItemLayout }, nodOps: { default: null, type: cc.Node }, }, // 数据重置 rebind: function( _idx, _data, _key ) { this._super( _idx, _data, _key ); if( nx.dt.objEmpty( _data ) ) { return; } this.data = _data; this.step = _data.step; // 序列 nx.gui.setString( this.nodStep, "txt", `STEP ${this.step}` ); // 奖励 let items = []; let push = function( _bid ) { if( nx.dt.numPositive( _bid, false ) ) { items.push( [ _bid, 1 ] ); } }; push( _data.item1_id ); push( _data.item2_id ); push( _data.item3_id ); this.lstRewards.rebuild( items ); // 文本 nx.gui.setString( this.nodDesc, "", nx.text.getKey( _data.content ) ); nx.gui.setColor( this.nodDesc, "", new cc.Color().fromHEX( _data.color ) ); // OPS let data = STModel.getInstance().getData(); this.setCurrentStep( data ? data.step : 0 ); }, // 设置当前步骤 setCurrentStep: function( _step ) { // 未到 if( this.step > _step ) { nx.gui.setActive( this.nodOps, "get", false ); nx.gui.setActive( this.nodOps, "done", false ); return; } // 已过 if( this.step < _step ) { nx.gui.setActive( this.nodOps, "get", false ); nx.gui.setActive( this.nodOps, "done", true ); return; } // 当前 let cost = this.data.item_show[0]; let args = { enough: false, type: SCRT.Item, bid: cost[0], need: cost[1], }; // 道具判断 const BC = BackPackController.getInstance(); const BM = BC.getModel(); // 道具不足或者次数够用则可用钻石 let cnt = BM.getBackPackItemNumByBid( args.bid ); if( cnt >= args.need ) { args.enough = true; } let data = STModel.getInstance().getData(); if( cnt < args.need && data.gold_times > 0 ) { let diamonds = this.data.diamond_show[0]; if( diamonds[0] != 3 ) { nx.error( "[STEP-UP]不支持非钻石!" ); } else { let role = RoleController.getInstance().getRoleVo(); if( role.gold >= diamonds[1] ) { args.enough = true; args.type = SCRT.Diamond; args.bid = diamonds[0]; args.need = diamonds[1]; } } } else { args.enough = true; } nx.gui.setActive( this.nodOps, "done", false ); let btn = nx.gui.setActive( this.nodOps, "get", true ); btn.params = args; // 货币刷新 let tinfo = gitemdata( args.bid ); nx.bridge.setIcon( btn, "list/icon", tinfo.icon ); nx.gui.setString( btn, "list/num", args.need ); }, } );