Files
fc/dev/project/assets/Scripts/mod/setting/cmps/cmp.setting.wnd.js
T

366 lines
10 KiB
JavaScript
Raw Normal View History

2026-05-23 22:10:14 +08:00
/******************************************************************
*
* 设置界面
*
******************************************************************/
const BridgeWindow = require( "bridge.window" );
const FFSDK = require( "ff_sdk" );
const RoleController = require( "role_controller" );
const LoginMod = require( "login.mod" );
cc.Class( {
extends: BridgeWindow,
properties: {
nodMusic: { default: null, type: cc.Node },
nodEffect: { default: null, type: cc.Node },
nodVoice: { default: null, type: cc.Node },
nodServer: { default: null, type: cc.Node },
nodOps : { default: null, type: cc.Node },
},
onLoad: function(){
let canshow = FFSDK.getInstance().mJsonSDKInfo ? FFSDK.getInstance().mJsonSDKInfo.channelName == "erolabs" : false;
nx.gui.setActive( this.nodOps, "erolabs", canshow );
},
// 显示
onEnable: function() {
// 视图绑定
nx.frame.vbind( this, [
[ "BgmVolume", this.onMusicVolumeChanged.bind( this ) ],
[ "SfxVolume", this.onEffectVolumeChanged.bind( this ) ],
[ "VocVolume", this.onVoiceVolumeChanged.bind( this ) ],
] );
// 服务器名
let info = nx.bridge.vget( "curServer" );
let name = info ? info.srv_name : "";
if( nx.dt.strNEmpty( name ) ) {
this.nodServer.active = true;
let sname = nx.text.format( "Zoom", info.zone_id ) + nx.text.getKey( name );
nx.gui.setString( this.nodServer, "txt", sname );
} else {
this.nodServer.active = false;
}
},
// 关闭
onDisable: function() {
// 视图监听解除
nx.frame.vunbind( this );
},
// ======================================================
// 音乐控制
// ======================================================
// 单条刷新
freshVolume: function( _item, _vol ) {
let vol = parseFloat( _vol ) || 0;
let open = ( vol >= 0.01 );
nx.gui.setActive( _item, "togger/on", open );
nx.gui.setActive( _item, "togger/off", !open );
nx.gui.setString( _item, "percent", Math.floor( vol * 100 ) + "%" );
this.freshSlider( _item, vol );
},
// 滑动条模拟
freshSlider: function( _item, _vol ) {
let slider = nx.gui.getComponent( _item, "slider", cc.Slider );
let probar = nx.gui.getComponent( _item, "slider/progress", cc.ProgressBar );
if( slider && probar ) {
slider.progress = _vol;
probar.progress = _vol;
}
},
// 开关切换
onMusicTog: function() {
let vol = nx.frame.vget( "BgmVolume" );
let opening = ( vol > 0.01 ) ? true : false;
nx.audio.setBGMVolume( opening ? 0 : 0.5 );
},
// 音量滑动
onMusicSliderChanged: function( _slider ) {
this.freshSlider( this.nodMusic, _slider.progress );
let vol = nx.frame.vget( "BgmVolume" );
let cur = Math.floor( _slider.progress * 100 ) / 100;
if( vol != cur ) {
nx.audio.setBGMVolume( cur );
}
},
// 音量改变
onMusicVolumeChanged: function( _vol ) {
this.freshVolume( this.nodMusic, _vol );
},
// ======================================================
// 音效控制
// ======================================================
// 开关切换
onEffectTog: function() {
let vol = nx.frame.vget( "SfxVolume" );
let opening = ( vol > 0.01 ) ? true : false;
nx.audio.setSFXVolume( opening ? 0 : 0.5 );
},
// 音量滑动
onEffectSliderChanged: function( _slider ) {
this.freshSlider( this.nodEffect, _slider.progress );
let vol = nx.frame.vget( "SfxVolume" );
let cur = Math.floor( _slider.progress * 100 ) / 100;
if( vol != cur ) {
nx.audio.setSFXVolume( cur );
}
},
// 音量改变
onEffectVolumeChanged: function( _vol ) {
this.freshVolume( this.nodEffect, _vol );
},
// ======================================================
// 语音控制
// ======================================================
// 开关切换
onVoiceTog: function() {
let vol = nx.frame.vget( "VocVolume" );
let opening = ( vol > 0.01 ) ? true : false;
nx.audio.setVoiceVolume( opening ? 0 : 0.5 );
},
// 音量滑动
onVoiceSliderChanged: function( _slider ) {
this.freshSlider( this.nodVoice, _slider.progress );
let vol = nx.frame.vget( "VocVolume" );
let cur = Math.floor( _slider.progress * 100 ) / 100;
if( vol != cur ) {
nx.audio.setVoiceVolume( cur );
}
},
// 音量改变
onVoiceVolumeChanged: function( _vol ) {
this.freshVolume( this.nodVoice, _vol );
},
// ======================================================
// 其他
// ======================================================
// 点击切换账号
onTouchTogAccount: function() {
let self = this;
if( FFSDK.getInstance().mJsonSDKInfo && FFSDK.getInstance().mJsonSDKInfo.channelName == "erolabs" ){
if( nx.dt.strEmpty( FFSDK.getInstance().accountinfo.data.user_info.account ) ){
nx.mbox( "BingAccountTip", [ 'no', 'yes' ], ( _key, _box )=>{
_box.close();
if( _key == 'yes' ){
LoginMod.getInstance().reqSDKLogout( ()=>{
FFSDK.getInstance().autoLogin()
} );
}else{
}
} )
}else{
nx.mbox( "AskTogAccount", [ 'no', 'yes' ], ( _key, _box )=>{
_box.close();
if( _key == 'yes' ){
LoginMod.getInstance().reqSDKLogout( ()=>{
FFSDK.getInstance().autoLogin()
} );
}else{
console.log( "switchAccount" + JSON.stringify( this.accountinfo ) );
}
} )
}
}else{
nx.mbox( "AskTogAccount", [ "no", "yes" ], ( _key, _box ) => {
_box.close();
if( _key == "yes" ) {
game.enterLogin( true );
};
} );
}
},
// 点击切换区服
onTouchTogServer: function() {
nx.mbox( "AskTogServer", [ "no", "yes" ], ( _key, _box ) => {
_box.close();
if( _key == "yes" ) {
game.enterLogin();
};
} );
},
// 点击BUG反馈
onTouchBugBack: function() {
let url = nx.bridge.vget( "gmUrl" );
if( FFSDK.getInstance().isEnableSDK() &&
nx.dt.strNEmpty( url ) ) {
FFSDK.getInstance().openUrl( url );
return;
}
nx.bridge.createPanel( "WndBugReport" );
},
// 点击玩家社区
onTouchBBS: function() {
let url = nx.bridge.vget( "socialUrl" );
if( FFSDK.getInstance().isEnableSDK() &&
nx.dt.strNEmpty( url ) ) {
FFSDK.getInstance().openUrl( url );
}
},
// 点击退出游戏
onTouchQuitGame: function() {
nx.mbox( "AskQuitGame", [ "no", "yes" ], ( _key, _box ) => {
_box.close();
if( _key == "yes" ) {
nx.appQuit();
};
} );
},
// 点击綁定賬號
onTouchBindAccount: function() {
nx.bridge.createPanel( "WndBind", {
desc : nx.text.getKey( "SetBind" ),
cb : ()=>{
FFSDK.getInstance().guestBind( ( _account )=>{
// console.log( "當前的account----sssss" + JSON.stringify( _account ) );
// console.log( "當前的account----wwwwwww" + _account.data.user_info.user_id );
RoleController.getInstance().reqGetBindReward( _account.data.user_info.account, ( _ret, _data )=>{
// console.log( "當前的account----" + _account.data.user_info.account );
if( !_ret ){
nx.tbox( _data );
return;
}
if( _data.code == 1 ){
// 重新登錄 ---
nx.mTip.openTip( "setting.bind", false );
nx.mTip.openTip( "unbind", false );
nx.storage.set( "bindreward" + _account.data.user_info.account, "get" );
game.enterLogin( true );
}
} );
} );
}
} )
},
// 点击 聯係客服
onTouchCCT: function() {
let url = nx.bridge.vget( "contackUrl" );
if( FFSDK.getInstance().isEnableSDK() &&
nx.dt.strNEmpty( url ) ) {
FFSDK.getInstance().openUrl( url );
}
},
// 点击 群組
onTouchTGroup: function() {
let url = nx.bridge.vget( "tgroupUrl" );
if( FFSDK.getInstance().isEnableSDK() &&
nx.dt.strNEmpty( url ) ) {
FFSDK.getInstance().openUrl( url );
}
},
// 点击 免費ECoin
onTouchFree: function() {
let url = nx.bridge.vget( "ecoinUrl" );
if( FFSDK.getInstance().isEnableSDK() &&
nx.dt.strNEmpty( url ) ) {
FFSDK.getInstance().openUrl( url );
}
},
// 点击 免費ECoin
onTouchGetBindReward: function() {
nx.bridge.createPanel( "WndBind", {
desc : nx.text.getKey( "Get" ),
cb : ()=>{
let account = FFSDK.getInstance().accountinfo ? FFSDK.getInstance().accountinfo.data.user_info.account : "";
// let role = RoleController.getInstance().getRoleVo();
RoleController.getInstance().reqGetBindReward( "", ( _ret, _data )=>{
if( !_ret ){
nx.tbox( _data );
return;
}
if( _data.code == 1 ){
nx.mTip.openTip( "setting.bind", false );
nx.storage.set( "bindreward" + account, "get" );
}
} );
}
} )
},
} );