import { CCInteger } from 'cc'; import { Label } from 'cc'; import { Slider } from 'cc'; import { _decorator, Component, Node } from 'cc'; import { UmLog } from '../../../cc-common/cc-util/UmLog'; const { ccclass, property } = _decorator; @ccclass('ItemDataConfig') export class ItemDataConfig extends Component { @property(Slider) slider: Slider = null!; @property(Label) valueTxt: Label = null!; @property(CCInteger) maxValue = 100; @property(CCInteger) minValue = 1; @property(CCInteger) roundDigits = 0; protected onEnable(): void { this.slider.node.on('slide', this.onSlide, this); } protected onDisable(): void { this.slider.node.off('slide', this.onSlide, this); } onSlide(slider: Slider) { this.updateDisplay(); } setData(value) { var progress = (value - this.minValue) / (this.maxValue - this.minValue); UmLog.log("Slider => ", progress); progress = Math.min(1, progress); this.slider.progress = progress; this.updateDisplay(); } updateDisplay() { var value = this.minValue + this.slider.progress * (this.maxValue - this.minValue); value = Math.min(this.maxValue, value); this.valueTxt.string = value.roundDigits(this.roundDigits).toString(); } getData(): number { return Number(this.valueTxt.string); } }