Files
fc/dev/project/library/imports/2c/2cdb66e2-a186-4953-863d-bdcedfdba6b3.js
2026-05-24 10:21:26 +08:00

107 lines
2.7 KiB
JavaScript

"use strict";
cc._RF.push(module, '2cdb6bioYZJU4Y9vc7f26az', 'cmp.slider.prog.selector');
// Scripts/mod/backpack/cmps/cmp.slider.prog.selector.js
"use strict";
/******************************************************************
* Copyright(C) 2019 - 2020 Nx Studio
*
* 滑动条+滚动条+增减Max
*
* 2018.05.18
******************************************************************/
var 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 build(_min, _max, _cur, _cb) {
this.min = _min;
this.max = _max;
this.cb = _cb;
// 滑动功能开关
var step = _max - _min;
nx.gui.setEnable(this.nodSlider, "Handle", step >= this.minSlider);
this.setCur(_cur || _max);
},
// 设置
setCur: function setCur(_cur) {
this.cur = Math.floor(parseInt(_cur));
var 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 onSlider() {
var 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 onTouchDec() {
this.setCur(this.cur - 1);
},
// 增加
onTouchInc: function onTouchInc() {
this.setCur(this.cur + 1);
},
// 最大
onTouchMax: function onTouchMax() {
this.setCur(this.max);
}
});
cc._RF.pop();