import * as React from "react"; import { Observable } from "babylonjs/Misc/observable"; import { TargetedAnimation } from "babylonjs/Animations/animationGroup"; import { Scene } from "babylonjs/scene"; import { PropertyChangedEvent } from "../../../../propertyChangedEvent"; import { ButtonLineComponent } from "../../../lines/buttonLineComponent"; import { LineContainerComponent } from "../../../lineContainerComponent"; import { TextLineComponent } from "../../../lines/textLineComponent"; import { LockObject } from "../lockObject"; import { GlobalState } from "../../../../globalState"; import { TextInputLineComponent } from "../../../lines/textInputLineComponent"; import { PopupComponent } from "../animations/popupComponent"; import { AnimationCurveEditorComponent } from "../animations/animationCurveEditorComponent"; import { AnimationGroup } from "babylonjs/Animations/animationGroup"; interface ITargetedAnimationGridComponentProps { globalState: GlobalState; targetedAnimation: TargetedAnimation; scene: Scene; lockObject: LockObject; onSelectionChangedObservable?: Observable; onPropertyChangedObservable?: Observable; } export class TargetedAnimationGridComponent extends React.Component< ITargetedAnimationGridComponentProps > { private _isCurveEditorOpen: boolean; private _animationGroup: AnimationGroup | undefined; constructor(props: ITargetedAnimationGridComponentProps) { super(props); this._animationGroup = this.props.scene.animationGroups.find((ag) => { let ta = ag.targetedAnimations.find( (ta) => ta === this.props.targetedAnimation ); return ta !== undefined; }); } onOpenAnimationCurveEditor() { this._isCurveEditorOpen = true; } onCloseAnimationCurveEditor(window: Window | null) { this._isCurveEditorOpen = false; if (window !== null) { window.close(); } } playOrPause() { if (this._animationGroup) { if (this._animationGroup.isPlaying) { this._animationGroup.stop(); } else { this._animationGroup.start(); } this.forceUpdate(); } } deleteAnimation() { if (this._animationGroup) { let index = this._animationGroup.targetedAnimations.indexOf( this.props.targetedAnimation ); if (index > -1) { this._animationGroup.targetedAnimations.splice(index, 1); this.props.onSelectionChangedObservable?.notifyObservers(null); if (this._animationGroup.isPlaying) { this._animationGroup.stop(); this._animationGroup.start(); } } } } render() { const targetedAnimation = this.props.targetedAnimation; return (
{targetedAnimation.target.name && ( this.props.globalState.onSelectionChangedObservable.notifyObservers( targetedAnimation ) } /> )} this.onOpenAnimationCurveEditor()} /> {this._isCurveEditorOpen && ( {}} onClose={(window: Window) => this.onCloseAnimationCurveEditor(window) } > this.playOrPause()} lockObject={this.props.lockObject} close={(event) => this.onCloseAnimationCurveEditor(event.view)} /> )} this.deleteAnimation()} />
); } }