/****************************************************************** * * 闺房亲密度场景 * ******************************************************************/ const BridgeWindow = require( "bridge.window" ); const BackPackController = require( "backpack_controller" ); const HomeModel = require( "home.mod" ); // const HomeHMod = require( "home.h.mod" ); const FxSpine = require( "nx.fx.spine" ); const MAX_USE = 5; const ACTIONS = [ { action: "action1", voice: 0 }, { action: "action2", voice: 1 }, { action: "action3", voice: 2 }, ]; cc.Class( { extends: BridgeWindow, properties: { spGirl: { default: null, type: FxSpine }, nodGirls: { default: null, type: cc.ScrollView }, nodLoading: { default: null, type: cc.Node }, nodUI: { default: null, type: cc.Node }, nodRole: { default: null, type: cc.Node }, nodParts: { default: null, type: cc.Node }, nodArchives: { default: null, type: cc.Node }, nodGifts: { default: null, type: cc.Node }, nodRelation: { default: null, type: cc.Node }, nodOps: { default: null, type: cc.Node }, nodEffect: { default: null, type: cc.Node }, nodAddition: { default: null, type: cc.Node }, }, // 显示 onEnable: function() { // 置空 this.setEmpty(); // 初始化道具格子 this.initItemList(); // 背包监听 this.bindGEvent( EventId.ADD_GOODS, this.onBagItemUpdate.bind( this ) ); this.bindGEvent( EventId.DELETE_GOODS, this.onBagItemUpdate.bind( this ) ); this.bindGEvent( EventId.MODIFY_GOODS_NUM, this.onBagItemUpdate.bind( this ) ); // 闺蜜列表重建 this.rebuildMenu(); // 视图绑定 nx.bridge.vbind( this, [ ["HomeGirlShow", this.onCurrentGirl.bind( this )] ] ); }, // 关闭 onDisable: function() { // 视图监听解除 nx.bridge.vunbind( this ); // 背包监听解除 this.unbindGEvents(); // 展示清除 nx.bridge.vset( "HomeGirlShow", 0 ); }, // 置空 setEmpty: function() { this.current = null; // this.nodRole.active = false; this.nodLoading.active = false; this.nodUI.active = false; }, // 闺蜜列表重建 rebuildMenu: function() { // 伙伴列表 let arr = []; let focusId = 0; let girls = nx.bridge.vget( "HomeGirls" ); for( let id in game.configs.favor_data.data_partner ) { let pt = game.configs.favor_data.data_partner[id]; let ifo = nx.dt.objClone( pt ); ifo.have = nx.dt.arrMember( girls, null, ( _t ) => { return _t && ( _t.partner_id == id ); } ); arr.push( ifo ); // 默认聚焦记录 if( focusId == 0 && ifo.have ) { focusId = parseInt( id ); } } // 排序 arr.sort( ( _a, _b ) => { if( _a.have != _b.have ) { return _a.have ? -1 : 1; } return _a.sort - _b.sort; } ); // 列表重建 let root = this.nodGirls.content; let build = function( _index, _node, _partner ) { _node.gindex = _index; _node.partner_id = _partner.partner_id; // let partner = game.configs.partner_data.data_partner_base[_partner.partner_id]; // 锁定 if( !_partner.have ) { nx.gui.setActive( _node, "normal", false ); nx.gui.setActive( _node, "lock", true ); // nx.gui.setString( _node, "lock/txt", partner.name ); let path = cc.path.join( "prefab/home/bedroom/roles", _partner.res, "icon2_" + nx.getLocLanguage() ); nx.gui.setSpriteFrame( _node, "lock/img", path ); return; } // 解锁 nx.gui.setActive( _node, "lock", false ); nx.gui.setActive( _node, "normal", true ); nx.gui.setActive( _node, "normal/focus", false ); // nx.gui.setString( _node, "normal/txt", partner.name ); let path = cc.path.join( "prefab/home/bedroom/roles", _partner.res, "icon_" + nx.getLocLanguage() ); nx.gui.setSpriteFrame( _node, "normal/img", path ); }; nx.gui.gocChildren( root, "", arr.length, root.children[0] ); for( let i = 0; i < arr.length; ++i ) { let node = root.children[i]; if( node ) { build( i, node, arr[i] ); } } // 延迟选中 this.scheduleOnce( () => { let pid = nx.bridge.vget( "HomeGirlShow" ); if( !nx.dt.numPositive( pid, false ) && focusId > 0 ) { nx.bridge.vset( "HomeGirlShow", focusId ); } }, 0.01 ); }, // ======================================================================== // 闺蜜相关 // ======================================================================== // 载入新闺蜜 loadGirl: function( _pid, _cb ) { // 角色模型动画 let infos = game.configs.favor_data.data_partner[_pid]; if( nx.dt.objEmpty( infos ) ) { return; } this.cmpRole = null; this.nodLoading.active = true; // this.nodRole.active = true; // this.nodRole.removeAllChildren(); // 载入新预制 let path = cc.path.join( "prefab/home/bedroom/roles", infos.res, "role" ); nx.res.loadPrefab( path, ( _err, _data ) => { this.nodLoading.active = false; if( _err ) { return; } let node = cc.instantiate( _data ); node.parent = this.nodRole; this.cmpRole = nx.gui.getComponent( node, "", "cmp.bedroom.girl.show" ); this.cmpRole.bindTouch( this.onTouchGirl.bind( this ) ); nx.dt.fnInvoke( _cb ); } ); }, // 闺蜜选中 onCurrentGirl: function( _pid, _old ) { // 选择切换 let chds = this.nodGirls.content.children; for( let i = 0; i < chds.length; ++i ) { let node = chds[i]; nx.gui.setActive( node, "normal/focus", node.partner_id == _pid ); } // 新角色 let partner = HomeModel.getInstance().queryGirl( _pid ); if( !partner ) { this.setEmpty(); return; } // 动画判断 let pid = this.current ? this.current.partner_id : 0; if( pid == _pid ) { this.doEffect( this.current, partner ); } // 角色切换 this.current = partner; // 信息刷新 let self = this; let showUI = function( _init = false ) { self.nodUI.active = true; self.updateIntimacy( _init ); self.updateArchives( _init ); self.updateActions( _init ); self.onBagItemUpdate(); }; // 新角色载入 if( pid != this.current.partner_id ) { this.nodUI.active = false; // this.loadGirl( this.current.partner_id, () => { this.rebuildItems(); // this.freshHEntry(); showUI( true ); // } ); } else { showUI( false ); } }, // 闺蜜切换 onTouchTogRole: function( _item ) { let pid = _item ? _item.parent.partner_id : -1; if( !nx.dt.numPositive( pid, false ) ) { return; } if( !this.current || this.current.partner_id != pid ) { nx.bridge.vset( "HomeGirlShow", pid ); } }, // 点击闺蜜 onTouchGirl: function( _part ) { console.log( "TOUCH:", _part ); }, // ======================================================================== // 亲密度相关 // ======================================================================== // 刷新亲密度 updateIntimacy: function( _init ) { // 无效 let DATA = game.configs.favor_data.data_intimacy_lev; if( nx.dt.objEmpty( this.current ) || nx.dt.objEmpty( DATA ) ) { return; } let exp = this.current.intimacy_num; let lev = this.current.intimacy_lev; let cur = DATA[lev]; let next = DATA[lev + 1]; // 亲密度 nx.gui.setString( this.nodRelation, "level/txt", lev ); let prog = nx.gui.getComponent( this.nodRelation, "prog", cc.ProgressBar ); if( cur && prog ) { if( !next ) { prog.progress = 1; nx.gui.setString( prog, "txt", "" ); } else { prog.progress = exp / next.exp; nx.gui.setString( prog, "txt", exp + "/" + next.exp ); } } // 满级 if( !next ) { nx.gui.setString( this.nodAddition, "to/txt", lev ); nx.gui.setActive( this.nodAddition, "from", false ); nx.gui.setActive( this.nodAddition, "top", true ); nx.gui.setString( this.nodAddition, "next", nx.text.getKey( "好感加成已满" ) ); nx.gui.setString( this.nodAddition, "atk/from", nx.text.getKey( "满加成" ) ); nx.gui.setString( this.nodAddition, "atk/to", cur.attr[0][1] ); nx.gui.setString( this.nodAddition, "def/from", nx.text.getKey( "满加成" ) ); nx.gui.setString( this.nodAddition, "def/to", cur.attr[1][1] ); nx.gui.setString( this.nodAddition, "hp/from", nx.text.getKey( "满加成" ) ); nx.gui.setString( this.nodAddition, "hp/to", cur.attr[2][1] ); } else { nx.gui.setString( this.nodAddition, "from/txt", lev ); nx.gui.setString( this.nodAddition, "to/txt", lev + 1 ); nx.gui.setActive( this.nodAddition, "from", true ); nx.gui.setActive( this.nodAddition, "top", false ); let tip = nx.text.format( "好感加成解锁", next.exp - exp ); nx.gui.setString( this.nodAddition, "next", tip ); nx.gui.setString( this.nodAddition, "atk/from", ( cur.attr.length > 0 ) ? cur.attr[0][1] : 0 ); nx.gui.setString( this.nodAddition, "atk/to", next.attr[0][1] ); nx.gui.setString( this.nodAddition, "def/from", ( cur.attr.length > 0 ) ? cur.attr[1][1] : 0 ); nx.gui.setString( this.nodAddition, "def/to", next.attr[1][1] ); nx.gui.setString( this.nodAddition, "hp/from", ( cur.attr.length > 0 ) ? cur.attr[2][1] : 0 ); nx.gui.setString( this.nodAddition, "hp/to", next.attr[2][1] ); } }, // ======================================================================== // 档案相关 // ======================================================================== // 刷新档案 updateArchives: function() { // 无效 let DATA = game.configs.favor_data.data_intimacy_lev; if( nx.dt.objEmpty( this.current ) || nx.dt.objEmpty( DATA ) ) { return; } let num = 1; let lev = this.current.intimacy_lev; for( let i = 0; i < lev; ++i ) { let ifo = DATA[i]; if( ifo.type == 1 ) { ++num; } } let list = nx.gui.find( this.nodArchives, "list" ); if( list ) { for( let i = 0; i < list.children.length; ++i ) { let item = list.children[i]; let lock = ( i >= num ); nx.gui.setActive( item, "on", !lock ); nx.gui.setActive( item, "off", lock ); } } }, // 点击档案 onTouchArchive: function( _key ) { if( !this.current ) { return; } let HC = HomeModel.getInstance(); let pid = this.current.partner_id + "_" + _key; HC.reqStoryData( pid, ( _ret, _data ) => { if( !_ret ) { nx.tbox( _data ); return; } nx.bridge.createPanel( "WndBedroomStory", { partner_id: this.current.partner_id, profile_id: pid, step: _data.step, } ) } ); }, // ======================================================================== // 动作相关 // ======================================================================== // 刷新动作 updateActions: function( _init ) { // 无效 let DATA = game.configs.favor_data.data_intimacy_lev; if( nx.dt.objEmpty( this.current ) || nx.dt.objEmpty( DATA ) ) { return; } let num = 0; let lev = this.current.intimacy_lev; for( let i = 0; i <= lev; ++i ) { if( DATA[i].type == 2 ) { ++num; } } for( let i = 0; i < this.nodParts.children.length; ++i ) { let item = this.nodParts.children[i]; let lock = ( i >= num ); nx.gui.setActive( item, "lock", lock ); nx.gui.setActive( item, "on", !lock ); nx.gui.setActive( item, "off", false ); } // 换人了 if( !nx.dt.numGood( this.actionIdx ) || ( this.actionIdx >= num ) ) { this.actionIdx = 0; } this.onTogActionTag( this.actionIdx, _init ); }, // 切换动作 onTogActionTag: function( _index, _force ) { let index = parseInt( _index ) || 0; for( let i = 0; i < this.nodParts.children.length; ++i ) { let item = this.nodParts.children[i]; nx.gui.setActive( item, "on", i == index ); nx.gui.setActive( item, "off", i != index ); } if( this.actionIdx == index && !_force ) { return; } this.actionIdx = index; let open = nx.bridge.vget( "HOpened" ); let key = open ? "data_actions_h" : "data_actions"; let DATA = game.configs.favor_data[key]; if( nx.dt.objNEmpty( DATA ) && nx.dt.objNEmpty( this.current ) ) { let temp = DATA[this.current.partner_id][`${index}`]; if( temp ) { this.spGirl.play( temp.path, temp.name, null, true ); } return; } }, // 点击锁定动作 onTouchLockTag: function( _index ) { nx.tbox( "好感度不足" ); }, // ======================================================================== // 道具相关 // ======================================================================== // 初始化道具格子 initItemList: function() { let adds = game.configs.favor_data.data_const.itemrate_data.val; let chds = this.nodGifts.children; for( let i = 0; i < chds.length; ++i ) { let item = chds[i]; nx.gui.setString( item, "point/num", "+" + adds[i] ); } }, // 重构道具列表 rebuildItems: function() { let pid = this.current ? this.current.partner_id : 0; let DATA = game.configs.favor_data.data_partner[pid]; if( nx.dt.objEmpty( DATA ) ) { nx.gui.setActive( this.nodOps, "", false ); return; } let chds = this.nodGifts.children; for( let i = 0; i < chds.length; ++i ) { let node = chds[i]; node.cfgs = gitemdata( DATA.item[i] ); if( nx.dt.objEmpty( node.cfgs ) ) { node.active = false; } else { node.active = true; nx.bridge.setIcon( node, "icon", node.cfgs.icon ); nx.gui.setString( node, "name", nx.text.getKey( node.cfgs.name ) ); } } this.selectGift( 0 ); }, // 礼物选中 selectGift: function( _index ) { let item = null; let chds = this.nodGifts.children; for( let i = 0; i < chds.length; ++i ) { let node = chds[i]; nx.gui.setActive( node, "focus", _index == i ); if( _index == i ) { item = node; } } // 当前道具 this.item = item ? item.cfgs : null; if( nx.dt.objEmpty( this.item ) ) { nx.gui.setActive( this.nodOps, "", false ); return; } nx.gui.setActive( this.nodOps, "", true ); let model = BackPackController.getInstance().getModel(); let count = model.getBackPackItemNumByBid( this.item.id ); nx.gui.setActive( this.nodOps, "one", count > 0 ); nx.gui.setActive( this.nodOps, "all", count > 1 ); }, // 礼物切换 onTouchTogGift: function( _key ) { let index = parseInt( _key ) || 1; this.selectGift( index - 1 ); }, // 道具使用 onTouchUse: function( _key ) { if( !this.item ) { return; } let model = BackPackController.getInstance().getModel(); let count = model.getBackPackItemNumByBid( this.item.id ); let num = ( _key == "all" ) ? Math.min( count, MAX_USE ) : 1; HomeModel.getInstance().reqUseIntimacyItem( this.item.id, num, ( _ret, _data ) => { if( !_ret ) { // nx.tbox( _data ); return; } } ); }, // 道具更新 onBagItemUpdate: function( _bagCode, _itemList ) { if( !this.current ) { return; } let DATA = game.configs.favor_data.data_partner[this.current.partner_id] let chds = this.nodGifts.children; let items = DATA.item; let model = BackPackController.getInstance().getModel(); for( let i = 0; i < chds.length; ++i ) { let count = model.getBackPackItemNumByBid( items[i] ); nx.gui.setString( chds[i], "count/txt", count ); } }, // 动画效果 doEffect: function( _from, _to ) { if( !_from || !_to ) return; // 亲密度增加 let pt = _to.intimacy_num - _from.intimacy_num; if( nx.dt.numPositive( pt, false ) ) { let ach = nx.gui.find( this.nodEffect, "pt" ); let tmp = nx.gui.find( this.nodEffect, "ts/point" ); let node = cc.instantiate( tmp ); nx.gui.setString( node, "txt", "+" + pt ); node.parent = ach; node.position = cc.Vec2.ZERO; node.opacity = 0; cc.tween( node ) .to( 0.2, { opacity: 255, position: cc.v2( 0, 50 ) } ) .to( 0.6, { position: cc.v2( 0, 100 ), opacity: 100 } ) .removeSelf() .start(); nx.audio.playSFX( cc.path.join( "prefab/home/bedroom/bgm", "c1" ), false ); } // 等级改变 let lv = _to.intimacy_lev - _from.intimacy_lev; let DATA = game.configs.favor_data.data_intimacy_lev[_from.intimacy_lev]; if( DATA && nx.dt.numPositive( lv, false ) ) { let path = ""; switch( DATA.type ) { case 1: path = "imgDoc"; break; case 2: path = "imgAction"; break; case 3: path = "imgEvent"; break; default: break; } if( path == "" ) { return; } let ach = nx.gui.find( this.nodEffect, "new" ); let tmp = nx.gui.find( this.nodEffect, "ts/new" ); let node = cc.instantiate( tmp ); node.parent = ach; node.position = cc.Vec2.ZERO; nx.gui.setSpriteFrame( node, "img", cc.path.join( "prefab/home/bedroom/ui", path ) ); node.scale = 0.9; node.opacity = 0; cc.tween( node ) .to( 0.2, { scale: 1.1, opacity: 255 } ) .to( 0.1, { scale: 1 } ) .to( 0.6, { position: cc.v2( 0, 255 ), opacity: 100 } ) .removeSelf() .start(); nx.audio.playSFX( cc.path.join( "prefab/home/bedroom/bgm", "c2" ), false ); } }, // ======================================================================== // 其他 // ======================================================================== // 点击帮助 onTouchHelp: function() { nx.bridge.createPanel( "WndBedroomHelp" ); }, // 点击引导 onTouchGuide: function() { nx.bridge.createPanel( "WndPlotPictures", { id: "bedroom" } ); }, // 全屏切换 onTogExpand: function() { let vis = nx.gui.isActive( this, "ui" ); nx.gui.setActive( this, "ui", !vis ); nx.gui.setActive( this, "effect", !vis ); nx.gui.setActive( this, "girls", !vis ); nx.gui.setActive( this, "LT", !vis ); nx.gui.setActive( this, "expand/on", !vis ); nx.gui.setActive( this, "expand/off", vis ); }, // ======================================================================== // H // ======================================================================== // 刷新入口 freshHEntry: function() { // // 未开启 // let HH = HomeHMod.getInstance(); // let open = nx.bridge.vget( "HOpened" ); // if( !HH || !open ) { // nx.gui.setActive( this.nodUI, "hentry", false ); // return; // } // // 当前闺蜜 // let pid = nx.bridge.vget( "HomeGirlShow" ); // if( !HH.isMember( pid ) ) { // nx.gui.setActive( this.nodUI, "hentry", false ); // return; // } // nx.gui.setActive( this.nodUI, "hentry", true ); }, // 点击入口 onTouchHEntry: function() { // let open = nx.bridge.vget( "HOpened" ); // if( !open ) { // nx.warn( "$Bedroom:未开启!" ); // return; // } // let pid = nx.bridge.vget( "HomeGirlShow" ); // if( !nx.dt.numPositive( pid, false ) ) { // nx.warn( "$Bedroom:当前无效!" + pid + typeof ( pid ) ); // return; // } // nx.bridge.createPanel( "WndHomeH", { pid: pid } ); }, } );