cursor-style-manager-wle
Version:
Shared cursor styles for Wonderland Engine
40 lines • 1.63 kB
JavaScript
import { CSMComponent } from './CSMComponent';
export class CSMButtonComponent extends CSMComponent {
onActivate() {
this.cursorTarget = this.object.getComponent('cursor-target');
if (!this.cursorTarget) {
console.warn("Can't set up button; button object has no cursor-target component");
return;
}
this.hoverCallback = this.onButtonStateChanged.bind(this, 'hovering');
this.cursorTarget.onHover.add(this.hoverCallback);
this.unhoverCallback = this.onButtonStateChanged.bind(this, 'released');
this.cursorTarget.onUnhover.add(this.unhoverCallback);
this.downCallback = this.onButtonStateChanged.bind(this, 'pressing');
this.cursorTarget.onDown.add(this.downCallback);
this.upCallback = () => {
this.onButtonStateChanged('hovering');
this.onButtonClick();
};
this.cursorTarget.onUp.add(this.upCallback);
}
onDeactivate() {
super.onDeactivate();
if (this.cursorTarget) {
this.cursorTarget.onHover.remove(this.hoverCallback);
this.cursorTarget.onUnhover.remove(this.unhoverCallback);
this.cursorTarget.onDown.remove(this.downCallback);
this.cursorTarget.onUp.remove(this.upCallback);
this.cursorTarget = null;
}
}
onButtonStateChanged(newState) {
if (newState === 'hovering' || newState === 'pressing') {
this.setCursorStyle('pointer');
}
else {
this.setCursorStyle(null);
}
}
}
//# sourceMappingURL=CSMButtonComponent.js.map