From 0e7e6dd3baed3623e9ec52b794cb706808b6f2e1 Mon Sep 17 00:00:00 2001 From: Purp1e <47248616+Purple-CSGO@users.noreply.github.com> Date: Thu, 27 Mar 2025 17:36:04 +0800 Subject: [PATCH] [feat] enable tab switch in edit mode --- src-tauri/src/vdf/preset.rs | 12 +- src/components/cstb/VideoSetting.tsx | 232 +++++++++++++++++++++++---- src/store/tool.ts | 42 ++--- 3 files changed, 230 insertions(+), 56 deletions(-) diff --git a/src-tauri/src/vdf/preset.rs b/src-tauri/src/vdf/preset.rs index a290659..297b390 100644 --- a/src-tauri/src/vdf/preset.rs +++ b/src-tauri/src/vdf/preset.rs @@ -355,9 +355,9 @@ pub fn get_cs2_video(file_path: &str) -> Result { let json_data = super::parse::to_json(&data); let kv: HashMap = serde_json::from_str(&json_data)?; let video_config = VideoConfig { - version: kv.get("version").unwrap_or(&"".to_string()).to_string(), - vendor_id: kv.get("vendor_id").unwrap_or(&"".to_string()).to_string(), - device_id: kv.get("device_id").unwrap_or(&"".to_string()).to_string(), + version: kv.get("Version").unwrap_or(&"".to_string()).to_string(), + vendor_id: kv.get("VendorID").unwrap_or(&"".to_string()).to_string(), + device_id: kv.get("DeviceID").unwrap_or(&"".to_string()).to_string(), cpu_level: kv .get("setting.cpu_level") .unwrap_or(&"".to_string()) @@ -414,7 +414,7 @@ pub fn get_cs2_video(file_path: &str) -> Result { .get("setting.high_dpi") .unwrap_or(&"".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 .get("setting.shaderquality") .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: ®ex::Captures| { let key = &caps[1]; // 捕获的键名 let value = match key { + "Version" => &data.version, + "VendorID" => &data.vendor_id, + "DeviceID" => &data.device_id, "setting.cpu_level" => &data.cpu_level, "setting.gpu_mem_level" => &data.gpu_mem_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.fullscreen_min_on_focus_loss" => &data.fullscreen_min_on_focus_loss, "setting.high_dpi" => &data.high_dpi, + "AutoConfig" => &data.auto_config, "setting.shaderquality" => &data.shaderquality, "setting.r_texturefilteringquality" => &data.r_texturefilteringquality, "setting.msaa_samples" => &data.msaa_samples, diff --git a/src/components/cstb/VideoSetting.tsx b/src/components/cstb/VideoSetting.tsx index e3f7b2c..f6e29b0 100644 --- a/src/components/cstb/VideoSetting.tsx +++ b/src/components/cstb/VideoSetting.tsx @@ -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(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 && ( <> - setVconfig({ ...vconfig, ...VideoSettingTemplate.low })}>低 - setVconfig({ ...vconfig, ...VideoSettingTemplate.middle })}>中 - setVconfig({ ...vconfig, ...VideoSettingTemplate.high })}>高 - setVconfig({ ...vconfig, ...VideoSettingTemplate.veryhigh })}>非常高 - setVconfig({ ...vconfig, ...VideoSettingTemplate.recommend })}>推荐 + setVconfig({ ...vconfig, ...VideoSettingTemplate.low })}> + 低 + + setVconfig({ ...vconfig, ...VideoSettingTemplate.middle })} + > + 中 + + setVconfig({ ...vconfig, ...VideoSettingTemplate.high })}> + 高 + + setVconfig({ ...vconfig, ...VideoSettingTemplate.veryhigh })} + > + 非常高 + + setVconfig({ ...vconfig, ...VideoSettingTemplate.recommend })} + > + 推荐 + { 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 = () => { )} - { - await tool.getVideoConfig(steam.state.steamDir, steam.currentUser()?.steam_id32 || 0) + { + if (steam.state.steamDirValid && steam.currentUser()) + await tool.getVideoConfig( + steam.state.steamDir, + steam.currentUser()?.steam_id32 || 0 + ) setVconfig(tool.state.videoSetting) setEdit(!edit) - }}> - {edit ? ( - <> - - 取消编辑 - - ) : ( - <> - - 编辑 - - )} - + }} + > + {edit ? ( + <> + + 取消编辑 + + ) : ( + <> + + 编辑 + + )} + - 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" }) + }} > 读取 @@ -243,14 +401,24 @@ const VideoSetting = () => {
  • {vid.title} { + 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, _) => ( - + ))}
  • diff --git a/src/store/tool.ts b/src/store/tool.ts index 114ce74..0b4a7d8 100644 --- a/src/store/tool.ts +++ b/src/store/tool.ts @@ -46,44 +46,44 @@ export interface VideoSetting { } // 视频设置预设模版 -// TODO: 校准 export const VideoSettingTemplate = { veryhigh: { shaderquality: "1", r_texturefilteringquality: "3", msaa_samples: "8", r_csgo_cmaa_enable: "0", - videocfg_shadow_quality: "0", + videocfg_shadow_quality: "3", videocfg_dynamic_shadows: "1", - videocfg_texture_detail: "1", - videocfg_particle_detail: "0", - videocfg_ao_detail: "0", - videocfg_hdr_detail: "3", + videocfg_texture_detail: "2", + videocfg_particle_detail: "3", + videocfg_ao_detail: "3", + videocfg_hdr_detail: "-1", + videocfg_fsr_detail: "0", }, high: { - shaderquality: "0", - r_texturefilteringquality: "2", + shaderquality: "1", + r_texturefilteringquality: "3", msaa_samples: "4", r_csgo_cmaa_enable: "0", - videocfg_shadow_quality: "0", + videocfg_shadow_quality: "2", videocfg_dynamic_shadows: "1", - videocfg_texture_detail: "1", - videocfg_particle_detail: "0", - videocfg_ao_detail: "0", - videocfg_hdr_detail: "3", + videocfg_texture_detail: "2", + videocfg_particle_detail: "2", + videocfg_ao_detail: "2", + videocfg_hdr_detail: "-1", videocfg_fsr_detail: "0", }, middle: { shaderquality: "0", - r_texturefilteringquality: "2", + r_texturefilteringquality: "1", msaa_samples: "2", r_csgo_cmaa_enable: "0", - videocfg_shadow_quality: "0", + videocfg_shadow_quality: "1", videocfg_dynamic_shadows: "1", videocfg_texture_detail: "1", - videocfg_particle_detail: "0", + videocfg_particle_detail: "1", videocfg_ao_detail: "0", - videocfg_fsr_detail: "1", + videocfg_fsr_detail: "2", }, low: { shaderquality: "0", @@ -91,11 +91,12 @@ export const VideoSettingTemplate = { msaa_samples: "0", r_csgo_cmaa_enable: "0", videocfg_shadow_quality: "0", - videocfg_dynamic_shadows: "1", - videocfg_texture_detail: "1", + videocfg_dynamic_shadows: "0", + videocfg_texture_detail: "0", videocfg_particle_detail: "0", videocfg_ao_detail: "0", - videocfg_fsr_detail: "2", + videocfg_hdr_detail: "3", + videocfg_fsr_detail: "3", }, recommend: { shaderquality: "0", @@ -107,6 +108,7 @@ export const VideoSettingTemplate = { videocfg_texture_detail: "1", videocfg_particle_detail: "0", videocfg_ao_detail: "0", + videocfg_hdr_detail: "3", videocfg_fsr_detail: "0", }, }