forked from mirror/ObjToSchematic
Fix for obeyGroupEnables properties not updating correctly
This commit is contained in:
parent
765faecd2f
commit
4a295894ab
@ -27,7 +27,7 @@ export abstract class BaseUIElement<T> {
|
||||
* Set whether or not this UI element is interactable.
|
||||
*/
|
||||
public setEnabled(isEnabled: boolean, isGroupEnable: boolean = true) {
|
||||
if (isGroupEnable && !this._obeyGroupEnables) {
|
||||
if (isEnabled && isGroupEnable && !this._obeyGroupEnables) {
|
||||
return;
|
||||
}
|
||||
this._isEnabled = isEnabled;
|
||||
@ -43,6 +43,7 @@ export abstract class BaseUIElement<T> {
|
||||
*/
|
||||
public setShouldObeyGroupEnables(obey: boolean) {
|
||||
this._obeyGroupEnables = obey;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -14,6 +14,7 @@ export abstract class ConfigUIElement<T, F> extends BaseUIElement<F> {
|
||||
private _value?: T;
|
||||
private _cachedValue?: T;
|
||||
private _onValueChangedListeners: Array<(newValue: T) => void>;
|
||||
private _onEnabledChangedListeners: Array<(isEnabled: boolean) => void>;
|
||||
|
||||
public constructor(defaultValue?: T) {
|
||||
super();
|
||||
@ -22,6 +23,7 @@ export abstract class ConfigUIElement<T, F> extends BaseUIElement<F> {
|
||||
this._hasLabel = false;
|
||||
this._labelElement = new LabelElement(this._label, this._description);
|
||||
this._onValueChangedListeners = [];
|
||||
this._onEnabledChangedListeners = [];
|
||||
}
|
||||
|
||||
public setDefaultValue(value: T) {
|
||||
@ -71,6 +73,14 @@ export abstract class ConfigUIElement<T, F> extends BaseUIElement<F> {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a delegate that will be called when the value changes.
|
||||
*/
|
||||
public addEnabledChangedListener(delegate: (isEnabled: boolean) => void) {
|
||||
this._onEnabledChangedListeners.push(delegate);
|
||||
return this;
|
||||
}
|
||||
|
||||
public override finalise(): void {
|
||||
super.finalise();
|
||||
|
||||
@ -98,6 +108,10 @@ export abstract class ConfigUIElement<T, F> extends BaseUIElement<F> {
|
||||
if (this._hasLabel) {
|
||||
this._labelElement.setEnabled(this.getEnabled());
|
||||
}
|
||||
|
||||
this._onEnabledChangedListeners.forEach((listener) => {
|
||||
listener(this.getEnabled());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -208,12 +208,13 @@ export class UI {
|
||||
.setUncheckedText('Off')
|
||||
.setDefaultValue(false)
|
||||
.setLabel('Calculate lighting')
|
||||
.addValueChangedListener((value: boolean) => {
|
||||
if (value) {
|
||||
this._ui.assign.elements.lightThreshold.setEnabled(true, false);
|
||||
} else {
|
||||
this._ui.assign.elements.lightThreshold.setEnabled(false, false);
|
||||
}
|
||||
.addValueChangedListener((newValue: boolean) => {
|
||||
const isEnabled = this._ui.assign.elements.calculateLighting.getEnabled();
|
||||
this._ui.assign.elements.lightThreshold.setEnabled(newValue && isEnabled, false);
|
||||
})
|
||||
.addEnabledChangedListener((isEnabled: boolean) => {
|
||||
const value = this._ui.assign.elements.calculateLighting.getValue();
|
||||
this._ui.assign.elements.lightThreshold.setEnabled(value && isEnabled, false);
|
||||
}),
|
||||
'lightThreshold': new SliderElement()
|
||||
.setMin(0)
|
||||
@ -221,7 +222,8 @@ export class UI {
|
||||
.setDefaultValue(1)
|
||||
.setDecimals(0)
|
||||
.setStep(1)
|
||||
.setLabel('Light threshold'),
|
||||
.setLabel('Light threshold')
|
||||
.setShouldObeyGroupEnables(false),
|
||||
},
|
||||
elementsOrder: [
|
||||
'textureAtlas',
|
||||
|
Loading…
Reference in New Issue
Block a user