const SvcItem = require( "nx.fx.sv.expand.item" ); const RoleController = require( "role_controller" ) const PathTool = require( "pathtool" ); cc.Class( { extends: SvcItem, properties: { isSelf: { default: false, displayName: "是否属于自己" }, icon: { default: null, type: cc.Sprite }, frame: { default: null, type: cc.Sprite }, lev: { default: null, type: cc.Label }, desc: { default: null, type: cc.Label }, leader_icon: { default: null, type: cc.Node }, bg: { default: null, type: cc.Node } }, // LIFE-CYCLE CALLBACKS: // 数据重置 rebind: function( _idx, _data, _key ) { this._super( _idx, _data, _key ); // 刷新 this.setData( _data ) }, onLoad() { this.normal = new cc.Material.createWithBuiltin( "2d-sprite" ) this.gray = new cc.Material.createWithBuiltin( "2d-gray-sprite" ); if( this.isSelf ) { let role_vo = RoleController.getInstance().getRoleVo(); this.setData( role_vo ); //需要绑定属性改变监听 } }, start() { }, setData( _data ) { if( nx.dt.objEmpty( _data ) ) { return false; } this.setEmpty(); if( _data.desc ) { this.desc.string = _data.desc; } if( _data.is_leader ) { this.leader_icon.active = _data.is_leader; } if( this.lev ){ this.lev.string = _data.lev || ""; } this.loadHeadRes( _data.face || _data.face_id ); this.loadFrameRes( _data.avatar || _data.avatar_bid || _data.avatar_base_id || _data.avatar_id); }, setEmpty() { if( this.lev ){ this.lev.string = ""; } this.desc.string = ""; this.leader_icon.active = false; this.bg.active = true; this.frame.spriteFrame = null; }, // 设置锁定状态 setLockStatus: function( bool ) { if( bool ) { this.icon.setMaterial( this.gray ); this.frame.setMaterial( this.gray ); } else { this.icon.setMaterial( this.normal ); this.frame.setMaterial( this.normal ); } }, setHeadRes( res ) { this.loadHeadRes( res ); }, setFrameRes( res ) { this.loadFrameRes( res ); }, // 加载资源,这里可能需要判断一下加载回来的是不是我需要的资源,私有方法 不能外部调用,外部滴啊用请用 setHeadRes loadHeadRes: function( res_id ) { if(!res_id)return; nx.bridge.setAvatarByFaceId( this.icon, "", res_id ); }, loadFrameRes: function( bid ) { if(!bid)return; nx.bridge.setAvatarFrame( this.frame, "", bid ); }, addCallBack( cb ) { this.touch_cb = cb; this.openTouch( true, this.touch_cb.bind( this ) ); } // update (dt) {}, } );