Add behavior details panel & auto switch behavior details panels & mod behavior model add cache object #34
@ -112,7 +112,7 @@ class BehaviorList extends Component<IBehaviorListProps & IMixinSettingProps & I
|
||||
if (behavior instanceof Behavior) {
|
||||
id = behavior.id;
|
||||
name = behavior.name;
|
||||
color = behavior.color;
|
||||
color = `rgb(${behavior.color.join(",")})`;
|
||||
needLocal = false;
|
||||
info = behavior.behaviorName;
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ class BehaviorPicker extends Component<IBehaviorPickerProps & IMixinSettingProps
|
||||
|
||||
return <>
|
||||
<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
|
||||
className="behavior-picker-line-icon-view"
|
||||
|
@ -123,8 +123,7 @@ class BehaviorPopupComponent extends Component<
|
||||
) + " " + (recorder.nameIndex - 1).toString();
|
||||
|
||||
// 赋予一个随机颜色
|
||||
let color = randomColor(true);
|
||||
newBehavior.color = `rgb(${color[0]},${color[1]},${color[2]})`;
|
||||
newBehavior.color = randomColor(true);
|
||||
}
|
||||
});
|
||||
this.props.onDismiss ? this.props.onDismiss() : undefined;
|
||||
|
@ -11,7 +11,7 @@ import { Setting } from "./Setting";
|
||||
import { I18N } from "@Component/Localization/Localization";
|
||||
import { superConnectWithEvent, superConnect } from "./Context";
|
||||
import { PopupController } from "./Popups";
|
||||
import { Behavior } from "@Model/Behavior";
|
||||
import { Behavior, IBehaviorParameter, IParamValue } from "@Model/Behavior";
|
||||
import { Actuator } from "@Model/Actuator";
|
||||
|
||||
function randomColor(unNormal: boolean = false) {
|
||||
@ -43,6 +43,7 @@ interface IStatusEvent {
|
||||
rangeAttrChange: void;
|
||||
labelAttrChange: void;
|
||||
groupAttrChange: void;
|
||||
behaviorAttrChange: void;
|
||||
individualChange: void;
|
||||
behaviorChange: 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) {
|
||||
const group = this.model.getObjectById(id);
|
||||
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;
|
||||
|
||||
export {
|
||||
Behavior, BehaviorRecorder, IBehaviorParameterOption, IBehaviorParameterOptionItem,
|
||||
IAnyBehavior, IAnyBehaviorRecorder, BehaviorInfo, IRenderBehavior
|
||||
Behavior, BehaviorRecorder, IBehaviorParameterOption, IBehaviorParameterOptionItem, IParamValue,
|
||||
IAnyBehavior, IAnyBehaviorRecorder, BehaviorInfo, IRenderBehavior, IBehaviorParameter
|
||||
};
|
||||
export default { Behavior };
|
@ -56,11 +56,11 @@ class SimulatorWeb extends Component {
|
||||
this.status.newLabel().name = "New Label";
|
||||
this.status.newLabel().name = "Test Label 01";
|
||||
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]);
|
||||
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]);
|
||||
boundary.name = "Boundary"; boundary.color = "rgb(80, 200, 250)";
|
||||
boundary.name = "Boundary"; boundary.color = [80, 200, 250];
|
||||
boundary.parameter.range = this.status.model.allRangeLabel;
|
||||
group.addBehavior(dynamic);
|
||||
group.addBehavior(brownian);
|
||||
|
@ -2,15 +2,36 @@ import { Component, ReactNode} from "react";
|
||||
import { useStatusWithEvent, IMixinStatusProps } from "@Context/Status";
|
||||
import { Behavior } from "@Model/Behavior";
|
||||
import { Message } from "@Component/Message/Message";
|
||||
import { AttrInput } from "@Component/AttrInput/AttrInput";
|
||||
import { ColorInput } from "@Component/ColorInput/ColorInput";
|
||||
import "./BehaviorDetails.scss";
|
||||
|
||||
interface IBehaviorDetailsProps {}
|
||||
|
||||
@useStatusWithEvent("focusBehaviorChange")
|
||||
@useStatusWithEvent("focusBehaviorChange", "behaviorAttrChange")
|
||||
class BehaviorDetails extends Component<IBehaviorDetailsProps & IMixinStatusProps> {
|
||||
|
||||
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 {
|
||||
|
@ -13,7 +13,7 @@ interface IBehaviorListProps {
|
||||
}
|
||||
|
||||
@useSetting
|
||||
@useStatusWithEvent("behaviorChange", "focusBehaviorChange")
|
||||
@useStatusWithEvent("behaviorChange", "focusBehaviorChange", "behaviorAttrChange")
|
||||
class BehaviorList extends Component<IBehaviorListProps & IMixinStatusProps & IMixinSettingProps> {
|
||||
|
||||
private labelInnerClick: boolean = false;
|
||||
|
@ -29,7 +29,8 @@ const allOption: IDisplayItem[] = [
|
||||
@useSetting
|
||||
@useStatusWithEvent(
|
||||
"groupAttrChange", "groupLabelChange", "focusObjectChange",
|
||||
"focusBehaviorChange", "behaviorChange", "groupBehaviorChange"
|
||||
"focusBehaviorChange", "behaviorChange", "groupBehaviorChange",
|
||||
"behaviorAttrChange"
|
||||
)
|
||||
class GroupDetails extends Component<IGroupDetailsProps & IMixinStatusProps & IMixinSettingProps> {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user