From c3d4c13c1042c264450ce48a271c3f629f9a0fdd Mon Sep 17 00:00:00 2001 From: MrKBear Date: Sun, 10 Apr 2022 18:50:29 +0800 Subject: [PATCH] Add parameter restore --- source/Localization/EN-US.ts | 4 ++ source/Localization/ZH-CN.ts | 4 ++ .../Panel/BehaviorDetails/BehaviorDetails.tsx | 43 ++++++++++++++++++- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/source/Localization/EN-US.ts b/source/Localization/EN-US.ts index d6081fe..a9edf6f 100644 --- a/source/Localization/EN-US.ts +++ b/source/Localization/EN-US.ts @@ -57,8 +57,11 @@ const EN_US = { "Popup.Action.No": "Cancel", "Popup.Action.Objects.Confirm.Title": "Confirm Delete", "Popup.Action.Objects.Confirm.Delete": "Delete", + "Popup.Action.Objects.Confirm.Restore.Title": "Confirm Restore", + "Popup.Action.Objects.Confirm.Restore": "Restore", "Popup.Delete.Objects.Confirm": "Are you sure you want to delete this object(s)? The object is deleted and cannot be recalled.", "Popup.Delete.Behavior.Confirm": "Are you sure you want to delete this behavior? The behavior is deleted and cannot be recalled.", + "Popup.Restore.Behavior.Confirm": "Are you sure you want to reset all parameters of this behavior? This operation cannot be recalled.", "Popup.Setting.Title": "Preferences setting", "Popup.Add.Behavior.Title": "Add behavior", "Popup.Add.Behavior.Action.Add": "Add all select behavior", @@ -108,6 +111,7 @@ const EN_US = { "Common.Attr.Key.Generation.Error.Invalid.Label": "The specified label has expired", "Common.Attr.Key.Kill.Random": "Random kill", "Common.Attr.Key.Kill.Count": "Kill count", + "Common.Attr.Key.Behavior.Restore": "Restore default parameters", "Common.Render.Attr.Key.Display.Shape": "Display Shape", "Common.Render.Attr.Key.Display.Shape.Square": "Square", "Common.Render.Attr.Key.Display.Shape.Hollow.Square": "Hollow square", diff --git a/source/Localization/ZH-CN.ts b/source/Localization/ZH-CN.ts index 3908339..11a40eb 100644 --- a/source/Localization/ZH-CN.ts +++ b/source/Localization/ZH-CN.ts @@ -57,8 +57,11 @@ const ZH_CN = { "Popup.Action.No": "取消", "Popup.Action.Objects.Confirm.Title": "删除确认", "Popup.Action.Objects.Confirm.Delete": "删除", + "Popup.Action.Objects.Confirm.Restore.Title": "重置确认", + "Popup.Action.Objects.Confirm.Restore": "重置", "Popup.Delete.Objects.Confirm": "你确定要删除这个(些)对象吗?对象被删除将无法撤回。", "Popup.Delete.Behavior.Confirm": "你确定要删除这个行为吗?行为被删除将无法撤回。", + "Popup.Restore.Behavior.Confirm": "你确定要重置此行为的全部参数吗?此操作无法撤回。", "Popup.Setting.Title": "首选项设置", "Popup.Add.Behavior.Title": "添加行为", "Popup.Add.Behavior.Action.Add": "添加全部选中行为", @@ -108,6 +111,7 @@ const ZH_CN = { "Common.Attr.Key.Generation.Error.Invalid.Label": "指定的标签已失效", "Common.Attr.Key.Kill.Random": "随机消除", "Common.Attr.Key.Kill.Count": "消除数量", + "Common.Attr.Key.Behavior.Restore": "还原默认参数", "Common.Render.Attr.Key.Display.Shape": "显示形状", "Common.Render.Attr.Key.Display.Shape.Square": "方形", "Common.Render.Attr.Key.Display.Shape.Hollow.Square": "空心方形", diff --git a/source/Panel/BehaviorDetails/BehaviorDetails.tsx b/source/Panel/BehaviorDetails/BehaviorDetails.tsx index e3490e9..c9f69d2 100644 --- a/source/Panel/BehaviorDetails/BehaviorDetails.tsx +++ b/source/Panel/BehaviorDetails/BehaviorDetails.tsx @@ -1,6 +1,7 @@ import { Component, ReactNode} from "react"; import { useSettingWithEvent, IMixinSettingProps } from "@Context/Setting"; import { useStatusWithEvent, IMixinStatusProps } from "@Context/Status"; +import { getDefaultValue } from "@Model/Parameter"; import { IAnyBehavior } from "@Model/Behavior"; import { Message } from "@Input/Message/Message"; import { AttrInput } from "@Input/AttrInput/AttrInput"; @@ -12,9 +13,17 @@ import "./BehaviorDetails.scss"; interface IBehaviorDetailsProps {} +interface IBehaviorDetailsState { + updateId: number; +} + @useSettingWithEvent("language") @useStatusWithEvent("focusBehaviorChange", "behaviorAttrChange") -class BehaviorDetails extends Component { +class BehaviorDetails extends Component { + + public state: Readonly = { + updateId: 1 + }; private handelDeleteBehavior = (behavior: IAnyBehavior) => { if (this.props.status) { @@ -32,6 +41,28 @@ class BehaviorDetails extends Component { + if (this.props.status) { + const status = this.props.status; + status.popup.showPopup(ConfirmPopup, { + infoI18n: "Popup.Restore.Behavior.Confirm", + titleI18N: "Popup.Action.Objects.Confirm.Restore.Title", + yesI18n: "Popup.Action.Objects.Confirm.Restore", + red: "yes", + yes: () => { + status.changeBehaviorAttrib( + behavior.id, "parameter", + getDefaultValue(behavior.parameterOption) as any, + true + ); + this.setState({ + updateId: this.state.updateId + 1 + }); + } + }) + } + } + private renderFrom(behavior: IAnyBehavior): ReactNode { return <> @@ -60,9 +91,17 @@ class BehaviorDetails extends Component + + { + this.handelRestoreBehavior(behavior) + }} + /> behavior.getTerms(name, language)}