Files
fc/dev/project/assets/Scripts/mod/guild/base/cmps/cmp.guild.donate.wnd.js
T

253 lines
7.0 KiB
JavaScript
Raw Normal View History

2026-05-23 22:10:14 +08:00
/******************************************************************
*
* 联盟捐献
*
******************************************************************/
const BridgeWindow = require( "bridge.window" );
const TipController = require( "tips_controller" );
const GuildController = require( "guild_controller" );
const GuildEvent = require( "guild_event" );
cc.Class( {
extends: BridgeWindow,
properties: {
nodChoices: { default: null, type: cc.Node },
nodToday: { default: null, type: cc.Node },
nodProgress: { default: null, type: cc.Node },
},
// 显示
onEnable: function() {
this.ctrl = GuildController.getInstance();
this.model = this.ctrl.getModel();
// 提示关闭
nx.mTip.openTip( "guild.donate.tip", false );
this.freshBase();
this.bindGEvent( GuildEvent.UpdateMyInfoEvent, this.onUpdateGuildInfo.bind( this ) );
this.bindGEvent( GuildEvent.UpdateDonateInfo, this.onUpdateDonateInfo.bind( this ) );
this.bindGEvent( GuildEvent.UpdateDonateBoxStatus, this.onUpdateRewardInfo.bind( this ) );
this.ctrl.reqDonateData( ( _ret, _data ) => {
if( !_ret ) {
nx.tbox( _data );
this.scheduleOnce( () => {
this.close();
}, 0.01 );
return;
}
} );
},
// 关闭
onDisable: function() {
if( nx.bridge.prompt ) {
nx.bridge.prompt.delPrompt(19);
}
this.unbindGEvents();
},
// 基础显示
freshBase: function() {
// 贡献选项
let choices = game.configs.guild_data.data_donate;
for( let i in choices ) {
let info = choices[ i ];
let node = nx.gui.find( this.nodChoices, "t" + i );
node.cinfo = info;
nx.gui.setString( node, "tip", nx.text.getKey( info.desc ) );
nx.gui.hideAllChildren( node, "ops" );
// 消耗
let need = nx.gui.find( node, "ops/donate/need" );
if( need ) {
let loss = info.loss[ 0 ];
nx.bridge.setIconS( need, "ico", loss[ 0 ] );
nx.gui.setString( need, "txt", loss[ 1 ] );
}
// 奖励
let reward = nx.gui.find( node, "reward" );
for( let t = 0; t < 2; ++t ) {
let ifo = info.gain[ t ];
let tmp = nx.gui.find( reward, "t" + t );
if( nx.dt.arrEmpty( ifo ) ) {
tmp.active = false;
continue;
}
tmp.active = true;
nx.bridge.setIconS( tmp, "icon", ifo[ 0 ] );
nx.gui.setString( tmp, "txt", ifo[ 1 ] );
}
}
// 今日贡献
nx.gui.setString( this.nodToday, "txt", 0 );
// 贡献奖励
let boxes = game.configs.guild_data.data_donate_box;
for( let id in boxes ) {
let box = boxes[ id ];
let node = nx.gui.find( this.nodProgress, "r" + id );
node.boxinfo = box;
nx.gui.setString( node, "txt", box.box_val );
nx.gui.setActive( node, "box/off", true );
nx.gui.setActive( node, "box/on", false );
nx.gui.setActive( node, "box/got", false );
}
// 等级更新
this.onUpdateGuildInfo();
},
// 联盟信息更新
onUpdateGuildInfo: function() {
// 当前等级提示
let levels = game.configs.guild_data.data_guild_lev;
if( !levels ) {
return;
}
let gifo = this.model.getMyGuildInfo();
let txt = nx.text.format( "GuidDonateMaxLevel", gifo.lev );
if( gifo.lev < game.configs.guild_data.data_guild_lev_length ) {
let clv = levels[ gifo.lev ];
txt = nx.text.format( "GuidDonateNextLevel", gifo.lev, nx.text.getKey( clv.desc ) );
}
nx.gui.setString( this, "panel/tip", txt );
},
// 捐献信息更新
onUpdateDonateInfo: function() {
// 捐献情况
let chds = this.nodChoices.children;
for( let i = 0; i < chds.length; ++i ) {
let node = chds[ i ];
let ifo = this.model.checkDonateStatus( node.cinfo.id );
// 已捐献
let key = "donate";
if( ifo[ 0 ] ) {
key = ( ifo[ 1 ] == true ) ? "done" : "out";
}
let ops = nx.gui.find( node, "ops" );
ops.children.forEach( t => {
t.active = ( t.name == key );
} );
}
// 捐献奖励更新
this.onUpdateRewardInfo();
},
// 捐献奖励更新
onUpdateRewardInfo: function() {
// 贡献进度
let exp = this.model.donate_exp;
let max = game.configs.guild_data.data_const.day_exp_max.val;
let bar = nx.gui.getComponent( this.nodProgress, "", cc.ProgressBar );
if( bar ) {
bar.progress = exp / max;
}
nx.gui.setString( this.nodToday, "txt", exp );
// 进度奖励
let boxes = game.configs.guild_data.data_donate_box;
for( let id in boxes ) {
let box = boxes[ id ];
let node = nx.gui.find( this.nodProgress, "r" + id );
if( exp < box.box_val ) {
nx.gui.setActive( node, "box/off", true );
nx.gui.setActive( node, "box/on", false );
nx.gui.setActive( node, "box/got", false );
}
else {
let got = this.model.donate_rewards[ id ];
nx.gui.setActive( node, "box/off", got );
nx.gui.setActive( node, "box/on", !got );
nx.gui.setActive( node, "box/got", got );
}
}
},
// 捐献
onTouchDonate: function( _key ) {
let type = parseInt( _key );
this.ctrl.reqDonate( type, ( _ret, _data ) => {
if( !_ret ) {
nx.tbox( _data );
return;
}
} );
},
// 领奖
onTouchReward: function( _key ) {
let id = parseInt( _key );
let box = game.configs.guild_data.data_donate_box[ id ];
if( nx.dt.objEmpty( box ) ) {
return;
}
let node = nx.gui.find( this.nodProgress, "r" + id );
let can = nx.gui.isActive( node, "box/on" );
if( !can ) {
nx.bridge.createPanel( "PopItemsPreview", {
tip: "PreviewReward",
items: box.rewards
} );
return;
}
// 领奖
this.ctrl.requestDonateBoxRewards( id, ( _ret, _data ) => {
if( !_ret ) {
nx.tbox( _data );
return;
}
} );
},
// 说明
onTouchHelp: function() {
let TC = TipController.getInstance();
if( TC ) {
let txt = game.configs.guild_data.data_const.game_rule1;
TC.showTextPanel( "tip", txt.desc );
}
},
} );