Files
fc/dev/project/assets/Scripts/mod/partner/cmps/basic/cmp.partner.look.js
T
2026-05-23 22:10:14 +08:00

154 lines
4.2 KiB
JavaScript

const BridgeWindow = require( "bridge.window" );
const SliderProgress = require( "cmp.slider.prog.selector" );
const Slider = require( "cmp.slider.prog.selector" );
const NxSpine = require( "nx.fx.spine" );
cc.Class( {
extends: BridgeWindow,
properties: {
cmpCounter: {
default: null,
type: Slider,
},
nodResult: {
default: null,
type: NxSpine,
},
},
// 重载:参数打开
onOpenConfigs: function( _params ) {
this.max_scale = 1.5;
this.min_scale = 0.5;
this.nodResult.stop();
this.can = true;
// // 重建
this.setIcon( _params );
this.freshCount();
this.nodResult.node.on( cc.Node.EventType.TOUCH_MOVE, this._onTouchMove, this );
this.nodResult.node.on( cc.Node.EventType.TOUCH_END, this._onTouchEnd, this );
},
onPreClosed: function( _params ) {
this.nodResult.node.off( cc.Node.EventType.TOUCH_MOVE, this._onTouchMove, this );
this.nodResult.node.off( cc.Node.EventType.TOUCH_END, this._onTouchEnd, this );
},
setIcon: function( _partner ) {
let path = "";
let cfg = game.configs.partner_data.data_partner_base[ _partner.bid ].draw_res;
if( cfg ) {
// console.log( "当前的伙伴id" + cfg );
// 战斗迷你
path = PathTool.getSpinePath( cfg, "show", false );
this.nodResult.load( path, ( _e ) => {
if( !_e ) {
this.nodResult.action( "action1", true );
} else {
this.nodResult.stop();
}
} );
}
},
freshCount: function() {
this.changeCount();
},
// 数量改变
changeCount: function() {
this.maxLen = 101;
this.minLen = 1;
// 设置滚动条
this.cmpCounter.build( 1, 101, 50, ( _count ) => {
this.changeScale( _count );
} );
},
changeScale: function( _count ) {
// _count = _count * ( ( this.max_scale - this.min_scale ) / ( this.maxLen - this.minLen ) )
// 0.1 * 5 0.1 * 10 count = 0 - 100 101 = 1 50-- 0.5 1 --- 0.1
let scale = 0;
let dec = ( this.maxLen - this.minLen );
let rate = ( this.max_scale - this.min_scale ) / dec; // 计算比率 最大减去最小
// 计算滑动条值
let progress = _count * rate + + this.min_scale;
// 当滑动条数值为 最小时 显示的当前ui的缩放比例是0.1 (101 x 0.01)x + y = 1 (50 X 0.01)x + y = 0.5
if( progress <= this.min_scale ) {
scale = this.min_scale;
} else {
if( progress >= this.max_scale ) {
scale = this.max_scale;
} else {
scale = progress;
}
}
// scale = _count;
// console.log( progress + "数值缩放 " + scale );
this.nodResult.node.scale = scale * 1;
},
// update (dt) {}
_onTouchMove( touchEvent ) {
// let location = touchEvent.getLocation();
// this.nodResult.node.position = this.nodResult.node.parent.convertToNodeSpaceAR( location ); // 确定位置
// 偏移移动
let offset = touchEvent.getDelta();
let pos = this.nodResult.position;
this.nodResult.position = cc.v2( pos.x + offset.x, pos.y + offset.y );
this.can = false;
},
_onTouchEnd( touchEvent ) {
// 放下
this.can = true;
},
hideAllOps: function() {
nx.gui.setActive( this, "panel/ops", !nx.gui.find( this, "panel/ops" ).active );
nx.gui.setActive( this, "panel/back", !nx.gui.find( this, "panel/back" ).active );
},
// 点击动画
onTouchSpine: function() {
if( this.can ){
// 屏蔽频繁点击打断
if( this.nodResult.spAction != "action1" ) {
return;
}
// 播放 -> 常态
this.nodResult.action( "action2", false, ( _event ) => {
if( _event == "complete" ) {
this.nodResult.action( "action1", true );
}
} );
}
},
} );