Files
2026-05-23 22:10:14 +08:00

258 lines
7.1 KiB
JavaScript

/******************************************************************
*
* 闺房剧情分支图
*
******************************************************************/
const BridgeWindow = require( "bridge.window" );
const HomeModel = require( "home.mod" );
cc.Class( {
extends: BridgeWindow,
properties: {
nodHead: { default: null, type: cc.Node },
nodList: { default: null, type: cc.Node },
nodTemplates: { default: null, type: cc.Node },
},
// 重载:参数打开
onOpenConfigs: function( _params ) {
// 档案基本信息
this.baseinfo = game.configs.favor_data.data_interface[ _params.profile_id ];
this.data = game.configs.favor_data.data_content[ _params.profile_id ];
// 分支信息
if( nx.dt.objEmpty( this.data ) ||
nx.dt.objEmpty( this.baseinfo ) ) {
nx.error( "无效的闺蜜档案:", _params.profile_id );
this.scheduleOnce( () => {
this.close();
}, 0.01 );
return;
}
// 档案名字
nx.gui.setString( this.nodHead, "txt", nx.text.getKey( this.baseinfo.name ) );
this.partner_id = _params.partner_id;
this.profile_id = _params.profile_id;
this.cmpStory = _params.story;
// 数据统计
this.dataStatistics( _params.talks || [], _params.results || [] );
// 列表重构
this.rebuildList();
nx.doc = this;
},
// 数据统计
dataStatistics: function( _talks, _results ) {
// 统计已开启条目
let talkList = {};
for( let i in _talks ) {
let t = _talks[ i ];
if( t ) {
talkList[ t.talk_id ] = 1;
}
}
// 统计奖励
let giftList = {};
for( let i in _results ) {
let t = _results[ i ];
if( t ) {
giftList[ t.talk_id ] = t.is_get_reward;
}
}
// 统计对话
let talks = [];
for( let id in this.data ) {
let t = this.data[ id ];
if( t && t.rank > 0 ) {
talks.push( id );
}
}
// 判空
let empty = nx.dt.arrEmpty( talks );
nx.gui.setActive( this, "empty", empty );
nx.gui.setActive( this, "graphic", !empty );
if( empty ) {
return;
}
// 统计
this.items = [];
for( let idx = 0; idx < talks.length; ++idx ) {
// 一级
let tid = talks[ idx ];
let temp = this.data[ tid ];
let info = {
id: tid,
show: !!talkList[ tid ],
name: temp.section_desc,
txt: temp.content[ 0 ],
ops: [],
};
// 二级
for( let i = 0; i < temp.next_content_id.length; ++i ) {
let sid = temp.next_content_id[ i ];
let stmp = this.data[ sid ];
let sifo = {
id: sid,
icon: stmp.icon,
txt: stmp.content[ 0 ],
done: !!talkList[ sid ],
end: null,
};
// 最终奖励
if( sifo.done &&
stmp.next_content_id.length == 1 ) {
let eid = stmp.next_content_id[ 0 ];
let etp = this.data[ eid ];
if( etp && etp.rank < 1 && nx.dt.arrEmpty( etp.next_content_id ) ) {
sifo.end = {
id: eid,
txt: etp.content[ 0 ],
status: giftList[ eid ],
};
}
}
info.ops.push( sifo );
}
this.items.push( info );
}
console.log( this.items );
},
// 列表重构
rebuildList: function() {
let self = this;
// 三级条目
let create3 = function( _parent, _info ) {
let T = nx.gui.find( self.nodTemplates, "T3" );
let node = cc.instantiate( T );
node.parent = _parent;
node.info = _info;
let txt = nx.text.getKey( _info.txt );
nx.gui.setString( node, "info/txt", nx.dt.strCut( txt, 50 ) );
nx.gui.setActive( node, "info/gift/get", _info.status == 0 );
nx.gui.setActive( node, "info/gift/got", _info.status == 1 );
nx.gui.setActive( node, "info/gift/yet", _info.status != 0 && _info.status != 1 );
};
// 二级条目
let create2 = function( _parent, _info ) {
let T = nx.gui.find( self.nodTemplates, "T2" );
let node = cc.instantiate( T );
node.parent = _parent;
node.info = _info;
let txt = nx.text.getKey( _info.txt );
nx.gui.setString( node, "info/txt", nx.dt.strCut( txt, 60 ) );
let path = cc.path.join( "prefab/home/bedroom/ui", "icon" + _info.icon );
nx.gui.setSpriteFrame( node, "info/icon", path );
nx.gui.setActive( node, "info/cbox/on", _info.done );
if( _info.end ) {
create3( node, _info.end );
}
return node;
};
// 一级条目
let createItem = function( _parent, _info ) {
let T = nx.gui.find( self.nodTemplates, "T1" );
let node = cc.instantiate( T );
node.parent = _parent;
node.info = _info;
nx.gui.setString( node, "info/btn/txt", nx.text.getKey( _info.name ) );
let txt = nx.text.getKey( _info.txt );
nx.gui.setString( node, "info/txt", nx.dt.strCut( txt, 70 ) );
for( let i = 0; i < _info.ops.length; ++i ) {
create2( node, _info.ops[i] );
}
return node;
};
this.nodList.removeAllChildren();
for( let i = 0; i < this.items.length; ++i ) {
let info = this.items[i];
if( info && info.show ) {
createItem( this.nodList, info );
}
}
},
// 点击对话
onTouchDialog: function( _item ) {
let node = _item ? _item.parent.parent : null;
let ifo = node ? node.info : null;
if( !this.cmpStory || !ifo ) {
return;
}
this.cmpStory.onTouchAutoCancel();
this.cmpStory.resetTalk( ifo.id );
this.close();
},
// 点击领奖
onTouchReward: function( _item ) {
let node = _item ? _item.parent.parent.parent : null;
let ifo = node ? node.info : null;
if( !ifo ) {
return;
}
let home = HomeModel.getInstance();
home.reqGetIntimacyReward( this.profile_id, ifo.id, ( _ret, _data ) => {
if( !_ret ) {
nx.tbox( _data );
return;
}
node.status = 1;
nx.gui.setActive( node, "info/gift/get", false );
nx.gui.setActive( node, "info/gift/got", true );
});
},
} );