Skip to content
This repository was archived by the owner on Jul 23, 2023. It is now read-only.

Commit 73c0489

Browse files
authored
Add enable/disable all mods button (#184)
* Add enable/disable all mods button * Bump version
1 parent bf2a6b8 commit 73c0489

File tree

4 files changed

+74
-7
lines changed

4 files changed

+74
-7
lines changed

app/components/Mods/ModRowSection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const ModRowSection: React.FunctionComponent<Props> = ({
4343
className={highlighted ? styles.required : ''}
4444
>
4545
<Table className={styles.modsTable} size="small">
46-
<ModTableHead title={title} />
46+
<ModTableHead title={title} mods={mods} />
4747
<TableBody>
4848
{mods.map((mod: Mod) => (
4949
<ModTableRow

app/components/Mods/ModTableHead.tsx

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,81 @@
11
import React from 'react';
2-
import TableCell from '@material-ui/core/TableCell';
3-
import TableHead from '@material-ui/core/TableHead';
4-
import TableRow from '@material-ui/core/TableRow';
2+
import {
3+
TableCell,
4+
TableHead,
5+
TableRow,
6+
Tooltip,
7+
IconButton,
8+
Box,
9+
} from '@material-ui/core';
10+
import {
11+
CheckBox as CheckBoxIcon,
12+
IndeterminateCheckBox as CheckBoxIndeterminateIcon,
13+
CheckBoxOutlineBlank as CheckBoxBlankIcon,
14+
} from '@material-ui/icons';
15+
16+
import { isInstalled, setEnabled } from '../../services';
517

618
import { modsText } from '../../helpers/static-text';
719

820
type Props = {
921
title: string;
22+
mods: Mod[];
23+
};
24+
25+
const getEnableTooltip = (mods: Mod[]) => {
26+
if (mods.every((mod) => mod.isEnabled)) {
27+
return modsText.actions.disable;
28+
}
29+
if (mods.every((mod) => isInstalled(mod))) {
30+
return modsText.actions.enable;
31+
}
32+
return '';
33+
};
34+
35+
const getCheckboxIcon = (mods: Mod[]) => {
36+
if (mods.every((mod) => mod.isEnabled)) {
37+
return <CheckBoxIcon />;
38+
}
39+
if (mods.some((mod) => mod.isEnabled)) {
40+
return <CheckBoxIndeterminateIcon />;
41+
}
42+
return <CheckBoxBlankIcon />;
43+
};
44+
45+
const toggleAllMods = (mods: Mod[]) => {
46+
const enabled = !mods.every((mod) => mod.isEnabled);
47+
mods.forEach((mod) => {
48+
if (mod.isRequired) return;
49+
setEnabled(mod, enabled);
50+
});
1051
};
1152

12-
const ModTableHead: React.FunctionComponent<Props> = ({ title }) => (
53+
const ModTableHead: React.FunctionComponent<Props> = ({ title, mods }) => (
1354
<TableHead>
1455
<TableRow>
1556
<TableCell>{title}</TableCell>
1657
<TableCell width="100px">{modsText.tableHead.downloadCount}</TableCell>
1758
<TableCell width="110px" align="center">
1859
{modsText.tableHead.version}
1960
</TableCell>
20-
<TableCell width="180px" />
61+
<TableCell width="180px">
62+
<Box display="flex" justifyContent="space-between">
63+
<Tooltip title={getEnableTooltip(mods)}>
64+
<span>
65+
<IconButton
66+
size="small"
67+
disabled={
68+
mods.every((mod) => !isInstalled(mod)) ||
69+
mods.every((mod) => mod.isRequired)
70+
}
71+
onClick={() => toggleAllMods(mods)}
72+
>
73+
{getCheckboxIcon(mods)}
74+
</IconButton>
75+
</span>
76+
</Tooltip>
77+
</Box>
78+
</TableCell>
2179
</TableRow>
2280
</TableHead>
2381
);

app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ow-mod-manager",
33
"productName": "OuterWildsModManager",
4-
"version": "1.17.1",
4+
"version": "1.17.2",
55
"description": "Outer Wilds Mod Manager",
66
"main": "./main.prod.js",
77
"author": {

app/services/mods.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,12 @@ export async function toggleEnabled(mod: Mod) {
200200
config.enabled = !config.enabled;
201201
saveConfig(mod, config);
202202
}
203+
204+
export async function setEnabled(mod: Mod, enabled: boolean) {
205+
const config = getConfig(mod);
206+
if (!config || (config.enabled && !(await showPatcherWarning(mod)))) {
207+
return;
208+
}
209+
config.enabled = enabled;
210+
saveConfig(mod, config);
211+
}

0 commit comments

Comments
 (0)