diff --git a/CHANGELOG.md b/CHANGELOG.md index 55fd9337..8576f20c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ User-facing changes only. The release workflow publishes the matching ### Fixed +- Crosshair and Sounds: when another pack replaces the same files, Show in Mods now opens Custom + packs with that pack marked, instead of only opening Mods. +- HUD and Viewmodels: importing something that belongs in Mods now says so and offers Open Mods, + instead of only failing. +- HUD: an imported HUD that is also in the catalog now offers Match to catalog, so it can get + updates. The button was missing for imported HUDs. - Mods: when a mod you import or download turns out to be a HUD, the file review now offers Install as HUD. Before, the install was refused and you had to import the file again in HUD. - Mods: a HUD found on GameBanana can now be installed from its card with Install HUD. Open HUD diff --git a/apps/desktop/src-tauri/core/src/hud.rs b/apps/desktop/src-tauri/core/src/hud.rs index 03f306e4..50fbc836 100644 --- a/apps/desktop/src-tauri/core/src/hud.rs +++ b/apps/desktop/src-tauri/core/src/hud.rs @@ -725,12 +725,14 @@ fn finish_extracted(raw: Vec<(String, Vec)>) -> Result Result<(), ProfileError> { - let info = tree.info_vdf().ok_or_else(|| { - ProfileError::Io( - "No HUD folder was found (missing info.vdf). Choose a complete HUD download or its extracted HUD folder.".into(), - ) - })?; + let info = tree + .info_vdf() + .ok_or_else(|| ProfileError::Io(NO_HUD_FOUND.into()))?; match std::str::from_utf8(info).ok().and_then(parse_ui_version) { Some(CURRENT_HUD_UI_VERSION) => Ok(()), Some(version) => Err(ProfileError::Io(format!( diff --git a/apps/desktop/src-tauri/core/src/viewmodel.rs b/apps/desktop/src-tauri/core/src/viewmodel.rs index a571cf0b..023cdf71 100644 --- a/apps/desktop/src-tauri/core/src/viewmodel.rs +++ b/apps/desktop/src-tauri/core/src/viewmodel.rs @@ -1081,6 +1081,9 @@ fn validate_viewmodel_import_metadata( Ok(()) } +/// Ends the refusal for a VPK that carries more than viewmodels. +pub const MIXED_VIEWMODEL_PACK: &str = "Import mixed-content packs through Mods."; + /// A custom VPK mounts every member as game content. Keep the Viewmodels /// shortcut limited to compiled first-person weapon models; mixed packs belong /// in Mods, where CFG members receive their separate trust review. @@ -1089,7 +1092,7 @@ fn validate_viewmodel_vpk(bytes: &[u8]) -> Result<(), ProfileError> { validate_vpk_dir_bytes_with_paths(bytes, &mut |path| { if !is_viewmodel_member(path) { return Err(VpkError(format!( - "Viewmodel VPK contains unrelated content: {path}. Import mixed-content packs through Mods." + "Viewmodel VPK contains unrelated content: {path}. {MIXED_VIEWMODEL_PACK}" ))); } if path.to_ascii_lowercase().ends_with(".mdl") { diff --git a/apps/desktop/src-tauri/src/commands/hud.rs b/apps/desktop/src-tauri/src/commands/hud.rs index 55590b9c..f8dca382 100644 --- a/apps/desktop/src-tauri/src/commands/hud.rs +++ b/apps/desktop/src-tauri/src/commands/hud.rs @@ -377,8 +377,13 @@ pub(super) fn install_local_hud( // These errors describe rejected input before any profile write. Keep the // core error code without its generic profile-library write failure prefix. +// A pick with no `info.vdf` gets its own code so the HUD pane can point an +// ordinary mod to Mods. pub(super) fn hud_input_error(error: execs_core::ProfileError) -> CommandError { match error { + execs_core::ProfileError::Io(message) if message == execs_core::hud::NO_HUD_FOUND => { + CommandError::new("NotAHud", message) + } execs_core::ProfileError::Io(message) => CommandError::new("Io", message), other => other.into(), } @@ -721,6 +726,13 @@ mod tests { assert!(invalid.message.contains("not a ZIP, 7z or RAR")); assert!(!invalid.message.contains("profile library")); + // An ordinary mod has no info.vdf; its own code lets the pane offer Mods. + let not_a_hud = hud_input_error(execs_core::ProfileError::Io( + execs_core::hud::NO_HUD_FOUND.into(), + )); + assert_eq!(not_a_hud.code, "NotAHud"); + assert_eq!(not_a_hud.message, execs_core::hud::NO_HUD_FOUND); + let lock = hud_input_error(execs_core::ProfileError::GameRunning); assert_eq!(lock.code, "GameRunning"); assert_eq!( diff --git a/apps/desktop/src-tauri/src/commands/viewmodel.rs b/apps/desktop/src-tauri/src/commands/viewmodel.rs index bf5ed25f..ae5b5863 100644 --- a/apps/desktop/src-tauri/src/commands/viewmodel.rs +++ b/apps/desktop/src-tauri/src/commands/viewmodel.rs @@ -519,17 +519,26 @@ pub async fn import_viewmodels( with_profile(move |root, profile_id| { context.ensure_current(&root, &profile_id)?; ensure_viewmodel_unchanged(&profile_id, initial_viewmodel.as_ref())?; - Ok(execs_core::import_viewmodel_vpk( - &root, - &profile_id, - &bytes, - preload, - )?) + execs_core::import_viewmodel_vpk(&root, &profile_id, &bytes, preload) + .map_err(viewmodel_input_error) }) .await .map(Some) } +// A VPK with more than viewmodels gets its own code so the pane can point it +// to Mods. +fn viewmodel_input_error(error: execs_core::ProfileError) -> CommandError { + match error { + execs_core::ProfileError::Io(message) + if message.ends_with(execs_core::viewmodel::MIXED_VIEWMODEL_PACK) => + { + CommandError::new("ViewmodelMixedContent", message) + } + other => other.into(), + } +} + fn ensure_viewmodel_unchanged( profile_id: &str, expected: Option<&execs_core::ViewmodelRecord>, diff --git a/apps/desktop/src/CrosshairPane.tsx b/apps/desktop/src/CrosshairPane.tsx index 1d255c44..328d5be8 100644 --- a/apps/desktop/src/CrosshairPane.tsx +++ b/apps/desktop/src/CrosshairPane.tsx @@ -174,7 +174,8 @@ export function CrosshairPane({ onDeactivate?: (stock?: { file: string; scale: number }) => Promise; stockArtSources?: ContentIndex | null; sourceStatus?: CrosshairSourceStatus | null; - onOpenMods?: () => void; + /** Shows the named `tf/custom` pack in Mods → Custom packs. */ + onOpenMods?: (pack: string) => void; hudOverlayState?: "enabled" | "disabled" | "possible" | "none"; hudName?: string; onOpenHud?: () => void; @@ -559,8 +560,12 @@ export function CrosshairPane({ different art.

{onOpenMods ? ( - ) : null} diff --git a/apps/desktop/src/HudPane.tsx b/apps/desktop/src/HudPane.tsx index 5947611d..f88ac638 100644 --- a/apps/desktop/src/HudPane.tsx +++ b/apps/desktop/src/HudPane.tsx @@ -50,6 +50,7 @@ import { HUD_SORTS, hudAuthorCopy, hudCatalogControls, + hudCatalogMatch, hudDisplayName, hudInstallSourceCopy, hudOptionsDirty, @@ -116,6 +117,9 @@ export function HudPane({ onApplyOptions, onImportArchive, onImportFolder, + modsImportHint = null, + onOpenMods, + onDismissModsImportHint, }: { api: Api; /** The profile this draft belongs to; a switch discards it. */ @@ -147,6 +151,10 @@ export function HudPane({ /** Install a HUD from a ZIP, 7z or RAR, or a folder on this computer. */ onImportArchive: () => HudMutationResult; onImportFolder: () => HudMutationResult; + /** Why the last import was refused as not being a HUD; it may be a mod. */ + modsImportHint?: string | null; + onOpenMods?: () => void; + onDismissModsImportHint?: () => void; }) { const { running, busy, setError } = useAppStatus(); const active = useContext(AutosaveActivity); @@ -224,6 +232,7 @@ export function HudPane({ const installedEntry = installedId ? (catalog.find((entry) => entry.id.toLowerCase() === installedId.toLowerCase()) ?? null) : null; + const catalogMatch = hudCatalogMatch(catalog, state); const mutationBlocked = locked || dirty || stateLoading || stateError !== null; const mutationReason = running ? "Close TF2 before changing the installed HUD." @@ -322,6 +331,27 @@ export function HudPane({ } /> + {modsImportHint ? ( + + That isn't a HUD + + It has no info.vdf, so nothing was imported. A mod is imported in Mods. + + + {onOpenMods ? ( + + ) : null} + {onDismissModsImportHint ? ( + + ) : null} + + + ) : null} +
- {state.inferred ? ( -

Match it to hud-db to enable updates.

+ {catalogMatch ? ( +

+ Match it to {hudDisplayName(catalogMatch)} in the catalog to get updates. +

) : null}
{state.updateAvailable ? ( @@ -387,16 +419,16 @@ export function HudPane({ {running ? "Close TF2 to update" : "Update HUD"} ) : null} - {state.inferred ? ( + {catalogMatch ? ( ) : null} + ) : null} ))} diff --git a/apps/desktop/src/ViewmodelPane.tsx b/apps/desktop/src/ViewmodelPane.tsx index 70add161..41f2ce7d 100644 --- a/apps/desktop/src/ViewmodelPane.tsx +++ b/apps/desktop/src/ViewmodelPane.tsx @@ -1,5 +1,6 @@ import { DownloadSimple, Trash } from "@phosphor-icons/react"; import { useState } from "react"; +import { Alert } from "./components/ui/Alert"; import { ClassTabs } from "./components/ui/ClassTabs"; import { PaneHeader } from "./components/ui/PaneHeader"; import { useAppStatus, useCanWrite } from "./hooks/useAppStatus"; @@ -24,6 +25,9 @@ export function ViewmodelPane({ onImport, onBuild, onRemove, + modsImportHint = null, + onOpenMods, + onDismissModsImportHint, }: { active: boolean; profileId: string | null; @@ -33,6 +37,10 @@ export function ViewmodelPane({ profilePreload: boolean | null; loadCatalog: () => Promise; onImport: (preload: boolean) => void; + /** Why the last VPK was refused for carrying more than viewmodels. */ + modsImportHint?: string | null; + onOpenMods?: () => void; + onDismissModsImportHint?: () => void; onBuild: (request: ViewmodelBuildRequest) => Promise; onRemove: () => void; }) { @@ -69,6 +77,25 @@ export function ViewmodelPane({ onRemovePack={onRemove} /> + {modsImportHint ? ( + + That pack has more than viewmodels + {modsImportHint} + + {onOpenMods ? ( + + ) : null} + {onDismissModsImportHint ? ( + + ) : null} + + + ) : null} +
{ }); describe("ModList", () => { + it("marks the pack another pane asked to show, or says it isn't a custom pack", async () => { + const render = (pack: string) => + root.render( + , + ); + await act(async () => render("Long-Mod.vpk")); + expect( + box.querySelector('[data-testid="mods-row-long-mod"]')?.getAttribute("data-focused"), + ).toBe("true"); + expect(box.querySelector('[data-testid="mods-row-other"]')?.hasAttribute("data-focused")).toBe( + false, + ); + expect(box.querySelector('[data-testid="mods-focus-missing"]')).toBeNull(); + await act(async () => render("execs-crosshairs")); + expect(box.querySelector('[data-testid="mods-focus-missing"]')?.textContent).toContain( + "tf/custom/execs-crosshairs", + ); + expect(box.querySelector("[data-focused]")).toBeNull(); + }); + it("toggles saved packs and protects selected particle sources", async () => { const onSetEnabled = vi.fn(); const render = (selected: string[], inactive = false) => diff --git a/apps/desktop/src/components/ModList.tsx b/apps/desktop/src/components/ModList.tsx index 6aa59adc..8e246392 100644 --- a/apps/desktop/src/components/ModList.tsx +++ b/apps/desktop/src/components/ModList.tsx @@ -1,8 +1,8 @@ import { ArrowSquareOut, Package } from "@phosphor-icons/react"; -import { useEffect, useState } from "react"; +import { useEffect, useRef, useState } from "react"; import type { ModRecord, ModUpdateStatus, ProfileSummary } from "../lib/bridge"; import { openExternal } from "../lib/bridge"; -import { formatModBytes, modDomId, modMetaLine, modSourceUrl } from "../lib/mods-ui"; +import { formatModBytes, modDomId, modMetaLine, modOwnsPack, modSourceUrl } from "../lib/mods-ui"; import { ModImport } from "./ModImport"; import { Modal } from "./ui/Modal"; import { PaneSection } from "./ui/PaneSection"; @@ -34,7 +34,10 @@ export function ModList({ checking = false, managementError, onCheckUpdates, + focus = null, }: { + /** A `tf/custom` pack to scroll to and mark; a new `key` repeats it. */ + focus?: { pack: string; key: number } | null; mods: ModRecord[]; /** TF2 is running or a write is in flight. */ locked: boolean; @@ -66,6 +69,13 @@ export function ModList({ setCopying(null); } }, [active]); + const focused = focus ? (mods.find((mod) => modOwnsPack(mod, focus.pack)) ?? null) : null; + const focusedRow = useRef(null); + const focusKey = focus?.key ?? 0; + // Scroll once per request, not on every list refresh. + useEffect(() => { + if (focusKey && active) focusedRow.current?.scrollIntoView?.({ block: "center" }); + }, [focusKey, active]); const copyMod = mods.find((mod) => mod.id === copying); // A status refresh may protect or remove a pack while its dialog is open. const current = confirming ? mods.find((mod) => mod.id === confirming.id) : undefined; @@ -114,6 +124,12 @@ export function ModList({

) : null} + {focus && !focused ? ( +

+ tf/custom/{focus.pack} isn't one of this profile's custom packs. +

+ ) : null} + {mods.length === 0 ? (