import { ComponentProps, ComputedSubject, DisplayComponent, FSComponent, NodeReference, Subscribable, VNode, } from '@microsoft/msfs-sdk'; import './controls.scss'; interface ControlsProps extends ComponentProps { containerRef: NodeReference; reload: () => void; position: Subscribable; page: number; } export class Controls extends DisplayComponent { private cycleRef = FSComponent.createRef(); private toTopRef = FSComponent.createRef(); private reloadRef = FSComponent.createRef(); private switchPosRef = FSComponent.createRef(); private buttonName = ComputedSubject.create(0, (val) => { if (val === 1) return '/Pages/VCockpit/Instruments/FSS_B727/KH_FE_FPLAN/assets/img/compass.png'; else if (val === 2) return '/Pages/VCockpit/Instruments/FSS_B727/KH_FE_FPLAN/assets/img/wrench.png'; return ''; }); constructor(props: ControlsProps) { super(props); props.position.sub((p) => this.buttonName.set(p)); } private cycle = (): void => { if (this.props.page === 0) SimVar.SetSimVarValue('L:KH_FE_FPLAN_P1', 'bool', true); else if (this.props.page === 1) SimVar.SetSimVarValue('L:KH_FE_FPLAN_P1', 'bool', false); }; private toTop = (): void => { if (!this.props.containerRef.instance) return; this.props.containerRef.instance.scrollTop = 0; }; private switchPosition = (): void => { if (this.props.position.get() === 1) SimVar.SetSimVarValue('L:KH_FE_FPLAN_BOARD', 'number', 2); else if (this.props.position.get() === 2) SimVar.SetSimVarValue('L:KH_FE_FPLAN_BOARD', 'number', 1); }; public render = (): VNode => (
{this.props.page === 1 && (
)}
{this.props.page === 0 && (
)}
); public onAfterRender = (): void => { this.cycleRef.instance.onclick = this.cycle; this.toTopRef.instance.onclick = this.toTop; this.reloadRef.instance.onclick = this.props.reload; this.switchPosRef.instance.onclick = this.switchPosition; }; }