From a32306b9ba60af64c21027f14874440af6d54777 Mon Sep 17 00:00:00 2001 From: zty012 Date: Fri, 6 Dec 2024 20:43:16 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20FileChooser=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ui/FileChooser.tsx | 32 +++++++++++++++++++++++ src/pages/settings/_field.tsx | 42 +++++++++--------------------- src/pages/settings/automation.tsx | 14 ---------- src/pages/settings/control.tsx | 12 --------- src/pages/settings/performance.tsx | 19 +++++--------- src/pages/settings/sounds.tsx | 16 +++--------- src/pages/test.tsx | 41 +++-------------------------- 7 files changed, 59 insertions(+), 117 deletions(-) create mode 100644 src/components/ui/FileChooser.tsx diff --git a/src/components/ui/FileChooser.tsx b/src/components/ui/FileChooser.tsx new file mode 100644 index 0000000..ab8759f --- /dev/null +++ b/src/components/ui/FileChooser.tsx @@ -0,0 +1,32 @@ +import { open } from "@tauri-apps/plugin-dialog"; +import { FolderOpen } from "lucide-react"; +import Button from "./Button"; +import Input from "./Input"; + +export default function FileChooser({ + kind, + value = "", + onChange = () => {}, +}: { + kind: "file" | "directory"; + value?: string; + onChange?: (value: string) => void; +}) { + return ( +
+ + +
+ ); +} diff --git a/src/pages/settings/_field.tsx b/src/pages/settings/_field.tsx index f474f26..e2e5ef6 100644 --- a/src/pages/settings/_field.tsx +++ b/src/pages/settings/_field.tsx @@ -1,7 +1,7 @@ -import { RotateCw } from "lucide-react"; import React from "react"; import { useTranslation } from "react-i18next"; import Button from "../../components/ui/Button"; +import FileChooser from "../../components/ui/FileChooser"; import Input from "../../components/ui/Input"; import Select from "../../components/ui/Select"; import Slider from "../../components/ui/Slider"; @@ -17,14 +17,16 @@ export function SettingField({ step = 1, placeholder = "", icon = <>, + kind = "file", }: { settingKey: keyof Settings.Settings; - type?: "text" | "number" | "slider" | "switch" | "select"; + type?: "text" | "number" | "slider" | "switch" | "select" | "file"; min?: number; max?: number; step?: number; placeholder?: string; icon?: React.ReactNode; + kind?: "file" | "directory"; }) { const [value, setValue] = React.useState(); const { t, i18n } = useTranslation("settings"); @@ -45,32 +47,11 @@ export function SettingField({ }, [value]); return ( -
-
- {icon} -
- {t(`${settingKey}.title`)} -
- {t(`${settingKey}.description`, { defaultValue: "" }) - .split("\n") - .map((dd, ii) => ( -

- {dd} -

- ))} -
- {settingKey} -
-
-
- + {type === "text" && ( )} @@ -100,7 +81,10 @@ export function SettingField({ }))} > )} -
+ {type === "file" && ( + + )} + ); } export function ButtonField({ diff --git a/src/pages/settings/automation.tsx b/src/pages/settings/automation.tsx index c0e4a66..fd9424f 100644 --- a/src/pages/settings/automation.tsx +++ b/src/pages/settings/automation.tsx @@ -18,30 +18,22 @@ export default function AutoNamer() { } settingKey="autoNamerTemplate" - title={t("autoNamerTemplate.title")} - details={t("autoNamerTemplate.description")} type="text" placeholder="例如:p{{i}}" /> } settingKey="autoSaveWhenClose" - title={t("autoSaveWhenClose.title")} - details={t("autoSaveWhenClose.description")} type="switch" /> } settingKey="autoSave" - title={t("autoSave.title")} - details={t("autoSave.description")} type="switch" /> } settingKey="autoSaveInterval" - title={t("autoSaveInterval.title")} - details={t("autoSaveInterval.description")} type="slider" min={1} max={60} @@ -50,15 +42,11 @@ export default function AutoNamer() { } settingKey="autoBackup" - title={t("autoBackup.title")} - details={t("autoBackup.description")} type="switch" /> } settingKey="autoBackupInterval" - title={t("autoBackupInterval.title")} - details={t("autoBackupInterval.description")} type="slider" min={60} max={6000} @@ -67,8 +55,6 @@ export default function AutoNamer() { } settingKey="autoBackupDraftPath" - title={t("autoBackupDraftPath.title")} - details={t("autoBackupDraftPath.description")} type="text" /> diff --git a/src/pages/settings/control.tsx b/src/pages/settings/control.tsx index b1c4908..64bdbb3 100644 --- a/src/pages/settings/control.tsx +++ b/src/pages/settings/control.tsx @@ -1,17 +1,12 @@ import { Keyboard, Move, ScanEye, Skull } from "lucide-react"; import { SettingField } from "./_field"; -import { useTranslation } from "react-i18next"; export default function Control() { - const { t } = useTranslation("settingsControl"); - return ( <> } settingKey="scaleExponent" - title={t("scaleExponent.title")} - details={t("scaleExponent.description")} type="slider" min={0} max={1} @@ -20,15 +15,11 @@ export default function Control() { } settingKey="allowMoveCameraByWSAD" - title={"允许使用“WSAD”键来控制视角移动"} - details={"WSAD"} type="switch" /> } settingKey="moveAmplitude" - title={t("moveAmplitude.title")} - details={t("moveAmplitude.description")} type="slider" min={0} max={10} @@ -37,8 +28,6 @@ export default function Control() { } settingKey="moveFriction" - title={t("moveFriction.title")} - details={t("moveFriction.description")} type="slider" min={0} max={1} @@ -47,7 +36,6 @@ export default function Control() { } settingKey="gamepadDeadzone" - title={t("gamepadDeadzone")} type="slider" min={0} max={1} diff --git a/src/pages/settings/performance.tsx b/src/pages/settings/performance.tsx index cd27f4f..8456750 100644 --- a/src/pages/settings/performance.tsx +++ b/src/pages/settings/performance.tsx @@ -1,27 +1,22 @@ -import { useTranslation } from "react-i18next"; -import { SettingField } from "./_field"; import { Sparkles, SquareStack } from "lucide-react"; +import { SettingField } from "./_field"; export default function Performance() { - - const { t } = useTranslation("settingsPerformance"); - - return <> - + } settingKey="renderEffect" - title={t("renderEffect")} type="switch" /> - } settingKey="historySize" - title={t("historySize.title")} - details={t("historySize.description")} type="slider" min={10} max={1000} step={10} /> - ; + + ); } diff --git a/src/pages/settings/sounds.tsx b/src/pages/settings/sounds.tsx index c64816b..0a8abd6 100644 --- a/src/pages/settings/sounds.tsx +++ b/src/pages/settings/sounds.tsx @@ -7,30 +7,22 @@ export default function Sounds() { } settingKey="cuttingLineStartSoundFile" - title={"切割线开始音效"} - details={"右键按下时刚开始创建切割线准备切割东西时播放的音效文件。"} - type="text" + type="file" /> } settingKey="connectLineStartSoundFile" - title={"连接线开始音效"} - details={"右键按下时刚开始创建连接时播放的音效文件。"} - type="text" + type="file" /> } settingKey="connectFindTargetSoundFile" - title={"连接线查找目标音效"} - details={"当"} - type="text" + type="file" /> } settingKey="cuttingLineReleaseSoundFile" - title={"切断线释放特效"} - details={"纯粹解压用的"} - type="text" + type="file" /> ); diff --git a/src/pages/test.tsx b/src/pages/test.tsx index 5b7cb99..138a238 100644 --- a/src/pages/test.tsx +++ b/src/pages/test.tsx @@ -1,28 +1,21 @@ -import { invoke } from "@tauri-apps/api/core"; import { TestTube2 } from "lucide-react"; import React from "react"; -import { useTranslation } from "react-i18next"; import Button from "../components/ui/Button"; +import FileChooser from "../components/ui/FileChooser"; import IconButton from "../components/ui/IconButton"; import Input from "../components/ui/Input"; import Switch from "../components/ui/Switch"; -import { LastLaunch } from "../core/LastLaunch"; -import { StageDumper } from "../core/stage/StageDumper"; import { usePopupDialog } from "../utils/popupDialog"; -import { XML } from "../utils/xml"; -import { SoundService } from "../core/SoundService"; export default function TestPage() { const [switchValue, setSwitchValue] = React.useState(false); + const [file, setFile] = React.useState(""); const popupDialog = usePopupDialog(); - const { t } = useTranslation(); const popup = () => { popupDialog.show(<>test); }; - const handleTestHttp = async () => {}; - return (
@@ -31,35 +24,7 @@ export default function TestPage() { setSwitchValue(e)} /> - {t("test")} -

test xml:

- {new XML("ompl") - .attr("version", "2.0") - .add("head") - .add("title") - .text("test") - .up() - .up() - .add("body") - .toString()} -
-
-

序列化信息

-
-          {JSON.stringify(StageDumper.dump(), null, 2)}
-        
-
- - - - last launch: {LastLaunch.version} + setFile(e)} />
); } - -function handleTestImageBase64() { - invoke("convert_image_to_base64", { - imagePath: - "D:\\Projects\\Project-Tools\\project-graph\\src\\assets\\icon.png", - }).then((_res) => {}); -}