Add behavior attr panel basic props editer
This commit is contained in:
parent
4d818988f9
commit
c10dd6e882
@ -112,7 +112,7 @@ class BehaviorList extends Component<IBehaviorListProps & IMixinSettingProps & I
|
|||||||
if (behavior instanceof Behavior) {
|
if (behavior instanceof Behavior) {
|
||||||
id = behavior.id;
|
id = behavior.id;
|
||||||
name = behavior.name;
|
name = behavior.name;
|
||||||
color = behavior.color;
|
color = `rgb(${behavior.color.join(",")})`;
|
||||||
needLocal = false;
|
needLocal = false;
|
||||||
info = behavior.behaviorName;
|
info = behavior.behaviorName;
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ class BehaviorPicker extends Component<IBehaviorPickerProps & IMixinSettingProps
|
|||||||
|
|
||||||
return <>
|
return <>
|
||||||
<div className="behavior-picker-line-color-view">
|
<div className="behavior-picker-line-color-view">
|
||||||
<div style={{ borderLeft: `10px solid ${behavior.color}` }}/>
|
<div style={{ borderLeft: `10px solid rgb(${behavior.color.join(",")})` }}/>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
className="behavior-picker-line-icon-view"
|
className="behavior-picker-line-icon-view"
|
||||||
|
@ -123,8 +123,7 @@ class BehaviorPopupComponent extends Component<
|
|||||||
) + " " + (recorder.nameIndex - 1).toString();
|
) + " " + (recorder.nameIndex - 1).toString();
|
||||||
|
|
||||||
// 赋予一个随机颜色
|
// 赋予一个随机颜色
|
||||||
let color = randomColor(true);
|
newBehavior.color = randomColor(true);
|
||||||
newBehavior.color = `rgb(${color[0]},${color[1]},${color[2]})`;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.props.onDismiss ? this.props.onDismiss() : undefined;
|
this.props.onDismiss ? this.props.onDismiss() : undefined;
|
||||||
|
@ -11,7 +11,7 @@ import { Setting } from "./Setting";
|
|||||||
import { I18N } from "@Component/Localization/Localization";
|
import { I18N } from "@Component/Localization/Localization";
|
||||||
import { superConnectWithEvent, superConnect } from "./Context";
|
import { superConnectWithEvent, superConnect } from "./Context";
|
||||||
import { PopupController } from "./Popups";
|
import { PopupController } from "./Popups";
|
||||||
import { Behavior } from "@Model/Behavior";
|
import { Behavior, IBehaviorParameter, IParamValue } from "@Model/Behavior";
|
||||||
import { Actuator } from "@Model/Actuator";
|
import { Actuator } from "@Model/Actuator";
|
||||||
|
|
||||||
function randomColor(unNormal: boolean = false) {
|
function randomColor(unNormal: boolean = false) {
|
||||||
@ -43,6 +43,7 @@ interface IStatusEvent {
|
|||||||
rangeAttrChange: void;
|
rangeAttrChange: void;
|
||||||
labelAttrChange: void;
|
labelAttrChange: void;
|
||||||
groupAttrChange: void;
|
groupAttrChange: void;
|
||||||
|
behaviorAttrChange: void;
|
||||||
individualChange: void;
|
individualChange: void;
|
||||||
behaviorChange: void;
|
behaviorChange: void;
|
||||||
popupChange: void;
|
popupChange: void;
|
||||||
@ -193,6 +194,24 @@ class Status extends Emitter<IStatusEvent> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改群属性
|
||||||
|
*/
|
||||||
|
public changeBehaviorAttrib<K extends IBehaviorParameter, P extends keyof K | keyof Behavior<K>>
|
||||||
|
(id: ObjectID, key: P, val: IParamValue<K[P]>) {
|
||||||
|
const behavior = this.model.getBehaviorById(id);
|
||||||
|
if (behavior) {
|
||||||
|
if (key === "color") {
|
||||||
|
behavior.color = val as number[];
|
||||||
|
} else if (key === "name") {
|
||||||
|
behavior.name = val as string;
|
||||||
|
} else {
|
||||||
|
behavior.parameter[key] = val;
|
||||||
|
}
|
||||||
|
this.emit("behaviorAttrChange");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public addGroupBehavior(id: ObjectID, val: Behavior) {
|
public addGroupBehavior(id: ObjectID, val: Behavior) {
|
||||||
const group = this.model.getObjectById(id);
|
const group = this.model.getObjectById(id);
|
||||||
if (group && group instanceof Group) {
|
if (group && group instanceof Group) {
|
||||||
|
@ -295,7 +295,7 @@ class Behavior<
|
|||||||
/**
|
/**
|
||||||
* 颜色
|
* 颜色
|
||||||
*/
|
*/
|
||||||
public color: string = "";
|
public color: number[] = [0, 0, 0];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 优先级
|
* 优先级
|
||||||
@ -397,7 +397,7 @@ class Behavior<
|
|||||||
type IRenderBehavior = BehaviorInfo | Behavior;
|
type IRenderBehavior = BehaviorInfo | Behavior;
|
||||||
|
|
||||||
export {
|
export {
|
||||||
Behavior, BehaviorRecorder, IBehaviorParameterOption, IBehaviorParameterOptionItem,
|
Behavior, BehaviorRecorder, IBehaviorParameterOption, IBehaviorParameterOptionItem, IParamValue,
|
||||||
IAnyBehavior, IAnyBehaviorRecorder, BehaviorInfo, IRenderBehavior
|
IAnyBehavior, IAnyBehaviorRecorder, BehaviorInfo, IRenderBehavior, IBehaviorParameter
|
||||||
};
|
};
|
||||||
export default { Behavior };
|
export default { Behavior };
|
@ -56,11 +56,11 @@ class SimulatorWeb extends Component {
|
|||||||
this.status.newLabel().name = "New Label";
|
this.status.newLabel().name = "New Label";
|
||||||
this.status.newLabel().name = "Test Label 01";
|
this.status.newLabel().name = "Test Label 01";
|
||||||
let dynamic = this.status.model.addBehavior(AllBehaviors[0]);
|
let dynamic = this.status.model.addBehavior(AllBehaviors[0]);
|
||||||
dynamic.name = "Dynamic"; dynamic.color = "rgb(250, 200, 80)";
|
dynamic.name = "Dynamic"; dynamic.color = [250, 200, 80];
|
||||||
let brownian = this.status.model.addBehavior(AllBehaviors[1]);
|
let brownian = this.status.model.addBehavior(AllBehaviors[1]);
|
||||||
brownian.name = "Brownian"; brownian.color = "rgb(200, 80, 250)";
|
brownian.name = "Brownian"; brownian.color = [200, 80, 250];
|
||||||
let boundary = this.status.model.addBehavior(AllBehaviors[2]);
|
let boundary = this.status.model.addBehavior(AllBehaviors[2]);
|
||||||
boundary.name = "Boundary"; boundary.color = "rgb(80, 200, 250)";
|
boundary.name = "Boundary"; boundary.color = [80, 200, 250];
|
||||||
boundary.parameter.range = this.status.model.allRangeLabel;
|
boundary.parameter.range = this.status.model.allRangeLabel;
|
||||||
group.addBehavior(dynamic);
|
group.addBehavior(dynamic);
|
||||||
group.addBehavior(brownian);
|
group.addBehavior(brownian);
|
||||||
|
@ -2,15 +2,36 @@ import { Component, ReactNode} from "react";
|
|||||||
import { useStatusWithEvent, IMixinStatusProps } from "@Context/Status";
|
import { useStatusWithEvent, IMixinStatusProps } from "@Context/Status";
|
||||||
import { Behavior } from "@Model/Behavior";
|
import { Behavior } from "@Model/Behavior";
|
||||||
import { Message } from "@Component/Message/Message";
|
import { Message } from "@Component/Message/Message";
|
||||||
|
import { AttrInput } from "@Component/AttrInput/AttrInput";
|
||||||
|
import { ColorInput } from "@Component/ColorInput/ColorInput";
|
||||||
import "./BehaviorDetails.scss";
|
import "./BehaviorDetails.scss";
|
||||||
|
|
||||||
interface IBehaviorDetailsProps {}
|
interface IBehaviorDetailsProps {}
|
||||||
|
|
||||||
@useStatusWithEvent("focusBehaviorChange")
|
@useStatusWithEvent("focusBehaviorChange", "behaviorAttrChange")
|
||||||
class BehaviorDetails extends Component<IBehaviorDetailsProps & IMixinStatusProps> {
|
class BehaviorDetails extends Component<IBehaviorDetailsProps & IMixinStatusProps> {
|
||||||
|
|
||||||
private renderFrom(behavior: Behavior): ReactNode {
|
private renderFrom(behavior: Behavior): ReactNode {
|
||||||
return <></>;
|
return <>
|
||||||
|
|
||||||
|
<Message i18nKey="Common.Attr.Title.Basic" isTitle first/>
|
||||||
|
|
||||||
|
<AttrInput
|
||||||
|
id={behavior.id} keyI18n="Common.Attr.Key.Display.Name" value={behavior.name}
|
||||||
|
valueChange={(val) => {
|
||||||
|
this.props.status?.changeBehaviorAttrib(behavior.id, "name", val);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<ColorInput
|
||||||
|
keyI18n="Common.Attr.Key.Color"
|
||||||
|
value={behavior.color}
|
||||||
|
valueChange={(color) => {
|
||||||
|
this.props.status?.changeBehaviorAttrib(behavior.id, "color", color);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
</>;
|
||||||
}
|
}
|
||||||
|
|
||||||
public render(): ReactNode {
|
public render(): ReactNode {
|
||||||
|
@ -13,7 +13,7 @@ interface IBehaviorListProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@useSetting
|
@useSetting
|
||||||
@useStatusWithEvent("behaviorChange", "focusBehaviorChange")
|
@useStatusWithEvent("behaviorChange", "focusBehaviorChange", "behaviorAttrChange")
|
||||||
class BehaviorList extends Component<IBehaviorListProps & IMixinStatusProps & IMixinSettingProps> {
|
class BehaviorList extends Component<IBehaviorListProps & IMixinStatusProps & IMixinSettingProps> {
|
||||||
|
|
||||||
private labelInnerClick: boolean = false;
|
private labelInnerClick: boolean = false;
|
||||||
|
@ -29,7 +29,8 @@ const allOption: IDisplayItem[] = [
|
|||||||
@useSetting
|
@useSetting
|
||||||
@useStatusWithEvent(
|
@useStatusWithEvent(
|
||||||
"groupAttrChange", "groupLabelChange", "focusObjectChange",
|
"groupAttrChange", "groupLabelChange", "focusObjectChange",
|
||||||
"focusBehaviorChange", "behaviorChange", "groupBehaviorChange"
|
"focusBehaviorChange", "behaviorChange", "groupBehaviorChange",
|
||||||
|
"behaviorAttrChange"
|
||||||
)
|
)
|
||||||
class GroupDetails extends Component<IGroupDetailsProps & IMixinStatusProps & IMixinSettingProps> {
|
class GroupDetails extends Component<IGroupDetailsProps & IMixinStatusProps & IMixinSettingProps> {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user