import { Component, Fragment, ReactNode} from "react"; import { useSettingWithEvent, IMixinSettingProps } from "@Context/Setting"; import { useStatusWithEvent, IMixinStatusProps } from "@Context/Status"; import { Behavior, IBehaviorParameter, isObjectType, isVectorType } from "@Model/Behavior"; import { Message } from "@Component/Message/Message"; import { AttrInput } from "@Component/AttrInput/AttrInput"; import { ColorInput } from "@Component/ColorInput/ColorInput"; import { TogglesInput } from "@Component/TogglesInput/TogglesInput"; import { ConfirmPopup } from "@Component/ConfirmPopup/ConfirmPopup"; import { ObjectPicker } from "@Component/ObjectPicker/ObjectPicker"; import "./BehaviorDetails.scss"; interface IBehaviorDetailsProps {} @useSettingWithEvent("language") @useStatusWithEvent("focusBehaviorChange", "behaviorAttrChange") class BehaviorDetails extends Component { private renderFrom (behavior: Behavior>): ReactNode { const allParameterKeys = Object.getOwnPropertyNames(behavior.parameterOption); return <> { this.props.status?.changeBehaviorAttrib(behavior.id, "name", val, true); }} /> { this.props.status?.changeBehaviorAttrib(behavior.id, "color", color, true); }} /> { if (this.props.status) { const status = this.props.status; status.popup.showPopup(ConfirmPopup, { infoI18n: "Popup.Delete.Behavior.Confirm", titleI18N: "Popup.Action.Objects.Confirm.Title", yesI18n: "Popup.Action.Objects.Confirm.Delete", red: "yes", yes: () => { status.model.deleteBehavior(behavior); status.setBehaviorObject(); } }) } }} /> { allParameterKeys.length > 0 ? : null } { allParameterKeys.map((key) => { return this.renderParameter(behavior, key); }) } ; } private renderParameter (behavior: Behavior>, key: keyof T): ReactNode { const type = behavior.parameterOption[key]; const value = behavior.parameter[key]; const indexKey = `${behavior.id}-${key}`; if (type.type === "number") { return { this.props.status?.changeBehaviorAttrib(behavior.id, key as string, (val as any) / 1); }} /> } if (type.type === "string") { return { this.props.status?.changeBehaviorAttrib(behavior.id, key as string, val); }} /> } if (type.type === "boolean") { return { this.props.status?.changeBehaviorAttrib(behavior.id, key as string, val); }} /> } if (isObjectType(type.type as any)) { return { (value as any).picker = obj; this.props.status?.changeBehaviorAttrib(behavior.id, key as string, value); }} cleanValue={() => { (value as any).picker = undefined; this.props.status?.changeBehaviorAttrib(behavior.id, key as string, value); }} /> } if (isVectorType(type.type as any)) { return { (value as number[])[0] = (val as any) / 1; this.props.status?.changeBehaviorAttrib(behavior.id, key as string, value); }} /> { (value as number[])[1] = (val as any) / 1; this.props.status?.changeBehaviorAttrib(behavior.id, key as string, value); }} /> { (value as number[])[2] = (val as any) / 1; this.props.status?.changeBehaviorAttrib(behavior.id, key as string, value); }} /> } return } public render(): ReactNode { if (this.props.status && this.props.status.focusBehavior) { return this.renderFrom(this.props.status.focusBehavior); } return ; } } export { BehaviorDetails };