[feat] enable tab switch in edit mode

This commit is contained in:
Purp1e
2025-03-27 17:36:04 +08:00
parent a10cf8eddf
commit 0e7e6dd3ba
3 changed files with 230 additions and 56 deletions

View File

@@ -19,24 +19,63 @@ const VideoSetting = () => {
title: "全屏",
value: video.fullscreen === "1" ? "全屏" : "窗口",
options: ["窗口", "全屏"],
mapping: (value: string) => {
return (
{
: "0",
: "1",
}[value] || "0"
)
},
},
{
type: "mat_vsync",
title: "垂直同步",
value: video.mat_vsync === "1" ? "开启" : "关闭",
options: ["关闭", "开启"],
mapping: (value: string) => {
return (
{
: "0",
: "1",
}[value] || "0"
)
},
},
{
type: "r_low_latency",
title: "低延迟模式",
value: video.r_low_latency === "1" ? "开启" : "关闭",
options: ["关闭", "开启"],
mapping: (value: string) => {
return (
{
: "0",
: "1",
}[value] || "0"
)
},
},
// TODO: 改选项不在 cs2_video.txt 中
// {
// type: "r_player_visible_mode",
// title: "增强角色对比度",
// value: video.r_csgo_cmaa_enable === "1" ? "启用" : "禁用",
// options: ["禁用", "启用"],
// },
{
type: "r_csgo_cmaa_enable",
title: "增强角色对比度",
value: video.r_csgo_cmaa_enable === "1" ? "启" : "禁用",
options: ["禁用", "启"],
title: "CMAA2抗锯齿",
value: video.r_csgo_cmaa_enable === "1" ? "启" : "关闭",
options: ["关闭", "启"],
mapping: (value: string) => {
return (
{
: "0",
: "1",
}[value] || "0"
)
},
},
{
type: "msaa_samples",
@@ -49,24 +88,61 @@ const VideoSetting = () => {
8: "8X MSAA",
}[parseInt(video.msaa_samples, 10)] || "无",
options: ["无", "2X MSAA", "4X MSAA", "8X MSAA"],
mapping: (value: string) => {
return (
{
: 0,
"2X MSAA": 2,
"4X MSAA": 4,
"8X MSAA": 8,
}[value] || "0"
)
},
},
{
type: "videocfg_shadow_quality",
title: "全局阴影效果",
value: ["低", "中", "高", "非常高"][parseInt(video.videocfg_shadow_quality, 10)] || "低",
options: ["低", "中", "高", "非常高"],
mapping: (value: string) => {
return (
{
: "0",
: "1",
: "2",
: "3",
}[value] || "0"
)
},
},
{
type: "videocfg_dynamic_shadows",
title: "动态阴影",
value: ["仅限日光", "全部"][parseInt(video.videocfg_dynamic_shadows, 10)] || "仅限日光",
options: ["仅限日光", "全部"],
mapping: (value: string) => {
return (
{
: "0",
: "1",
}[value] || "0"
)
},
},
{
type: "videocfg_texture_detail",
title: "模型/贴图细节",
value: ["低", "中", "高"][parseInt(video.videocfg_texture_detail, 10)] || "低",
options: ["低", "中", "高"],
mapping: (value: string) => {
return (
{
: "0",
: "1",
: "2",
}[value] || "0"
)
},
},
{
type: "r_texturefilteringquality",
@@ -76,24 +152,67 @@ const VideoSetting = () => {
parseInt(video.r_texturefilteringquality, 10)
] || "双线性",
options: ["双线性", "三线性", "异向 2X", "异向 4X", "异向 8X", "异向 16X"],
mapping: (value: string) => {
return (
{
线: "0",
线: "1",
"异向 2X": "2",
"异向 4X": "3",
"异向 8X": "4",
"异向 16X": "5",
}[value] || "0"
)
},
},
{
type: "videocfg_hdr_detail",
title: "光影细节",
value: ["低", "高"][parseInt(video.shaderquality, 10)] || "低",
value:
{
"3": "低",
"-1": "高",
}[parseInt(video.videocfg_hdr_detail, 10)] || "低",
options: ["低", "高"],
mapping: (value: string) => {
return (
{
: "3",
: "-1",
}[value] || "3"
)
},
},
{
type: "videocfg_particle_detail",
title: "粒子细节",
value: ["低", "中", "高", "非常高"][parseInt(video.videocfg_particle_detail, 10)] || "低",
options: ["低", "中", "高", "非常高"],
mapping: (value: string) => {
return (
{
: "0",
: "1",
: "2",
: "3",
}[value] || "低"
)
},
},
{
type: "videocfg_ao_detail",
title: "环境光遮蔽",
value: ["已禁用", "中", "高"][parseInt(video.videocfg_ao_detail, 10)] || "已禁用",
options: ["已禁用", "中", "高"],
mapping: (value: string) => {
return (
{
: "0",
: "1",
: "2",
}[value] || "已禁用"
)
},
},
{
type: "videocfg_fsr_detail",
@@ -102,6 +221,17 @@ const VideoSetting = () => {
["已禁用", "超高品质", "品质", "均衡", "性能"][parseInt(video.videocfg_fsr_detail, 10)] ||
"性能",
options: ["性能", "均衡", "品质", "超高品质", "已禁用"],
mapping: (value: string) => {
return (
{
: "0",
: "1",
: "2",
: "3",
: "4",
}[value] || "已禁用"
)
},
},
]
}
@@ -109,8 +239,8 @@ const VideoSetting = () => {
const [vconfig, setVconfig] = useState<VideoConfig>(tool.state.videoSetting)
useEffect(() => {
console.log("讀取設置")
void tool.getVideoConfig(steam.state.steamDir, steam.currentUser()?.steam_id32 || 0)
if (steam.state.steamDirValid && steam.currentUser())
void tool.getVideoConfig(steam.state.steamDir, steam.currentUser()?.steam_id32 || 0)
}, [])
return (
@@ -127,11 +257,27 @@ const VideoSetting = () => {
))} */}
{edit && (
<>
<ToolButton onClick={() => setVconfig({ ...vconfig, ...VideoSettingTemplate.low })}></ToolButton>
<ToolButton onClick={() => setVconfig({ ...vconfig, ...VideoSettingTemplate.middle })}></ToolButton>
<ToolButton onClick={() => setVconfig({ ...vconfig, ...VideoSettingTemplate.high })}></ToolButton>
<ToolButton onClick={() => setVconfig({ ...vconfig, ...VideoSettingTemplate.veryhigh })}></ToolButton>
<ToolButton onClick={() => setVconfig({ ...vconfig, ...VideoSettingTemplate.recommend })}></ToolButton>
<ToolButton onClick={() => setVconfig({ ...vconfig, ...VideoSettingTemplate.low })}>
</ToolButton>
<ToolButton
onClick={() => setVconfig({ ...vconfig, ...VideoSettingTemplate.middle })}
>
</ToolButton>
<ToolButton onClick={() => setVconfig({ ...vconfig, ...VideoSettingTemplate.high })}>
</ToolButton>
<ToolButton
onClick={() => setVconfig({ ...vconfig, ...VideoSettingTemplate.veryhigh })}
>
</ToolButton>
<ToolButton
onClick={() => setVconfig({ ...vconfig, ...VideoSettingTemplate.recommend })}
>
</ToolButton>
<ToolButton
onClick={async () => {
await tool.setVideoConfig(
@@ -139,7 +285,10 @@ const VideoSetting = () => {
steam.currentUser()?.steam_id32 || 0,
vconfig
)
await tool.getVideoConfig(steam.state.steamDir, steam.currentUser()?.steam_id32 || 0)
await tool.getVideoConfig(
steam.state.steamDir,
steam.currentUser()?.steam_id32 || 0
)
setEdit(false)
addToast({ title: "应用设置成功" })
}}
@@ -149,28 +298,37 @@ const VideoSetting = () => {
</ToolButton>
</>
)}
<ToolButton onClick={async() => {
await tool.getVideoConfig(steam.state.steamDir, steam.currentUser()?.steam_id32 || 0)
<ToolButton
onClick={async () => {
if (steam.state.steamDirValid && steam.currentUser())
await tool.getVideoConfig(
steam.state.steamDir,
steam.currentUser()?.steam_id32 || 0
)
setVconfig(tool.state.videoSetting)
setEdit(!edit)
}}>
{edit ? (
<>
<CloseSmall />
</>
) : (
<>
<Edit />
</>
)}
</ToolButton>
}}
>
{edit ? (
<>
<CloseSmall />
</>
) : (
<>
<Edit />
</>
)}
</ToolButton>
<ToolButton
onClick={() =>
void tool.getVideoConfig(steam.state.steamDir, steam.currentUser()?.steam_id32 || 0)
}
onClick={async () => {
if (steam.state.steamDirValid && steam.currentUser()) {
void tool.getVideoConfig(steam.state.steamDir, steam.currentUser()?.steam_id32 || 0)
addToast({ title: "读取成功" })
} else addToast({ title: "请先选择用户", color: "danger" })
}}
>
</ToolButton>
@@ -243,14 +401,24 @@ const VideoSetting = () => {
<li className="flex flex-col gap-1.5" key={index}>
<span className="ml-2">{vid.title}</span>
<Tabs
selectedKey={vid.value}
size="md"
radius="full"
className="min-w-36"
fullWidth
selectedKey={vid.value}
onSelectionChange={(key) => {
console.log(vid.type, key)
// 修改 vconfig 名为 vid.type 的 value为 key
edit && key
? setVconfig({
...vconfig,
[vid.type]: vid.mapping?.(key.toString()),
})
: null
}}
>
{vid.options.map((opt, _) => (
<Tab key={opt} title={opt} />
<Tab key={opt} title={opt} titleValue={opt} />
))}
</Tabs>
</li>