Files
fc/dev/project/assets/Scripts/mod/mainui/cmp/cmp.main.ui.js
T
2026-05-23 22:10:14 +08:00

488 lines
14 KiB
JavaScript

/******************************************************************
* Copyright(C) 2019 - 2020 Nx Studio
*
* 主界面
*
*
******************************************************************/
const BridgeWindow = require( "bridge.window" );
const RoleController = require( "role_controller" );
const DramaConst = require( "battle_drama_event" );
const PartnerBody = require( "cmp.partner.body.show" );
const BattleController = require( "battle_controller" );
const BattleConst = require( "battle_const" );
const ArenaConst = require( "arena_const" );
const { CKeys } = require( "bridge.conditions" );
const FID = require( "bridge.function.ids" );
const PLOT_DELAY = 0.02;
const SEC_DELAY = 2.5;
cc.Class( {
extends: BridgeWindow,
properties: {
imgDesktop: { default: null, type: cc.Node },
cmpBody: { default: null, type: PartnerBody },
nodPush: { default: null, type: cc.Node },
},
// 显示
onLoad: function() {
// 角色属性监听
this.role = RoleController.getInstance().getRoleVo();
this.handler = this.role.bind( EventId.UPDATE_ROLE_ATTRIBUTE, ( _key, _val ) => {
this.onRoleAttrChanged( _key, _val );
} );
// 关卡更新
this.bindGEvent( DramaConst.BattleDrama_Top_Update_Data, () => {
this.onDramaLevelChanged();
} );
this.racewnd = null;
this.isracing = false;
// 视图监听
this.vbind( [
[ "PPushGifts", this.onFreshGifts.bind( this ) ],
[ "clerkShowId", this.onActiveClerkChanged.bind( this ) ],
[ "matVersion", this.onMatchVersion.bind( this ) ],
[ "DailyPop", this.onShowPop.bind( this ) ],
[ "CChampionPro", this.onShowTips.bind( this ) ],
[ "CampfightTop", this.showCampTopThree.bind( this )]
] );
// 桌面更新
this.updateDesktop( this.role.theme_id );
// 其他常驻界面
this.createPanels();
// 调试接口
this.dbgOpen();
// 全局
nx.bridge.mainui = this;
// 战斗单例
this.battleC = BattleController.getInstance();
if( nx.storage.get( "battleArena" ) != "null" ){
nx.bridge.jumper.jump2Window( nx.storage.get( "battleArena" ) );
}
// console.log( nx. );
},
// 销毁
onDestroy: function() {
// 战斗单例
this.battleC = null;
// 角色属性监听解除
if( this.role && this.handler ) {
this.role.unbind( this.handler );
this.handler = null;
this.role = null;
}
// 监听事件释放
this.unbindGEvents();
// 战斗实例销毁
if( this.battleC ) {
BattleController.instance.onDestroy();
delete BattleController.instance;
BattleController.instance = null;
this.battleC = null;
}
this.racewnd = null;
},
// 帧更新
update: function( dt ) {
if( this.battleC ) {
this.battleC.update( dt );
}
},
// 主场景显隐
show: function( _show, _force ) {
// let cur = ( this.node.opacity > 0 );
// if( cur == _show ) {
// return;
// }
//
// this.node.opacity = _show ? 255 : 0;
// 激活剧情辅助器
if( _show ) {
this.tryPlot();
this.onDramaLevelChanged();
}
},
// 剧情触发
tryPlot: function( _key = "main" ) {
let cmp = nx.gui.getComponent( this, "pres/plot", "cmp.main.ui.plot" );
if( !cmp ) {
return;
}
// 战斗剧情触发 -- 挂机界面
if( _key == "drama" ) {
this.scheduleOnce( () => {
cmp.backDramaHook();
}, PLOT_DELAY );
return;
}
// 战斗剧情触发 -- 编队界面
if( _key == "drama_team" ) {
this.scheduleOnce( () => {
cmp.backDramaTeamHook();
}, PLOT_DELAY );
return;
}
// 战斗剧情触发 -- 编队界面
if( _key == "drama_team" ) {
this.scheduleOnce( () => {
cmp.backDramaTeamHook();
}, PLOT_DELAY );
return;
}
// 主界面触发
if( this.node.opacity > 0 ) {
this.scheduleOnce( () => {
cmp.backMainScene();
}, PLOT_DELAY );
return;
}
},
// 设置桌面
updateDesktop: function( _id ) {
let id = _id || 1;
let path = cc.path.join( "resDB/desktop", "" + id );
nx.gui.setSpriteFrame( this.imgDesktop, "", path );
},
// 角色属性改变
onRoleAttrChanged: function( _key, _val ) {
// 设置桌面
if( _key == "theme_id" ) {
this.updateDesktop( _val );
return;
}
if( !nx.dt.arrMember( CKeys, _key ) ) {
return;
}
// 功能解锁检查
nx.bridge.mods.checkUnLock();
nx.bridge.acts.freshForeshow();
// 解锁条件更新
let cmps = game.node.getComponentsInChildren( "bridge.condition.locker" );
if( nx.dt.arrNEmpty( cmps ) ) {
for( let i in cmps ) {
cmps[ i ].updateLocker( _key, _val );
}
}
},
// 关卡更新
onDramaLevelChanged: function() {
// 功能解锁检查
nx.bridge.mods.checkUnLock();
// 解锁条件更新
let cmps = game.node.getComponentsInChildren( "bridge.condition.locker" );
if( nx.dt.arrNEmpty( cmps ) ) {
for( let i in cmps ) {
cmps[ i ].updateLocker( "max_dun_id" );
}
}
nx.gui.setActive( this, "ui/kfyg", RoleController.getInstance().dealOpenServer() );
},
onTouchTrainCamp: function() {
this.battleC.requestOpenBattleRelevanceWindow( BattleConst.Fight_Type.Training_Camp );
},
// 其他常驻界面
createPanels: function() {
nx.bridge.createPanel( "WndHoverdLayer" );
nx.bridge.createPanel( "WndSummonAnimation" );
},
onShowPop: function( _pop ){
if( _pop == 1 ){
let showDaily = nx.bridge.vget( "DailyLimit" );
if( showDaily ){
switch( showDaily ){
case 1 : {
nx.bridge.jumper.jump2Window( FID.ActFirst );
nx.bridge.vset( "DailyLimit", null );
}; break;
case 2 : {
nx.bridge.jumper.jump2Window( FID.ActMySteryGift );
nx.bridge.vset( "DailyLimit", null );
}; break;
case 3 : {
nx.bridge.jumper.jump2Window( FID.ActOptional );
nx.bridge.vset( "DailyLimit", null );
};
}
}
}
},
showCampTopThree : function( _data ){
this.unscheduleAllCallbacks();
let show = nx.storage.get( "WndCampfightFinal" );
if( !_data || ( show && show == 1 ) ){
return;
}
if( !nx.bridge.getBridgeWindow( "WndCampfightFinal" ) ){
this.scheduleOnce( ()=>{
nx.bridge.createPanel( "WndCampfightFinal", { show : 100 } );
nx.bridge.vset( "CampfightTop", null );
}, SEC_DELAY );
}
},
onShowTips: function( _data ){
if( !_data || this.racewnd || this.isracing ){
return;
}
this.unscheduleAllCallbacks();
// console.log( "當前的跨服冠軍賽數據相關" + JSON.stringify( _data ) );
let self = this;
let data = _data;
if( data.showlist ){
let crosscc = nx.storage.get( "CChampionPro" );
if( !crosscc || ( crosscc && crosscc == 0 ) ){
this.scheduleOnce( ()=>{
nx.bridge.createPanel( "WndCChampionFinal", { show : 99 } );
nx.bridge.vset( "CChampionPro", null );
}, SEC_DELAY + 2 );
this.racewnd = data;
}
}else{
if ( data.round_status == ArenaConst.champion_round_status.guess ) { // 每次競猜都要彈提示
let info = {
type : BattleConst.Fight_Type.CrossChampion,
raceinfo : 3,
cb : ()=>{
nx.bridge.jumper.jump2Window( FID.CrossChampion );
self.isracing = true;
}
}
if( !this.racewnd ){
nx.bridge.createPanel( "WndPvpRaceTip", info );
this.racewnd = data;
}
// nx.bridge.vset( "CChampionPro", null );
}else{
if (data.step != ArenaConst.champion_step.unopened && data.step_status == ArenaConst.champion_step_status.opened
&& data.round == 1 && data.round_status == 0 ) {
let info = {
type : BattleConst.Fight_Type.CrossChampion,
raceinfo : 1,
cb : ()=>{
nx.bridge.jumper.jump2Window( FID.CrossChampion );
self.isracing = true;
}
}
if( !this.racewnd ){
// nx.bridge.createPanel( "WndPvpRaceTip", info );
nx.bridge.createPanel( "WndPvpRaceTip", info );
// nx.bridge.vset( "CChampionPro", null );
this.racewnd = data;
}
}
}
}
// nx.bridge.vset( "DailyLimit", null );
},
// ========================================================================
// 秘书相关
// ========================================================================
// 点击切换秘书
onTouchSwap: function() {
// 未解锁
let lst = nx.bridge.vget( "clerkList" );
if( nx.dt.arrEmpty( lst ) ) {
nx.tbox( "NeedUnlock" );
return;
}
// 只有一个
if( lst.length == 1 ) {
nx.bridge.createPanel( "WndPersonalClerk" );
return;
}
// 切换
nx.bridge.clerks.reqActiveShow();
},
// 当前秘书改变
onActiveClerkChanged: function( _id ) {
// 空
if( !this.cmpBody || nx.dt.strEmpty( _id ) ) {
if( this.cmpBody )
this.cmpBody.setEmpty();
return;
}
let arr = _id.split( "_" );
let info = nx.bridge.partner.parseShowInfo( ...arr );
if( nx.dt.objNEmpty( info ) ) {
this.cmpBody.setModel( info.sp_show, info.voice, info.phonetic_text || "", "main" );
}
},
// ========================================================================
// 个推相关
// ========================================================================
// 个人推送
onFreshGifts: function( _list ) {
if( !this.nodPush ||
this.nodPush.childrenCount > 0 ||
nx.dt.arrEmpty( _list ) ) {
return;
}
let path = cc.path.join( "prefab/push/fab_personal_push_entry" );
nx.res.loadPrefab( path, ( _err, _data ) => {
if( _err ) {
return;
}
let node = cc.instantiate( _data );
node.parent = this.nodPush;
node.position = cc.Vec2.ZERO;
} );
},
// ========================================================================
// 版本验证
// ========================================================================
onMatchVersion: function( _ver ) {
if( nx.dt.strEmpty( _ver ) ) {
return;
}
// 验证热更版本是否与服务器匹配
let cur = nx.frame.vget( "HotVersion" );
// let v1 = _ver.split( '.' );
// let v2 = cur.split( '.' );
// if( v1[ 0 ] != v2[ 0 ] || v1[ 1 ] != v2[ 1 ] ) {
if( cur != _ver ) {
nx.mbox( "检测到新版本", [ 'confirm' ], ( _key, _box ) => {
_box.close();
nx.restart();
} );
}
},
// ========================================================================
// 调试相关
// ========================================================================
// 调试接口
dbgOpen: function() {
if( !CC_DEBUG ) {
return;
}
nx.bridge = nx.bridge || {};
// 接口装载
let inst = function( _key, _fs ) {
let Mod = require( _fs );
let Ins = Mod.getInstance();
nx.bridge[ _key ] = Ins;
if( Ins && nx.dt.fnGood( Ins.getModel ) ) {
nx.bridge[ `${ _key }_mod` ] = Ins.getModel();
}
};
inst( "bag", "backpack_controller" ); // 背包
inst( "hero", "hero_controller" ); // 伙伴
inst( "role", "role_controller" ); // 自己
inst( "arena", "arena_controller" ); // 竞技
inst( "mu", "mainui_controller" ); // 奖励测试
inst( "sum", "summon.mod" ); // 召唤测试
inst( "bat", "battle_controller" ); // 战斗
inst( "task", "task_controller" ); // 任务
inst( "dispatch", "dispatch.mod" ); // 任务派遣
inst( "guild", "guild_controller" ); // 工会
inst( "drama", "battle_drama_controller" ); // 剧情
inst( "pvp", "pvp.mod" ); // STEP-UP
inst( "crystal", "summon.crystal.mod" ); // STEP-UP
inst( "home", "home.mod" ); // Home
inst( "vip", "vip_controller" ); // VIP
nx.bridge.timetool = require( "timetool" );
},
} );