Files
fc/dev/project/assets/Scripts/mod/acts/summonLimit/cmp/cmp.act.summon.limit.js
T

291 lines
8.2 KiB
JavaScript
Raw Normal View History

2026-05-23 22:10:14 +08:00
/******************************************************************
*
* 限定招募
*
******************************************************************/
const ActPage = require( "act.page.base" );
const NxSpine = require( "nx.fx.spine" );
const ItemLayout = require( "cmp.item.layout" );
const BridgeItemBinder = require( "bridge.binder.item.icon.count" );
const TipsController = require( "tips_controller" );
const FID = require( "bridge.function.ids" );
cc.Class( {
extends: ActPage,
properties: {
nodOps: { default: null, type: cc.Node },
spRole: { default: null, type: NxSpine },
spMini: { default: null, type: NxSpine },
nodInfo: { default: null, type: cc.Node },
nodDate: { default: null, type: cc.Node },
nodLogo: { default: null, type: cc.Node },
nodCoin: { default: null, type: BridgeItemBinder },
nodScore: { default: null, type: BridgeItemBinder },
nodRewards: { default: null, type: ItemLayout },
},
// 初始化
build: function( _data ) {
this._super( _data );
// 置空
if( !this.mod || nx.dt.objEmpty( this.data ) ) {
this.setEmpty();
return;
}
// 配置查询
this.configs = this.mod.queryConfigs();
if( !this.configs ) {
nx.error( `$SummonLimit:配置缺失! ${ this.data.camp_id }` );
this.setEmpty();
return;
}
// 基本信息
this.freshBasic();
},
// 显示
onEnable: function() {
// console.log( "Show:" + this.data.camp_id );
// 刷新
if( this.mod ) {
this.mod.reqBaseData( ( _ret, _data ) => {
if( _ret ) {
this.freshDate( _data.remain_sec );
this.freshRewards( _data.item_effect_list );
this.freshOps();
}
} );
}
},
// 关闭
onDisable: function() {
// console.log( "Hide:" + this.data.camp_id );
},
// 置空
setEmpty: function() {
nx.gui.setActive( this, "right", false );
},
// 基本信息
freshBasic: function() {
// 置空
if( !this.mod || !this.configs || nx.dt.objEmpty( this.data ) ) {
this.setEmpty();
return;
}
// 背景刷新
let bg = cc.path.join( "resDB/bigs", this.configs.bg || "bg005" );
nx.gui.setSpriteFrame( this, "bg", bg );
nx.gui.setActive( this, "right", true );
// 标签刷新
let tags = cc.path.join( "locals/{lang}/images/limitrecruit", this.configs.effect );
nx.gui.setSpriteFrame( this.nodInfo, "desc", nx.res.fmtPath( tags ) );
// Logo刷新
let logo = cc.path.join( "locals/{lang}/images/limitrecruit", this.configs.title );
nx.gui.setSpriteFrame( this.nodLogo, "", nx.res.fmtPath( logo ) );
// 道具绑定
this.nodCoin.setID( this.configs.prop_id, () => {
this.freshOps();
} );
// 积分绑定
this.nodScore.setID( this.configs.point_id );
// 角色信息刷新
this.freshPartner( this.configs.partner_id );
// 红点绑定
let tip1 = nx.gui.getComponent( this.nodOps, "once/tip", "nx.vb.visible" );
if( tip1 ) {
tip1.setTarget( nx.mTip, this.mod.getTipKey( "once" ) );
}
let tip2 = nx.gui.getComponent( this.nodOps, "ten/tip", "nx.vb.visible" );
if( tip2 ) {
tip2.setTarget( nx.mTip, this.mod.getTipKey( "ten" ) );
}
},
// 刷新角色
freshPartner: function( _bid ) {
let dat = game.configs.partner_data.data_partner_base[ _bid ];
let scfgs = gdata( "partner_data", "data_partner_star", `${ _bid }_${ dat.init_star }` );
if( nx.dt.objEmpty( scfgs ) ) {
nx.error( "刷新角色失败,无效伙伴:", _bid );
return;
}
// 名字
nx.gui.setString( this.nodInfo, "base/name", nx.text.getKey( dat.name ) );
// 品质
let path = cc.path.join( "coms/images", "mk_partner_qa" + dat.quality );
nx.gui.setSpriteFrame( this.nodInfo, "qa", path );
// 阵营
path = cc.path.join( "prefab/partner/ui/camp" + dat.camp_type );
nx.gui.setSpriteFrame( this.nodInfo, "base/camp", path );
// 星级
path = cc.path.join( "coms/images/star" + dat.init_star );
nx.gui.setSpriteFrame( this.nodInfo, "stars", path );
// 角色动画
path = PathTool.getSpinePath( scfgs.res_id, "show", false );
this.spRole.load( path, ( _e ) => {
if( !_e ) {
this.spRole.action( "action1", true );
} else {
this.spRole.stop();
}
} );
// MINI动画
path = PathTool.getSpinePath( scfgs.res_id, scfgs.res_id, false );
this.spMini.load( path, ( _e ) => {
if( !_e ) {
this.spMini.action( "stand2", true );
} else {
this.spMini.stop();
}
} );
// 技能
let sknode = nx.gui.find( this.nodInfo, "skills" );
for( let i = 0; i < sknode.children.length; ++i ) {
// 技能数组[0]为普攻,直接忽略,最多4个技能
let item = sknode.children[ i ];
let sifo = scfgs.skills[ i + 1 ];
if( !sifo ) {
item.active = false;
continue;
}
item.active = true;
let cmp = nx.gui.getComponent( item, "", "cmp.skill.base" );
if( cmp ) {
cmp.setData( sifo[ 1 ] );
}
}
},
// 刷新活动日期
freshDate: function( _secs ) {
let time = nx.bridge.time.toNeedSeconds( _secs );
nx.gui.setString( this.nodDate, "txt", time );
},
// 刷新奖励
freshRewards: function( _list ) {
let rewards = [];
if( nx.dt.arrNEmpty( _list ) ) {
for( let i = 0; i < _list.length; ++i ) {
rewards.push( [ _list[ i ].bid, 1 ] );
}
}
this.nodRewards.rebuild( rewards );
},
// 变化信息
freshOps: function() {
// 置空
if( !this.mod || !this.configs || nx.dt.objEmpty( this.data ) ) {
return;
}
// 按钮设置
let autoOp = function( _node, _draw ) {
let tinfo = gitemdata( _draw[ 0 ] );
if( !tinfo ) {
nx.error( `$SummonLimit:道具无效! ${ _draw[ 0 ] }` );
return;
}
nx.bridge.setIcon( _node, "btn/list/icon", tinfo.icon );
nx.gui.setString( _node, "btn/list/num", _draw[ 1 ] );
}
// 操作刷新
autoOp( nx.gui.find( this.nodOps, "once" ), this.configs.draw_one[ 0 ] );
autoOp( nx.gui.find( this.nodOps, "ten" ), this.configs.draw_ten[ 0 ] );
},
// 点击单抽
onTouchOnce: function() {
if( !this.configs || !this.mod ) {
return;
}
this.mod.reqRaffle( this.configs.group_id, true, ( _ret, _msg, _code ) => {
// 道具不足
if( !_ret && _code == 101 ) {
nx.tbox( _msg );
this.onTouchCoin();
}
} );
},
// 点击十抽
onTouchTen: function() {
if( !this.configs || !this.mod ) {
return;
}
this.mod.reqRaffle( this.configs.group_id, false, ( _ret, _msg, _code ) => {
// 道具不足
if( !_ret && _code == 101 ) {
nx.tbox( _msg );
this.onTouchCoin();
}
} );
},
// 点击规则
onTouchRule: function() {
let rule = this.mod ? this.mod.queryRule() : "";
if( nx.dt.strNEmpty( rule ) ) {
const TC = TipsController.getInstance();
TC.showTextPanel( "tip", rule );
}
},
// 点击道具
onTouchCoin: function() {
if( this.actRoot && this.configs ) {
this.actRoot.jumpToMenu( this.configs.jump );
}
},
// 点击兑换
onTouchShop: function() {
nx.bridge.jumper.jump2Window( FID.PartnerExChange );
},
} );