Skip to content

Commit 7f75b41

Browse files
committed
💄 优化控制设置界面,增加分组分类
1 parent c687593 commit 7f75b41

File tree

3 files changed

+71
-58
lines changed

3 files changed

+71
-58
lines changed

app/src/pages/settings/_field.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ const fieldColors = {
112112
blue: "bg-blue-500/20 hover:bg-blue-500/25",
113113
purple: "bg-purple-500/20 hover:bg-purple-500/25",
114114
};
115+
115116
export function Field({
116117
title = "",
117118
description = "",
@@ -153,3 +154,36 @@ export function Field({
153154
</div>
154155
);
155156
}
157+
158+
/**
159+
* 用于给各种设置项提供一个分类组
160+
* @param param0
161+
* @returns
162+
*/
163+
export function FieldGroup({
164+
title = "",
165+
icon = <></>,
166+
children = <></>,
167+
className = "",
168+
description = "",
169+
}: {
170+
title?: string;
171+
icon?: React.ReactNode;
172+
children?: React.ReactNode;
173+
className?: string;
174+
description?: string;
175+
}) {
176+
return (
177+
<div className={cn("flex w-full flex-col gap-2", className)}>
178+
{/* 第一行,标题行 */}
179+
<div className="text-panel-text my-2 flex items-center gap-2 pl-4 pt-4 text-lg underline">
180+
<span>{icon}</span>
181+
<span className="text-settings-text">{title}</span>
182+
</div>
183+
{/* 可能的描述行 */}
184+
{description && <div className="text-panel-details-text pl-4 text-xs">{description}</div>}
185+
{/* 内容 */}
186+
<div className="flex w-full flex-col gap-2 pl-6 text-sm">{children}</div>
187+
</div>
188+
);
189+
}

app/src/pages/settings/_layout.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,19 @@ export default function SettingsLayout() {
1818
<Info />
1919
{t("tabs.about")}
2020
</NavLink>
21+
{/* 越是用户可能频繁更改的,越靠上。(除了“关于”) */}
2122
<NavLink to="/settings/visual">
2223
<Eye />
2324
{t("tabs.visual")}
2425
</NavLink>
26+
<NavLink to="/settings/control">
27+
<Keyboard />
28+
{t("tabs.control")}
29+
</NavLink>
30+
<NavLink to="/settings/keybinds">
31+
<Command />
32+
{t("tabs.keybinds")}
33+
</NavLink>
2534
<NavLink to="/settings/performance">
2635
<Zap />
2736
{t("tabs.performance")}
@@ -34,14 +43,6 @@ export default function SettingsLayout() {
3443
<Bot />
3544
{t("tabs.automation")}
3645
</NavLink>
37-
<NavLink to="/settings/control">
38-
<Keyboard />
39-
{t("tabs.control")}
40-
</NavLink>
41-
<NavLink to="/settings/keybinds">
42-
<Command />
43-
{t("tabs.keybinds")}
44-
</NavLink>
4546
<NavLink to="/settings/ai">
4647
<Brain />
4748
{t("tabs.ai")}

app/src/pages/settings/control.tsx

Lines changed: 28 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,47 @@
11
import {
22
AlignStartVertical,
3+
Fullscreen,
4+
GitCompareArrows,
35
Keyboard,
46
ListCheck,
57
ListEnd,
8+
Mouse,
69
MousePointerClick,
710
Move,
811
RotateCw,
912
ScanEye,
1013
Skull,
14+
TextSelect,
1115
} from "lucide-react";
12-
import React from "react";
13-
import { useTranslation } from "react-i18next";
14-
import KeyBind from "../../components/KeyBind";
15-
import { KeyBinds } from "../../core/service/controlService/KeyBinds";
16-
import { Field, SettingField } from "./_field";
16+
import { FieldGroup, SettingField } from "./_field";
1717

1818
export default function Control() {
19-
const [keyBinds, setKeyBinds] = React.useState<[id: string, { key: string; modifiers: KeyBinds.KeyModifiers }][]>([]);
19+
return (
20+
<>
21+
<FieldGroup title="Mouse 鼠标设定" icon={<Mouse />}>
22+
<SettingField icon={<MousePointerClick />} settingKey="mouseRightDragBackground" type="select" />
23+
</FieldGroup>
2024

21-
React.useEffect(() => {
22-
KeyBinds.entries().then((entries) => {
23-
setKeyBinds(entries);
24-
});
25-
}, []);
25+
<FieldGroup title="TextNode 文本节点" icon={<TextSelect />}>
26+
<SettingField icon={<ListEnd />} settingKey="textNodeContentLineBreak" type="select" />
27+
<SettingField icon={<ListCheck />} settingKey="textNodeExitEditMode" type="select" />
28+
<SettingField icon={<AlignStartVertical />} settingKey="enableDragAutoAlign" type="switch" />
29+
</FieldGroup>
2630

27-
const { t } = useTranslation("keyBinds");
31+
<FieldGroup title="Edge 连线" icon={<GitCompareArrows />}>
32+
<SettingField icon={<RotateCw />} settingKey="allowAddCycleEdge" type="switch" />
33+
</FieldGroup>
2834

29-
return (
30-
<>
31-
<SettingField icon={<MousePointerClick />} settingKey="mouseRightDragBackground" type="select" />
32-
<SettingField icon={<ListEnd />} settingKey="textNodeContentLineBreak" type="select" />
33-
<SettingField icon={<ListCheck />} settingKey="textNodeExitEditMode" type="select" />
34-
<SettingField icon={<AlignStartVertical />} settingKey="enableDragAutoAlign" type="switch" />
35-
<SettingField icon={<ScanEye />} settingKey="scaleExponent" type="slider" min={0} max={1} step={0.01} />
36-
<SettingField icon={<ScanEye />} settingKey="scaleCameraByMouseLocation" type="switch" />
37-
<SettingField icon={<Keyboard />} settingKey="allowMoveCameraByWSAD" type="switch" />
38-
<SettingField icon={<Keyboard />} settingKey="cameraKeyboardMoveReverse" type="switch" />
39-
<SettingField icon={<RotateCw />} settingKey="allowAddCycleEdge" type="switch" />
40-
<SettingField icon={<Move />} settingKey="moveAmplitude" type="slider" min={0} max={10} step={0.1} />
41-
<SettingField icon={<Move />} settingKey="moveFriction" type="slider" min={0} max={1} step={0.01} />
42-
<SettingField icon={<Skull />} settingKey="gamepadDeadzone" type="slider" min={0} max={1} step={0.01} />
43-
<Field icon={<Keyboard />} title={t("title")} color="blue" />
44-
{keyBinds
45-
.map(([id, bind]) => (
46-
<Field
47-
key={id}
48-
icon={<Keyboard />}
49-
title={t(`${id}.title`, { defaultValue: id })}
50-
description={t(`${id}.description`, { defaultValue: "" })}
51-
>
52-
<KeyBind
53-
value={bind}
54-
onChange={(value) => {
55-
KeyBinds.set(id, value.key, value.modifiers);
56-
setKeyBinds((prev) => prev.map((item) => (item[0] === id ? [item[0], value] : item)));
57-
}}
58-
/>
59-
</Field>
60-
))
61-
.sort((a, b) => {
62-
if (a.key === null && b.key === null) return 0; // 两者均为 null,相等
63-
if (a.key === null) return 1; // a.key 为 null,把它排到后面
64-
if (b.key === null) return -1; // b.key 为 null,把它排到后面
65-
return a.key.localeCompare(b.key); // 正常比较
66-
})}
35+
<FieldGroup title="Camera 摄像机/视野/相关" icon={<Fullscreen />}>
36+
<SettingField icon={<ScanEye />} settingKey="scaleExponent" type="slider" min={0} max={1} step={0.01} />
37+
<SettingField icon={<ScanEye />} settingKey="scaleCameraByMouseLocation" type="switch" />
38+
<SettingField icon={<Keyboard />} settingKey="allowMoveCameraByWSAD" type="switch" />
39+
<SettingField icon={<Keyboard />} settingKey="cameraKeyboardMoveReverse" type="switch" />
40+
<SettingField icon={<Move />} settingKey="moveAmplitude" type="slider" min={0} max={10} step={0.1} />
41+
<SettingField icon={<Move />} settingKey="moveFriction" type="slider" min={0} max={1} step={0.01} />
42+
<SettingField icon={<Skull />} settingKey="gamepadDeadzone" type="slider" min={0} max={1} step={0.01} />
43+
</FieldGroup>
44+
{/* 已经有快捷键专栏了,这里不再显示快捷键相关 */}
6745
</>
6846
);
6947
}

0 commit comments

Comments
 (0)