/****************************************************************** * * 家园主界面 * ******************************************************************/ const BridgeWindow = require( "bridge.window" ); const HomeMod = require( "home.mod" ); const TipController = require( "tips_controller" ); const KernelController = require( "halidom_controller" ); const MallConst = require( "mall_const" ); cc.Class( { extends: BridgeWindow, properties: { nodScene: { default: null, type: cc.Node }, nodUI: { default: null, type: cc.Node }, }, // 显示 onEnable: function() { // 视图绑定 nx.bridge.vbind( this, [ [ "HomeTheme", this.onHomeThemeChanged.bind( this ) ], [ "HomeEditing", this.onEditModeChanged.bind( this ) ] ] ); // 亲密度请求 HomeMod.getInstance().reqIntimacyData( ( _ret, _data ) => { if( !_ret ) { nx.tbox( _data ); return; } } ); }, // 关闭 onDisable: function() { // 视图监听解除 nx.bridge.vunbind( this ); }, // 重载:参数打开 onOpenConfigs: function( _params ) { this.themeId = 0; this.target = null; if( nx.dt.objNEmpty( _params ) && nx.dt.strNEmpty( _params.srv_id ) && nx.dt.numPositive( _params.rid, false ) ) { this.target = { srv_id: _params.srv_id, rid: _params.rid }; }; // 自家刷新 const HM = HomeMod.getInstance(); const cb = function( _ret, _data ) { if( !_ret ) { nx.tbox( _data ); return; } }; if( nx.dt.objEmpty( this.target ) ) { HM.reqHomeData( cb ); } else { HM.reqVisitHome( this.target.srv_id, this.target.rid, cb ); } }, // 加载场景 onHomeThemeChanged: function( _id, _old, _init ) { if( this.themeId == _id || _id <= 0 ) { return; } const DATA = game.configs.homeland_data.data_theme_data[ _id ]; if( nx.dt.objEmpty( DATA ) ) { nx.warn( "当前家园主题无效:", _id ); this.themeId = 0; return; } this.themeId = _id; nx.gui.setActive( this.nodScene, "preview", true ); let path = cc.path.join( "resDB/home/themes", DATA.theme_res_id, "mini" ); nx.gui.setSpriteFrame( this.nodScene, "preview/bg", path ); const root = nx.gui.find( this.nodScene, "scene/view/content" ); path = cc.path.join( "prefab/home/themes", DATA.theme_res_id ); nx.res.loadPrefab( path, ( _err, _fab ) => { if( _err ) { nx.tbox( _err.message || "" ); return; } root.removeAllChildren(); // nx.bridge.NodeChidrenDestroy(root); let node = cc.instantiate( _fab ); node.parent = root; nx.gui.setActive( this.nodScene, "preview", false ); } ); }, // 编辑模式改变 onEditModeChanged: function( _open ) { nx.gui.setActive( this, "ui", !_open ); nx.gui.setActive( this, "theme", _open ); }, // 修改名字 onTouchModifyHomeName: function() { let HC = HomeMod.getInstance(); let TC = TipController.getInstance(); let modify = function( _name ) { HC.reqChangeName( _name, ( _ret, _data ) => { if( !_ret ) { nx.tbox( _data ); return; } } ); }; TC.showInputString( { tip: "HomeRenameTip", limit: [ 4, 20 ], cb: ( _box, _str ) => { _box.close(); modify( _str ); } } ); }, // 浏览开启 onTouchTogReview: function() { let review = nx.bridge.vget( "HomeViewing" ); nx.bridge.vset( "HomeViewing", !review ); }, // 编辑开启 onTouchThemeEdit: function() { HomeMod.getInstance().togHomeEdit(); }, // 同步中心 onTouchAsynCenter: function() { nx.bridge.createPanel( "WndSyncCenter" ); }, // 基础核心 onTouchBaseKernel: function() { let KC = KernelController.getInstance(); KC.openHomeKernelWind( true ); }, // 寝室 onTouchBedRoom: function() { nx.bridge.createPanel( "WndBedroom" ); }, // 访问足迹 onTouchFootmark: function() { nx.bridge.createPanel( "WndHomeFootmark" ); }, // 好友 onTouchFriend: function() { nx.bridge.createPanel( "WndFriend", { type: 1 } ); }, // 家园商店 onTouchShop: function() { nx.bridge.jumper.jump2Window( 132, [ MallConst.MallType.SummonShop, MallConst.MallType.ThemeShop ] ); }, // 离开家园 onTouchLeave: function() { // 直接离开 let mine = nx.bridge.vget( "HomeMine" ); if( mine ) { this.close(); return; } // 返回自己家园 const HM = HomeMod.getInstance(); HM.reqHomeData(); }, } );