[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

@@ -355,9 +355,9 @@ pub fn get_cs2_video(file_path: &str) -> Result<VideoConfig> {
let json_data = super::parse::to_json(&data); let json_data = super::parse::to_json(&data);
let kv: HashMap<String, String> = serde_json::from_str(&json_data)?; let kv: HashMap<String, String> = serde_json::from_str(&json_data)?;
let video_config = VideoConfig { let video_config = VideoConfig {
version: kv.get("version").unwrap_or(&"".to_string()).to_string(), version: kv.get("Version").unwrap_or(&"".to_string()).to_string(),
vendor_id: kv.get("vendor_id").unwrap_or(&"".to_string()).to_string(), vendor_id: kv.get("VendorID").unwrap_or(&"".to_string()).to_string(),
device_id: kv.get("device_id").unwrap_or(&"".to_string()).to_string(), device_id: kv.get("DeviceID").unwrap_or(&"".to_string()).to_string(),
cpu_level: kv cpu_level: kv
.get("setting.cpu_level") .get("setting.cpu_level")
.unwrap_or(&"".to_string()) .unwrap_or(&"".to_string())
@@ -414,7 +414,7 @@ pub fn get_cs2_video(file_path: &str) -> Result<VideoConfig> {
.get("setting.high_dpi") .get("setting.high_dpi")
.unwrap_or(&"".to_string()) .unwrap_or(&"".to_string())
.to_string(), .to_string(),
auto_config: kv.get("auto_config").unwrap_or(&"".to_string()).to_string(), auto_config: kv.get("AutoConfig").unwrap_or(&"".to_string()).to_string(),
shaderquality: kv shaderquality: kv
.get("setting.shaderquality") .get("setting.shaderquality")
.unwrap_or(&"".to_string()) .unwrap_or(&"".to_string())
@@ -486,6 +486,9 @@ pub fn set_cs2_video(file_path: &str, data: VideoConfig) -> Result<()> {
let updated_content = re.replace_all(&file_content, |caps: &regex::Captures| { let updated_content = re.replace_all(&file_content, |caps: &regex::Captures| {
let key = &caps[1]; // 捕获的键名 let key = &caps[1]; // 捕获的键名
let value = match key { let value = match key {
"Version" => &data.version,
"VendorID" => &data.vendor_id,
"DeviceID" => &data.device_id,
"setting.cpu_level" => &data.cpu_level, "setting.cpu_level" => &data.cpu_level,
"setting.gpu_mem_level" => &data.gpu_mem_level, "setting.gpu_mem_level" => &data.gpu_mem_level,
"setting.gpu_level" => &data.gpu_level, "setting.gpu_level" => &data.gpu_level,
@@ -500,6 +503,7 @@ pub fn set_cs2_video(file_path: &str, data: VideoConfig) -> Result<()> {
"setting.mat_vsync" => &data.mat_vsync, "setting.mat_vsync" => &data.mat_vsync,
"setting.fullscreen_min_on_focus_loss" => &data.fullscreen_min_on_focus_loss, "setting.fullscreen_min_on_focus_loss" => &data.fullscreen_min_on_focus_loss,
"setting.high_dpi" => &data.high_dpi, "setting.high_dpi" => &data.high_dpi,
"AutoConfig" => &data.auto_config,
"setting.shaderquality" => &data.shaderquality, "setting.shaderquality" => &data.shaderquality,
"setting.r_texturefilteringquality" => &data.r_texturefilteringquality, "setting.r_texturefilteringquality" => &data.r_texturefilteringquality,
"setting.msaa_samples" => &data.msaa_samples, "setting.msaa_samples" => &data.msaa_samples,

View File

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

View File

@@ -46,44 +46,44 @@ export interface VideoSetting {
} }
// 视频设置预设模版 // 视频设置预设模版
// TODO: 校准
export const VideoSettingTemplate = { export const VideoSettingTemplate = {
veryhigh: { veryhigh: {
shaderquality: "1", shaderquality: "1",
r_texturefilteringquality: "3", r_texturefilteringquality: "3",
msaa_samples: "8", msaa_samples: "8",
r_csgo_cmaa_enable: "0", r_csgo_cmaa_enable: "0",
videocfg_shadow_quality: "0", videocfg_shadow_quality: "3",
videocfg_dynamic_shadows: "1", videocfg_dynamic_shadows: "1",
videocfg_texture_detail: "1", videocfg_texture_detail: "2",
videocfg_particle_detail: "0", videocfg_particle_detail: "3",
videocfg_ao_detail: "0", videocfg_ao_detail: "3",
videocfg_hdr_detail: "3", videocfg_hdr_detail: "-1",
videocfg_fsr_detail: "0",
}, },
high: { high: {
shaderquality: "0", shaderquality: "1",
r_texturefilteringquality: "2", r_texturefilteringquality: "3",
msaa_samples: "4", msaa_samples: "4",
r_csgo_cmaa_enable: "0", r_csgo_cmaa_enable: "0",
videocfg_shadow_quality: "0", videocfg_shadow_quality: "2",
videocfg_dynamic_shadows: "1", videocfg_dynamic_shadows: "1",
videocfg_texture_detail: "1", videocfg_texture_detail: "2",
videocfg_particle_detail: "0", videocfg_particle_detail: "2",
videocfg_ao_detail: "0", videocfg_ao_detail: "2",
videocfg_hdr_detail: "3", videocfg_hdr_detail: "-1",
videocfg_fsr_detail: "0", videocfg_fsr_detail: "0",
}, },
middle: { middle: {
shaderquality: "0", shaderquality: "0",
r_texturefilteringquality: "2", r_texturefilteringquality: "1",
msaa_samples: "2", msaa_samples: "2",
r_csgo_cmaa_enable: "0", r_csgo_cmaa_enable: "0",
videocfg_shadow_quality: "0", videocfg_shadow_quality: "1",
videocfg_dynamic_shadows: "1", videocfg_dynamic_shadows: "1",
videocfg_texture_detail: "1", videocfg_texture_detail: "1",
videocfg_particle_detail: "0", videocfg_particle_detail: "1",
videocfg_ao_detail: "0", videocfg_ao_detail: "0",
videocfg_fsr_detail: "1", videocfg_fsr_detail: "2",
}, },
low: { low: {
shaderquality: "0", shaderquality: "0",
@@ -91,11 +91,12 @@ export const VideoSettingTemplate = {
msaa_samples: "0", msaa_samples: "0",
r_csgo_cmaa_enable: "0", r_csgo_cmaa_enable: "0",
videocfg_shadow_quality: "0", videocfg_shadow_quality: "0",
videocfg_dynamic_shadows: "1", videocfg_dynamic_shadows: "0",
videocfg_texture_detail: "1", videocfg_texture_detail: "0",
videocfg_particle_detail: "0", videocfg_particle_detail: "0",
videocfg_ao_detail: "0", videocfg_ao_detail: "0",
videocfg_fsr_detail: "2", videocfg_hdr_detail: "3",
videocfg_fsr_detail: "3",
}, },
recommend: { recommend: {
shaderquality: "0", shaderquality: "0",
@@ -107,6 +108,7 @@ export const VideoSettingTemplate = {
videocfg_texture_detail: "1", videocfg_texture_detail: "1",
videocfg_particle_detail: "0", videocfg_particle_detail: "0",
videocfg_ao_detail: "0", videocfg_ao_detail: "0",
videocfg_hdr_detail: "3",
videocfg_fsr_detail: "0", videocfg_fsr_detail: "0",
}, },
} }