Add confirmation modal to crafting

This commit is contained in:
nickofolas 2022-03-21 14:54:39 -05:00
parent 16fa4c8d7f
commit d6e0180116

@ -5,6 +5,7 @@ import { Construction } from "@mui/icons-material";
import { use } from "../../../ui/Context"; import { use } from "../../../ui/Context";
import { Money } from "../../../ui/React/Money"; import { Money } from "../../../ui/React/Money";
import { ConfirmationModal } from "../../../ui/React/ConfirmationModal";
import { Augmentations } from "../../../Augmentation/Augmentations"; import { Augmentations } from "../../../Augmentation/Augmentations";
import { AugmentationNames } from "../../../Augmentation/data/AugmentationNames"; import { AugmentationNames } from "../../../Augmentation/data/AugmentationNames";
import { Settings } from "../../../Settings/Settings"; import { Settings } from "../../../Settings/Settings";
@ -43,6 +44,7 @@ export const GraftingRoot = (): React.ReactElement => {
} }
const [selectedAug, setSelectedAug] = useState(getAvailableAugs(player)[0]); const [selectedAug, setSelectedAug] = useState(getAvailableAugs(player)[0]);
const [craftOpen, setCraftOpen] = useState(false);
return ( return (
<Container disableGutters maxWidth="lg" sx={{ mx: 0 }}> <Container disableGutters maxWidth="lg" sx={{ mx: 0 }}>
@ -75,14 +77,7 @@ export const GraftingRoot = (): React.ReactElement => {
<Construction sx={{ mr: 1 }} /> {selectedAug} <Construction sx={{ mr: 1 }} /> {selectedAug}
</Typography> </Typography>
<Button <Button
onClick={(event) => { onClick={() => setCraftOpen(true)}
if (!event.isTrusted) return;
const craftableAug = CraftableAugmentations[selectedAug];
player.loseMoney(craftableAug.cost, "augmentations");
player.startCraftAugmentationWork(selectedAug, craftableAug.time);
player.startFocusing();
router.toWork();
}}
sx={{ width: "100%" }} sx={{ width: "100%" }}
disabled={player.money < CraftableAugmentations[selectedAug].cost} disabled={player.money < CraftableAugmentations[selectedAug].cost}
> >
@ -92,6 +87,26 @@ export const GraftingRoot = (): React.ReactElement => {
</Typography> </Typography>
) )
</Button> </Button>
<ConfirmationModal
open={craftOpen}
onClose={() => setCraftOpen(false)}
onConfirm={() => {
const craftableAug = CraftableAugmentations[selectedAug];
player.loseMoney(craftableAug.cost, "augmentations");
player.startCraftAugmentationWork(selectedAug, craftableAug.time);
player.startFocusing();
router.toWork();
}}
confirmationText={
<>
Cancelling crafting will <b>not</b> save crafting progress, and the money you spend will <b>not</b> be
returned.
<br />
<br />
Additionally, grafting an Augmentation will increase the potency of the Entropy virus.
</>
}
/>
<Typography color={Settings.theme.info}> <Typography color={Settings.theme.info}>
<b>Time to Craft:</b> {convertTimeMsToTimeElapsedString(CraftableAugmentations[selectedAug].time)} <b>Time to Craft:</b> {convertTimeMsToTimeElapsedString(CraftableAugmentations[selectedAug].time)}
</Typography> </Typography>