mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-22 14:12:27 +01:00
UI: Allow filtering graftable augmentations (#1570)
This commit is contained in:
parent
dbeaef94a2
commit
440c074606
@ -4,8 +4,8 @@ import { Player } from "@player";
|
|||||||
import { AugmentationName } from "@enums";
|
import { AugmentationName } from "@enums";
|
||||||
|
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { CheckBox, CheckBoxOutlineBlank, Construction } from "@mui/icons-material";
|
import { CheckBox, CheckBoxOutlineBlank, Construction, Search } from "@mui/icons-material";
|
||||||
import { Box, Button, Container, List, ListItemButton, Paper, Typography } from "@mui/material";
|
import { Box, Button, Container, List, ListItemButton, Paper, TextField, Typography } from "@mui/material";
|
||||||
|
|
||||||
import { GraftingWork } from "../../../Work/GraftingWork";
|
import { GraftingWork } from "../../../Work/GraftingWork";
|
||||||
import { Augmentations } from "../../../Augmentation/Augmentations";
|
import { Augmentations } from "../../../Augmentation/Augmentations";
|
||||||
@ -66,17 +66,25 @@ export const GraftingRoot = (): React.ReactElement => {
|
|||||||
|
|
||||||
const [selectedAug, setSelectedAug] = useState(getGraftingAvailableAugs()[0]);
|
const [selectedAug, setSelectedAug] = useState(getGraftingAvailableAugs()[0]);
|
||||||
const [graftOpen, setGraftOpen] = useState(false);
|
const [graftOpen, setGraftOpen] = useState(false);
|
||||||
|
const [filterText, setFilterText] = useState("");
|
||||||
const selectedAugmentation = Augmentations[selectedAug];
|
const selectedAugmentation = Augmentations[selectedAug];
|
||||||
const rerender = useCycleRerender();
|
const rerender = useCycleRerender();
|
||||||
|
|
||||||
|
const matches = (s1: string, s2: string) => s1.toLowerCase().includes(s2.toLowerCase());
|
||||||
const getAugsSorted = (): AugmentationName[] => {
|
const getAugsSorted = (): AugmentationName[] => {
|
||||||
const augs = getGraftingAvailableAugs();
|
const augs = getGraftingAvailableAugs();
|
||||||
switch (Settings.PurchaseAugmentationsOrder) {
|
if (Settings.PurchaseAugmentationsOrder === PurchaseAugmentationsOrderSetting.Cost) {
|
||||||
case PurchaseAugmentationsOrderSetting.Cost:
|
augs.sort((a, b) => graftableAugmentations[a].cost - graftableAugmentations[b].cost);
|
||||||
return augs.sort((a, b) => graftableAugmentations[a].cost - graftableAugmentations[b].cost);
|
|
||||||
default:
|
|
||||||
return augs;
|
|
||||||
}
|
}
|
||||||
|
if (filterText !== "") {
|
||||||
|
return augs.filter(
|
||||||
|
(aug: AugmentationName) =>
|
||||||
|
matches(Augmentations[aug].name, filterText) ||
|
||||||
|
matches(Augmentations[aug].info, filterText) ||
|
||||||
|
matches(Augmentations[aug].stats, filterText),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return augs;
|
||||||
};
|
};
|
||||||
|
|
||||||
const switchSortOrder = (newOrder: PurchaseAugmentationsOrderSetting): void => {
|
const switchSortOrder = (newOrder: PurchaseAugmentationsOrderSetting): void => {
|
||||||
@ -114,19 +122,29 @@ export const GraftingRoot = (): React.ReactElement => {
|
|||||||
</Paper>
|
</Paper>
|
||||||
{getGraftingAvailableAugs().length > 0 ? (
|
{getGraftingAvailableAugs().length > 0 ? (
|
||||||
<Paper sx={{ mb: 1, width: "fit-content", display: "grid", gridTemplateColumns: "1fr 3fr" }}>
|
<Paper sx={{ mb: 1, width: "fit-content", display: "grid", gridTemplateColumns: "1fr 3fr" }}>
|
||||||
<List sx={{ height: 400, overflowY: "scroll", borderRight: `1px solid ${Settings.theme.welllight}` }}>
|
<Box>
|
||||||
{getAugsSorted().map((k, i) => (
|
<TextField
|
||||||
<ListItemButton key={i + 1} onClick={() => setSelectedAug(k)} selected={selectedAug === k}>
|
style={{ width: "100%" }}
|
||||||
<Typography
|
value={filterText}
|
||||||
sx={{
|
onChange={(e) => {
|
||||||
color: canGraft(graftableAugmentations[k]) ? Settings.theme.primary : Settings.theme.disabled,
|
setFilterText(e.target.value);
|
||||||
}}
|
}}
|
||||||
>
|
InputProps={{ startAdornment: <Search /> }}
|
||||||
{k}
|
/>
|
||||||
</Typography>
|
<List sx={{ height: 400, overflowY: "scroll", borderRight: `1px solid ${Settings.theme.welllight}` }}>
|
||||||
</ListItemButton>
|
{getAugsSorted().map((k, i) => (
|
||||||
))}
|
<ListItemButton key={i + 1} onClick={() => setSelectedAug(k)} selected={selectedAug === k}>
|
||||||
</List>
|
<Typography
|
||||||
|
sx={{
|
||||||
|
color: canGraft(graftableAugmentations[k]) ? Settings.theme.primary : Settings.theme.disabled,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{k}
|
||||||
|
</Typography>
|
||||||
|
</ListItemButton>
|
||||||
|
))}
|
||||||
|
</List>
|
||||||
|
</Box>
|
||||||
<Box sx={{ m: 1 }}>
|
<Box sx={{ m: 1 }}>
|
||||||
<Typography variant="h6" sx={{ display: "flex", alignItems: "center", flexWrap: "wrap" }}>
|
<Typography variant="h6" sx={{ display: "flex", alignItems: "center", flexWrap: "wrap" }}>
|
||||||
<Construction sx={{ mr: 1 }} /> {selectedAug}
|
<Construction sx={{ mr: 1 }} /> {selectedAug}
|
||||||
|
Loading…
Reference in New Issue
Block a user