/****************************************************************** * * 技能预览界面 * ******************************************************************/ const BridgeWindow = require( "bridge.window" ); const RoleController = require( "role_controller" ); const BackpackController = require( "backpack_controller" ); const TimeTool = require( "timetool" ); const FxTogs = require( "nx.fx.togs" ); const FxSVC = require( "nx.fx.sv.expand" ); const MenuTags = { Avatar: 0, HeadFrame: 1, Bubble: 2, Badge: 3, }; cc.Class( { extends: BridgeWindow, properties: { togMenu: { default: null, type: FxTogs }, nodPages: { default: null, type: cc.Node }, nodPreview: { default: null, type: cc.Node }, lstAvatars: { default: null, type: FxSVC }, lstFrames: { default: null, type: FxSVC }, lstBubbles: { default: null, type: FxSVC }, lstBadges: { default: null, type: FxSVC }, }, // 重载:参数打开 onOpenConfigs: function( _params ) { // 初始化预览 this.initPreview(); // Tog监听 this.togMenu.posTog = this.onTogMenu.bind( this ); if( _params.fromOther ){ this.togMenu.togTo( _params.fromOther ); this.onTogMenu( _params.fromOther ); return; } this.togMenu.togTo( 0 ); this.onTogMenu( 0 ); }, // 载入 onLoad: function() { // 监听绑定 this.role = RoleController.getInstance().getRoleVo(); // this.roleHandler = this.role.bind( EventId.UPDATE_ROLE_ATTRIBUTE, this.onRoleAttrUpdate, this ); // this.bindGEvent( RoleEvent.GetFaceList, this.rebuildFrameList.bind( this ) ); }, // 销毁 onDestroy: function() { // 监听绑定解除 if( this.roleHandler ) { this.role.unbind( this.roleHandler ); this.roleHandler = null; } }, // 重载:关闭前 onPreClosed: function() { // 列表清理 this.lstAvatars.rebuild( [] ); this.lstFrames.rebuild( [] ); this.lstBubbles.rebuild( [] ); this.lstBadges.rebuild( [] ); }, // 等级切换 onTogMenu: function( _index ) { switch( _index ) { case MenuTags.HeadFrame: { this.showFramePage(); } break; case MenuTags.Bubble: { this.showBubblePage(); } break; case MenuTags.Badge: { this.showBadgePage(); } break; default: { this.showAvatarPage(); } break; } }, // 角色属性改变 onRoleAttrUpdate: function( _key, _val ) { // // 头像更新 // if( _key == "face_id" || _key == "face_list" ) { // this.rebuildAvatarList(); // return; // } // // 头像框更新 // if( _key == "avatar_base_id" ) { // this.rebuildFrameList(); // return; // } }, // ======================================================================== // 头像选择相关 // ======================================================================== // 显示头像页 showAvatarPage: function() { nx.gui.setActive( this.nodPages, "avatars", true ); nx.gui.setActive( this.nodPages, "frames", false ); nx.gui.setActive( this.nodPages, "chat", false ); nx.gui.setActive( this.nodPages, "badges", false ); // 不需要重建 if( nx.dt.arrNEmpty( this.avatars ) ) { let index = ( this.idxAvatar >= 0 ) ? this.idxAvatar : 0; this.onAvatarFocusChanged( { index: index, mdata: this.avatars[ index ] } ); return; } // 重建 RoleController.getInstance().send10325( ( _ret, _data ) => { if( !_ret ) { nx.tbox( _data ); return; } // 列表重置 this.rebuildAvatarList( _data.face_list ); } ); }, // 列表重置 rebuildAvatarList: function( _list ) { let haves = {}; for( let i in _list ) { let tmp = _list[ i ]; if( tmp && nx.dt.numPositive( tmp.face_id, false ) ) { haves[ tmp.face_id ] = { id: tmp.face_id, have: true }; } } this.avatars = []; // 数组化 let libs = game.configs.looks_data.data_head_data; for( let id in libs ) { let tmp = libs[ id ]; let info = { id: tmp.id, name: tmp.name, icon: 0, date: 0, type: MenuTags.Avatar, lock: !haves[ id ], lock_tip: tmp.tips, unlock_tip: tmp.unlock_tips, }; let cfg = gitemdata( id ); info.icon = cfg ? cfg.icon : 0; this.avatars.push( info ); } // 排序 let curId = this.role.face_id; this.avatars.sort( ( _a, _b ) => { if( _a.lock != _b.lock ) { return _a.lock ? 1 : -1; } if( _a.id == curId ) { return -1; } if( _b.id == curId ) { return 1; } return _a.id - _b.id; } ); // 列表重建 this.lstAvatars.rebuild( this.avatars ); // 选中当前使用 this.idxAvatar = -1; for( let i = 0; i < this.avatars.length; ++i ) { let tmp = this.avatars[ i ]; if( tmp && tmp.id == curId ) { this.idxAvatar = i; let chds = this.lstAvatars.bindSCV.content.children; let node = chds[ i ]; if( node && node.svItem ) { node.svItem.setUsed( true ); } break; } } // 默认选中 let index = ( this.idxAvatar >= 0 ) ? this.idxAvatar : 0; this.onAvatarFocusChanged( { index: index, mdata: this.avatars[ index ] } ); }, // 选中切换 onAvatarFocusChanged: function( _item ) { // 空 if( !_item || !_item.mdata ) { return; } // 聚焦 this.lstAvatars.cleanFocus(); this.lstAvatars.addFocus( _item.index ); // 预览设置 this.setPreview( _item.mdata.icon ); this.setCurrent( _item.mdata ); }, // 更变头像 onTouchChangeAvatar: function() { let id = this.current.id; RoleController.getInstance().send10327( id, ( _ret, _data ) => { if( !_ret ) { nx.tbox( _data ); return; } let chds = this.lstAvatars.bindSCV.content.children; for( let i in chds ) { let node = chds[ i ]; if( node && node.svItem ) { node.svItem.setUsed( node.svItem.mdata.id == id ); } } nx.gui.setLocked( this.nodPreview, "ops/confirm", true ); } ); }, // ======================================================================== // 头像框选择相关 // ======================================================================== // 显示头像框页 showFramePage: function() { nx.gui.setActive( this.nodPages, "avatars", false ); nx.gui.setActive( this.nodPages, "frames", true ); nx.gui.setActive( this.nodPages, "chat", false ); nx.gui.setActive( this.nodPages, "badges", false ); nx.gui.setActive( this.nodPages, "frames/use", false ); nx.gui.setActive( this.nodPages, "frames/active", false ); RoleController.getInstance().send21500( ( _ret, _data ) => { if( !_ret ) { nx.tbox( _data ); return; } // 列表重置 this.rebuildFrameList( _data.avatar_frame ); } ); }, // 列表重置 rebuildFrameList: function( _list ) { let BC = BackpackController.getInstance(); let BM = BC.getModel(); let have = _list ? _list : []; let cur = this.role.avatar_base_id; let libs = game.configs.avatar_data.data_avatar; let records = {}; for( let k in have ) { let tmp = have[ k ]; if( tmp && nx.dt.numPositive( tmp.base_id, false ) ) { records[ tmp.base_id ] = tmp; } } this.frames = []; for( let k in libs ) { let tmp = libs[ k ]; if( !tmp || tmp.is_show != 1 ) { continue; } // 当前选中 let id = tmp.base_id; let item = { id: id, name: tmp.name, icon: tmp.item_icon_id, date: 0, type: MenuTags.HeadFrame, lock: true, attrs: tmp.attr || [], lock_tip: tmp.lock_tip || "Locked", unlock_tip: tmp.desc, canActive: false, }; if( records[ id ] ) { item.lock = false; if( nx.dt.numPositive( records[ id ].expire_time, false ) ) { item.date = records[ id ].expire_time; } } else if( tmp.loss && tmp.loss[ 0 ] ) { let num = BM.getBackPackItemNumByBid( tmp.loss[ 0 ][ 0 ] ); if( num >= tmp.loss[ 0 ][ 1 ] ) { item.canActive = true; item.lock = false; } } this.frames.push( item ); } // 排序 this.frames.sort( ( _a, _b ) => { if( _a.lock != _b.lock ) { return _a.lock ? 1 : -1; } if( _a.canActive != _b.canActive ) { return _a.canActive ? -1 : 1; } return _a.id - _b.id; } ); // 列表重建 this.lstFrames.rebuild( this.frames ); // 使用中 this.idxFrame = -1; for( let i = 0; i < this.frames.length; ++i ) { let tmp = this.frames[ i ]; if( tmp && tmp.id == cur ) { this.idxFrame = i; let chds = this.lstFrames.bindSCV.content.children; let node = chds[ i ]; if( node && node.svItem ) { node.svItem.setUsed( true ); } break; } } // 默认选中 let index = ( this.idxFrame >= 0 ) ? this.idxFrame : 0; this.onFrameFocusChanged( { index: index, mdata: this.frames[ index ] } ); }, // 选中切换 onFrameFocusChanged: function( _item ) { // 空 if( !_item || !_item.mdata ) { return; } // 聚焦 this.lstFrames.cleanFocus(); this.lstFrames.addFocus( _item.index ); // 预览设置 this.setPreview( -1, _item.mdata.id ); this.setCurrent( _item.mdata ); }, // 更变头像框 onTouchChangeFrame: function() { let id = this.current.id; RoleController.getInstance().send21501( id, ( _ret, _data ) => { if( !_ret ) { nx.tbox( _data ); return; } let chds = this.lstFrames.bindSCV.content.children; for( let i in chds ) { let node = chds[ i ]; if( node && node.svItem ) { node.svItem.setUsed( node.svItem.mdata.id == id ); } } nx.gui.setLocked( this.nodPreview, "ops/confirm", true ); } ); }, // ======================================================================== // 聊天泡泡选择相关 // ======================================================================== // 显示聊天泡泡页 showBubblePage: function() { nx.gui.setActive( this.nodPages, "avatars", false ); nx.gui.setActive( this.nodPages, "frames", false ); nx.gui.setActive( this.nodPages, "chat", true ); nx.gui.setActive( this.nodPages, "badges", false ); nx.gui.setActive( this.nodPages, "frames/use", false ); nx.gui.setActive( this.nodPages, "frames/active", false ); RoleController.getInstance().sender12700( ( _ret, _data ) => { if( !_ret ) { nx.tbox( _data ); return; } // 列表重置 this.rebuildBubbleList( _data.say_frame ); } ); }, // 列表重置 rebuildBubbleList: function( _list ) { let BC = BackpackController.getInstance(); let BM = BC.getModel(); let have = _list ? _list : []; let cur = this.role.bubble_bid; let libs = game.configs.say_data.data_say_frame; let records = {}; for( let k in have ) { let tmp = have[ k ]; if( tmp && nx.dt.numPositive( tmp.base_id, false ) ) { records[ tmp.base_id ] = tmp; } } this.bubbles = []; for( let key in libs ) { let tmp = libs[ key ]; if( !tmp ) { continue; } // 当前选中 let id = tmp.base_id; let item = { id: id, name: tmp.name, icon: id, date: 0, type: MenuTags.Bubble, lock: true, lock_tip: tmp.lock_tip || "Locked", unlock_tip: tmp.desc, canActive: false, }; if( records[ id ] ) { item.lock = false; if( nx.dt.numPositive( records[ id ].expire_time, false ) ) { item.date = records[ id ].expire_time; } } else if( tmp.loss && tmp.loss[ 0 ] ) { let num = BM.getBackPackItemNumByBid( tmp.loss[ 0 ][ 0 ] ); if( num >= tmp.loss[ 0 ][ 1 ] ) { item.canActive = true; item.lock = false; } } this.bubbles.push( item ); } // 排序 this.bubbles.sort( ( _a, _b ) => { if( _a.lock != _b.lock ) { return _a.lock ? 1 : -1; } if( _a.canActive != _b.canActive ) { return _a.canActive ? -1 : 1; } return _a.id - _b.id; } ); // 列表重建 this.lstBubbles.rebuild( this.bubbles ); // 使用中 this.idxBubble = -1; for( let i = 0; i < this.bubbles.length; ++i ) { let tmp = this.bubbles[ i ]; if( tmp && tmp.id == cur ) { this.idxBubble = i; let chds = this.lstBubbles.bindSCV.content.children; let node = chds[ i ]; if( node && node.svItem ) { node.svItem.setUsed( true ); } break; } } // 默认选中 let index = ( this.idxBubble >= 0 ) ? this.idxBubble : 0; this.onBubbleFocusChanged( { index: index, mdata: this.bubbles[ index ] } ); }, // 选中切换 onBubbleFocusChanged: function( _item ) { // 空 if( !_item || !_item.mdata ) { return; } // 聚焦 this.lstBubbles.cleanFocus(); this.lstBubbles.addFocus( _item.index ); // 预览设置 this.setPreview( -1, -1, _item.mdata.id ); this.setCurrent( _item.mdata ); }, // 更变聊天泡泡 onTouchChangeBubble: function() { let id = this.current.id; RoleController.getInstance().sender12701( id, ( _ret, _data ) => { if( !_ret ) { nx.tbox( _data ); return; } let chds = this.lstBubbles.bindSCV.content.children; for( let i in chds ) { let node = chds[ i ]; if( node && node.svItem ) { node.svItem.setUsed( node.svItem.mdata.id == id ); } } nx.gui.setLocked( this.nodPreview, "ops/confirm", true ); } ); }, // ======================================================================== // 徽章选择相关 // ======================================================================== // 显示徽章页 showBadgePage: function() { nx.gui.setActive( this.nodPages, "avatars", false ); nx.gui.setActive( this.nodPages, "frames", false ); nx.gui.setActive( this.nodPages, "chat", false ); nx.gui.setActive( this.nodPages, "badges", true ); // 不需要重建 if( nx.dt.arrNEmpty( this.badges ) ) { let index = ( this.idxBadge >= 0 ) ? this.idxBadge : 0; this.onBadgeFocusChanged( { index: index, mdata: this.badges[ index ] } ); return; } // 重建 RoleController.getInstance().send23300( ( _ret, _data ) => { if( !_ret ) { nx.tbox( _data ); return; } // 列表重置 this.rebuildBadgeList( _data.honor ); } ); }, // 列表重置 rebuildBadgeList: function( _list ) { let BC = BackpackController.getInstance(); let BM = BC.getModel(); let haves = {}; for( let i in _list ) { let tmp = _list[ i ]; if( tmp && nx.dt.numPositive( tmp.base_id, false ) ) { haves[ tmp.base_id ] = tmp; } } this.badges = []; // 数组化 let libs = game.configs.honor_data.data_title; for( let id in libs ) { let tmp = libs[ id ]; let info = { id: tmp.base_id, name: tmp.name, icon: tmp.res_id, sicon: tmp.item_icon_id, date: 0, type: MenuTags.Badge, lock: !haves[ id ], lock_tip: tmp.desc, unlock_tip: tmp.desc, attrs: tmp.attr, canActive: false, }; if( haves[id] ) { info.date = haves[id].expire_time; } else if( tmp.loss && tmp.loss[ 0 ] ) { let num = BM.getBackPackItemNumByBid( tmp.loss[ 0 ][ 0 ] ); if( num >= tmp.loss[ 0 ][ 1 ] ) { info.canActive = true; info.lock = false; } } this.badges.push( info ); } // 排序 let curId = this.role.title_id; this.badges.sort( ( _a, _b ) => { if( _a.lock != _b.lock ) { return _a.lock ? 1 : -1; } if( _a.id == curId ) { return -1; } if( _b.id == curId ) { return 1; } return _a.id - _b.id; } ); // 列表重建 this.lstBadges.rebuild( this.badges ); // 选中当前使用 this.idxBadge = -1; for( let i = 0; i < this.badges.length; ++i ) { let tmp = this.badges[ i ]; if( tmp && tmp.id == curId ) { this.idxBadge = i; let chds = this.lstBadges.bindSCV.content.children; let node = chds[ i ]; if( node && node.svItem ) { node.svItem.setUsed( true ); } break; } } // 默认选中 let index = ( this.idxBadge >= 0 ) ? this.idxBadge : 0; this.onBadgeFocusChanged( { index: index, mdata: this.badges[ index ] } ); }, // 选中切换 onBadgeFocusChanged: function( _item ) { // 空 if( !_item || !_item.mdata ) { return; } // 聚焦 this.lstBadges.cleanFocus(); this.lstBadges.addFocus( _item.index ); // 预览设置 this.setPreview( -1, -1, -1, _item.mdata.icon ); this.setCurrent( _item.mdata ); }, // 更变徽章 onTouchChangeBadge: function() { let id = this.current.id; RoleController.getInstance().send23301( id, ( _ret, _data ) => { if( !_ret ) { nx.tbox( _data ); return; } let chds = this.lstBadges.bindSCV.content.children; for( let i in chds ) { let node = chds[ i ]; if( node && node.svItem ) { node.svItem.setUsed( node.svItem.mdata.id == id ); } } nx.gui.setLocked( this.nodPreview, "ops/confirm", true ); } ); }, // ======================================================================== // 预览相关 // ======================================================================== // 初始化预览 initPreview: function() { let faceId = this.role.face_id; let frameId = this.role.avatar_base_id; let bubbleId = this.role.bubble_bid; let badgeId = this.role.title_id; this.setPreview( faceId, frameId, bubbleId, badgeId ); }, // 设置预览 setPreview: function( _avatar, _frame, _bubble, _badge ) { // 头像 if( nx.dt.numPositive( _avatar, false ) ) { nx.bridge.setAvatarByFaceId( this.nodPreview, "avatar/head", _avatar ); } // 头像框 if( nx.dt.numPositive( _frame, false ) ) { nx.bridge.setAvatarFrame( this.nodPreview, "avatar/frame", _frame ); } // 聊天框 if( nx.dt.numPositive( _bubble, false ) ) { nx.bridge.setChatBubble( this.nodPreview, "chat", _bubble ); } // 徽章 if( nx.dt.numGood( _badge ) ) { if( _badge <= 0 ) { nx.gui.setSpriteFrame( this.nodPreview, "badge", null ); } else { let path = cc.path.join( "resDB/honors", _badge ); nx.gui.setSpriteFrame( this.nodPreview, "badge", path ); } } }, // 设置当前操作项 setCurrent: function( _item ) { this.current = _item ? _item : null; // 置空 if( nx.dt.objEmpty( _item ) ) { nx.gui.setActive( this.nodPreview, "info", false ); nx.gui.setActive( this.nodPreview, "ops", false ); return; } // 标题 // let txt = _item.lock ? "UnlockCondition" : "BaseInfo"; let txt = _item.name || "BaseInfo"; let info = nx.gui.setActive( this.nodPreview, "info", true ); // 描述 let desc = _item.lock ? _item.lock_tip : _item.unlock_tip; let ops = nx.gui.setActive( this.nodPreview, "ops", true ); // 聊天框直设 // if( _item.type == MenuTags.Bubble ) { // txt = _item.name; // desc = _item.unlock_tip; // } nx.gui.setString( info, "head/txt", nx.text.getKey( txt ) ); nx.gui.setString( info, "desc", nx.text.getKey( desc ) ); // 加成 if( nx.dt.arrEmpty( _item.attrs ) ) { nx.gui.setString( info, "attr", nx.text.getKey( "NoPropBonus" ) ); } else { // 属性加成(显示两个) let txt = ""; for( let i = 0; i < _item.attrs.length; ++i ) { let attr = _item.attrs[i]; if( nx.dt.arrEmpty( attr ) ) { break; } let prop = nx.bridge.attrs.fmtAttribute( attr[0], attr[1] ); txt += nx.text.format( "PropValue", prop.name, prop.val ); if( i < ( _item.attrs.length -1 ) ) { txt += "\t\t"; } } nx.gui.setString( info, "attr", txt ); } // 有效期 let time = ""; if( !_item.lock ) { time = nx.text.getKey( "Permanent" ); if( _item.date > 0 ) { let tm = TimeTool.getYMD( _item.date ); time = nx.text.format( "ExpireDate", tm ); } } nx.gui.setString( this.nodPreview, "date", time ); // 操作 switch( _item.type ) { // 头像 case MenuTags.Avatar: { let curId = this.role.face_id; nx.gui.setActive( ops, "active", false ); nx.gui.setActive( ops, "confirm", true ); nx.gui.setLocked( ops, "confirm", _item.lock || ( _item.id == curId ) ); } break; // 头像框 case MenuTags.HeadFrame: { if( _item.canActive ) { nx.gui.setActive( ops, "active", true ); nx.gui.setActive( ops, "confirm", false ); } else { let curId = this.role.avatar_base_id; nx.gui.setActive( ops, "active", false ); nx.gui.setActive( ops, "confirm", true ); nx.gui.setLocked( ops, "confirm", _item.lock || ( _item.id == curId ) ); } } break; // 聊天框 case MenuTags.Bubble: { if( _item.canActive ) { nx.gui.setActive( ops, "active", true ); nx.gui.setActive( ops, "confirm", false ); } else { let curId = this.role.bubble_bid; nx.gui.setActive( ops, "active", false ); nx.gui.setActive( ops, "confirm", true ); nx.gui.setLocked( ops, "confirm", _item.lock || ( _item.id == curId ) ); } } break; // 徽章框 case MenuTags.Badge: { if( _item.canActive ) { nx.gui.setActive( ops, "active", true ); nx.gui.setActive( ops, "confirm", false ); } else { let curId = this.role.title_id; nx.gui.setActive( ops, "active", false ); nx.gui.setActive( ops, "confirm", true ); nx.gui.setLocked( ops, "confirm", _item.lock || ( _item.id == curId ) ); } } break; default: break; } }, // 点击激活 onTouchActive: function() { if( !this.current ) { return; } // 头像框激活 if( this.current.type == MenuTags.HeadFrame ) { let id = this.current.id; RoleController.getInstance().send21503( id, ( _ret, _data ) => { if( !_ret ) { nx.tbox( _data ); return; } let chds = this.lstAvatars.bindSCV.content.children; for( let i in chds ) { let node = chds[ i ]; if( node && node.svItem && node.svItem.mdata.id == id ) { node.svItem.setActive( false ); break; } } this.current.canActive = false; this.current.lock = false; let arr = _data.avatar_frame || []; for( let i = 0; i < arr.length; ++i ) { if( arr[ i ].base_id == this.current.id ) { this.current.date = arr[ i ].expire_time; break; } } this.setCurrent( this.current ); } ); return; } // 聊天泡泡激活 if( this.current.type == MenuTags.Bubble ) { let id = this.current.id; RoleController.getInstance().sender12703( id, ( _ret, _data ) => { if( !_ret ) { nx.tbox( _data ); return; } let chds = this.lstBubbles.bindSCV.content.children; for( let i in chds ) { let node = chds[ i ]; if( node && node.svItem && node.svItem.mdata.id == id ) { node.svItem.setActive( false ); break; } } this.current.canActive = false; this.current.lock = false; // let arr = _data.avatar_frame || []; // for( let i = 0; i < arr.length; ++i ) { // if( arr[ i ].base_id == this.current.id ) { // this.current.date = arr[ i ].expire_time; // break; // } // } this.setCurrent( this.current ); } ); return; } // 徽章泡泡激活 if( this.current.type == MenuTags.Badge ) { let id = this.current.id; RoleController.getInstance().send23303( id, ( _ret, _data ) => { if( !_ret ) { nx.tbox( _data ); return; } let chds = this.lstBadges.bindSCV.content.children; for( let i in chds ) { let node = chds[ i ]; if( node && node.svItem && node.svItem.mdata.id == id ) { node.svItem.setActive( false ); break; } } this.current.canActive = false; this.current.lock = false; this.setCurrent( this.current ); } ); return; } }, // 点击使用 onTouchUse: function() { if( !this.current ) { return; } // 区别处理 switch( this.current.type ) { case MenuTags.Avatar: { this.onTouchChangeAvatar(); } break; case MenuTags.HeadFrame: { this.onTouchChangeFrame(); } break; case MenuTags.Bubble: { this.onTouchChangeBubble(); } break; case MenuTags.Badge: { this.onTouchChangeBadge(); } break; default: break; } }, } );