Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions apps/desktop/src-tauri/core/src/hud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,12 +725,14 @@ fn finish_extracted(raw: Vec<(String, Vec<u8>)>) -> Result<ExtractedHud, Profile
})
}

/// The refusal for an archive or folder with no `info.vdf`: not a HUD at all,
/// which is how an ordinary mod picked in the HUD pane ends up.
pub const NO_HUD_FOUND: &str = "No HUD folder was found (missing info.vdf). Choose a complete HUD download or its extracted HUD folder.";

fn validate_hud_info(tree: &HudTree) -> 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!(
Expand Down
5 changes: 4 additions & 1 deletion apps/desktop/src-tauri/core/src/viewmodel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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") {
Expand Down
12 changes: 12 additions & 0 deletions apps/desktop/src-tauri/src/commands/hud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
Expand Down Expand Up @@ -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!(
Expand Down
21 changes: 15 additions & 6 deletions apps/desktop/src-tauri/src/commands/viewmodel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down
11 changes: 8 additions & 3 deletions apps/desktop/src/CrosshairPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ export function CrosshairPane({
onDeactivate?: (stock?: { file: string; scale: number }) => Promise<unknown>;
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;
Expand Down Expand Up @@ -559,8 +560,12 @@ export function CrosshairPane({
different art.
</p>
{onOpenMods ? (
<button type="button" className="btn btn-ghost mt-2" onClick={onOpenMods}>
Open installed mods
<button
type="button"
className="btn btn-ghost mt-2"
onClick={() => onOpenMods(stockArtConflict.pack)}
>
Show in Mods
</button>
) : null}
</div>
Expand Down
42 changes: 37 additions & 5 deletions apps/desktop/src/HudPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
HUD_SORTS,
hudAuthorCopy,
hudCatalogControls,
hudCatalogMatch,
hudDisplayName,
hudInstallSourceCopy,
hudOptionsDirty,
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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."
Expand Down Expand Up @@ -322,6 +331,27 @@ export function HudPane({
}
/>

{modsImportHint ? (
<Alert tone="warn" testId="hud-import-not-a-hud" className="mb-4">
<span className="block font-medium">That isn't a HUD</span>
<span className="mt-1 block">
It has no info.vdf, so nothing was imported. A mod is imported in Mods.
</span>
<span className="mt-3 flex flex-wrap gap-2">
{onOpenMods ? (
<button type="button" className="btn btn-ghost" onClick={onOpenMods}>
Open Mods
</button>
) : null}
{onDismissModsImportHint ? (
<button type="button" className="btn btn-quiet" onClick={onDismissModsImportHint}>
Dismiss
</button>
) : null}
</span>
</Alert>
) : null}

<div className="pane-views">
<ClassTabs
label="HUD workspace"
Expand Down Expand Up @@ -371,8 +401,10 @@ export function HudPane({
{installedEntry ? `${hudAuthorCopy(installedEntry)} · ` : ""}
{installedLabel}
</p>
{state.inferred ? (
<p className="t-meta mt-3">Match it to hud-db to enable updates.</p>
{catalogMatch ? (
<p className="t-meta mt-3">
Match it to {hudDisplayName(catalogMatch)} in the catalog to get updates.
</p>
) : null}
<div className="mt-3 flex flex-wrap gap-2">
{state.updateAvailable ? (
Expand All @@ -387,16 +419,16 @@ export function HudPane({
{running ? "Close TF2 to update" : "Update HUD"}
</button>
) : null}
{state.inferred ? (
{catalogMatch ? (
<button
type="button"
data-testid="hud-match"
disabled={mutationBlocked}
title={mutationReason}
onClick={() => onMatch(installedId)}
onClick={() => onMatch(catalogMatch.id)}
className="btn btn-ghost"
>
Match to catalog…
Match to catalog
</button>
) : null}
<button
Expand Down
18 changes: 17 additions & 1 deletion apps/desktop/src/ModsPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ export type ModsPaneProps = {
hudImportRequired?: string | null;
onReviewHudImport?: () => void;
onDismissHudImport?: () => void;
/** A pack another pane asked to show; a new `key` opens Custom packs on it. */
packFocus?: { pack: string; key: number } | null;
/** Navigate from Viewmodels directly to the shared Casual preload control. */
casualOpenRequest?: number;
};
Expand Down Expand Up @@ -147,6 +149,7 @@ export function ModsPane({
hudImportRequired,
onReviewHudImport,
onDismissHudImport,
packFocus = null,
casualOpenRequest,
}: ModsPaneProps) {
const { running, busy } = useAppStatus();
Expand Down Expand Up @@ -220,6 +223,15 @@ export function ModsPane({
useEffect(() => {
if (casualOpenRequest) setTask("casual");
}, [casualOpenRequest]);
// The highlight lasts until the player picks another task themselves.
const [focusedPack, setFocusedPack] = useState<{ pack: string; key: number } | null>(null);
const packFocusKey = packFocus?.key ?? 0;
// biome-ignore lint/correctness/useExhaustiveDependencies: only a new request, not a re-render with the same one, opens Custom packs.
useEffect(() => {
if (!packFocus) return;
setFocusedPack(packFocus);
setTask("installed");
}, [packFocusKey]);
const [confirmRestore, setConfirmRestore] = useState(false);
// Steam's verify runs outside the app; while it does, poll the status and,
// once every stale file reads as stock again, put the selection back.
Expand Down Expand Up @@ -369,7 +381,10 @@ export function ModsPane({
label="Mod tasks"
idPrefix="mods-task"
panelId="mods-task-panel"
onSelect={setTask}
onSelect={(next) => {
setFocusedPack(null);
setTask(next);
}}
/>
{task !== "casual" && hasRepair ? (
<button
Expand Down Expand Up @@ -555,6 +570,7 @@ export function ModsPane({
<ModList
key={profileId}
first
focus={focusedPack}
active={active && task === "installed"}
showImport={false}
mods={mods}
Expand Down
22 changes: 22 additions & 0 deletions apps/desktop/src/SettingsHost.hud-loading.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ let container: HTMLDivElement;
let refreshKey: number;
let running: boolean;
let onPendingChange: ReturnType<typeof vi.fn<(pending: boolean) => void>>;
let onNavigate: ReturnType<typeof vi.fn<(tab: string) => void>>;
function makeApi() {
return {
getFilesContext: vi.fn(async () => ({ profileId, root: "fixture", layer: "vanilla" })),
Expand Down Expand Up @@ -104,6 +105,7 @@ async function render() {
onBindSyncHandled={() => {}}
onBusyChange={() => {}}
onPendingChange={onPendingChange}
onNavigate={onNavigate}
onError={() => {}}
/>
</AppStatusProvider>
Expand Down Expand Up @@ -131,6 +133,7 @@ beforeEach(() => {
refreshKey = 1;
api = makeApi();
onPendingChange = vi.fn();
onNavigate = vi.fn();
});
afterEach(async () => {
await act(async () => root.unmount());
Expand Down Expand Up @@ -322,6 +325,25 @@ describe("HUD loading through the real settings host and pane", () => {
expect(element("toast").getAttribute("data-kind")).toBe("saved");
});

it("points an import that is not a HUD to Mods instead of a bare failure", async () => {
await render();
api.importHudArchive.mockRejectedValueOnce({
code: "NotAHud",
message: "No HUD folder was found (missing info.vdf).",
});
await click("hud-import");
await click("hud-import-archive");
const hint = element("hud-import-not-a-hud");
expect(hint.textContent).toContain("That isn't a HUD");
expect(container.querySelector('[data-testid="toast"][data-kind="error"]')).toBeNull();
const open = Array.from(hint.querySelectorAll("button")).find(
(button) => button.textContent === "Open Mods",
);
await act(async () => open?.click());
expect(onNavigate).toHaveBeenCalledWith("mods");
expect(container.querySelector('[data-testid="hud-import-not-a-hud"]')).toBeNull();
});

it("retains a same-HUD dirty draft through schema failure and retry without saving unavailable controls", async () => {
vi.useFakeTimers();
running = true;
Expand Down
Loading
Loading