bitburner-src/src/Bladeburner/ui/TeamSizeModal.tsx

50 lines
1.7 KiB
TypeScript
Raw Normal View History

2021-08-16 03:49:08 +02:00
import React, { useState } from "react";
2021-09-25 20:42:57 +02:00
import { dialogBoxCreate } from "../../ui/React/DialogBox";
2021-09-27 23:09:48 +02:00
import { Modal } from "../../ui/React/Modal";
2021-08-16 03:49:08 +02:00
import { Action } from "../Action";
import { IBladeburner } from "../IBladeburner";
2021-09-27 23:09:48 +02:00
import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button";
import TextField from "@mui/material/TextField";
2021-08-16 03:49:08 +02:00
interface IProps {
2021-09-05 01:09:30 +02:00
bladeburner: IBladeburner;
action: Action;
2021-09-27 23:09:48 +02:00
open: boolean;
onClose: () => void;
2021-08-16 03:49:08 +02:00
}
2021-09-27 23:09:48 +02:00
export function TeamSizeModal(props: IProps): React.ReactElement {
2021-09-05 01:09:30 +02:00
const [teamSize, setTeamSize] = useState<number | undefined>();
function confirmTeamSize(): void {
if (teamSize === undefined) return;
const num = Math.round(teamSize);
if (isNaN(num) || num < 0) {
2021-09-09 05:47:34 +02:00
dialogBoxCreate("Invalid value entered for number of Team Members (must be numeric, positive)");
2021-09-05 01:09:30 +02:00
} else {
props.action.teamCount = num;
2021-08-16 03:49:08 +02:00
}
2021-09-27 23:09:48 +02:00
props.onClose();
}
function onTeamSize(event: React.ChangeEvent<HTMLInputElement>): void {
const x = parseFloat(event.target.value);
if (x > props.bladeburner.teamSize) setTeamSize(props.bladeburner.teamSize);
else setTeamSize(x);
2021-09-05 01:09:30 +02:00
}
2021-08-16 03:49:08 +02:00
2021-09-05 01:09:30 +02:00
return (
2021-09-27 23:09:48 +02:00
<Modal open={props.open} onClose={props.onClose}>
<Typography>
2021-09-09 05:47:34 +02:00
Enter the amount of team members you would like to take on this Op. If you do not have the specified number of
team members, then as many as possible will be used. Note that team members may be lost during operations.
2021-09-27 23:09:48 +02:00
</Typography>
2021-09-29 07:49:22 +02:00
<TextField autoFocus type="number" placeholder="Team size" value={teamSize} onChange={onTeamSize} />
2021-09-27 23:09:48 +02:00
<Button sx={{ mx: 2 }} onClick={confirmTeamSize}>
2021-09-05 01:09:30 +02:00
Confirm
2021-09-27 23:09:48 +02:00
</Button>
</Modal>
2021-09-05 01:09:30 +02:00
);
}