/****************************************************************** * Copyright(C) 2019 - 2020 Nx Studio * * 滑动条+滚动条+增减Max * * 2018.05.18 ******************************************************************/ const NxButton = require( "nx.fx.button" ); cc.Class( { extends: cc.Component, properties: { minSlider: { default: 4, displayName: "滑动开启值" }, nodSlider: { default: null, type: cc.Slider, displayName: "滑动条" }, nodProg: { default: null, type: cc.Node, displayName: "进度条" }, txtProg: { default: null, type: cc.Node, displayName: "文本" }, btnDec: { default: null, type: NxButton, }, btnInc: { default: null, type: NxButton, }, btnMax: { default: null, type: NxButton, }, }, // 重建 build: function( _min, _max, _cur, _cb ) { this.min = _min; this.max = _max; this.cb = _cb; // 滑动功能开关 let step = _max - _min; nx.gui.setEnable( this.nodSlider, "Handle", step >= this.minSlider ); this.setCur( _cur || _max ); }, // 设置 setCur: function( _cur ) { this.cur = Math.floor( parseInt( _cur ) ); let rate = this.cur / this.max; this.nodSlider.progress = rate; // this.nodProg.width = 10 + this.nodSlider.node.width * rate; this.nodProg.scaleX = rate; this.btnDec.lock( this.cur <= this.min ); this.btnInc.lock( this.cur >= this.max ); this.btnMax.lock( this.cur >= this.max ); nx.gui.setString( this.nodSlider, "txt", this.cur ); nx.dt.fnInvoke( this.cb, this.cur ); }, // 滚动事件 onSlider: function() { let rate = this.nodSlider.progress; // this.nodProg.width = 10 + this.nodSlider.node.width * rate; this.nodProg.scaleX = rate; // 小碎步忽略 rate = Math.floor( this.min + ( this.max - this.min ) * rate ); if( this.cur == rate ) { return; } this.cur = rate; this.btnDec.lock( this.cur <= this.min ); this.btnInc.lock( this.cur >= this.max ); this.btnMax.lock( this.cur >= this.max ); nx.gui.setString( this.nodSlider, "txt", this.cur ); nx.dt.fnInvoke( this.cb, this.cur ); }, // 减少 onTouchDec: function() { this.setCur( this.cur - 1 ); }, // 增加 onTouchInc: function() { this.setCur( this.cur + 1 ); }, // 最大 onTouchMax: function() { this.setCur( this.max ); }, } );