From 9d0a63734d0c949764d31127f44030f3eca3124b Mon Sep 17 00:00:00 2001 From: Martin Fournier Date: Tue, 11 Jan 2022 19:22:55 -0500 Subject: [PATCH] Add details to work in overview Add a reusable component for the focus section, add a bit of details & some styling. --- src/ui/React/CharacterOverview.tsx | 206 ++++++++++++++++------------- 1 file changed, 113 insertions(+), 93 deletions(-) diff --git a/src/ui/React/CharacterOverview.tsx b/src/ui/React/CharacterOverview.tsx index e9edf79ff..50010bb07 100644 --- a/src/ui/React/CharacterOverview.tsx +++ b/src/ui/React/CharacterOverview.tsx @@ -17,7 +17,7 @@ import Typography from "@mui/material/Typography"; import Button from "@mui/material/Button"; import IconButton from "@mui/material/IconButton"; import SaveIcon from "@mui/icons-material/Save"; -import ArrowBackIcon from '@mui/icons-material/ArrowBack'; +import ArrowBackIcon from "@mui/icons-material/ArrowBack"; import ClearAllIcon from "@mui/icons-material/ClearAll"; import { Settings } from "../../Settings/Settings"; @@ -26,6 +26,7 @@ import { StatsProgressOverviewCell } from "./StatsProgressBar"; import { BitNodeMultipliers } from "../../BitNode/BitNodeMultipliers"; import { IRouter, Page } from "../Router"; import { Box, Tooltip } from "@mui/material"; +import { CONSTANTS } from "../../Constants"; interface IProps { save: () => void; @@ -80,101 +81,39 @@ function Bladeburner(): React.ReactElement { ); } -function Work(): React.ReactElement { - const player = use.Player(); - const router = use.Router(); +interface WorkInProgressOverviewProps { + tooltip: React.ReactNode; + header: React.ReactNode; + children: React.ReactNode; + onClickFocus: () => void; +} + +function WorkInProgressOverview({ + tooltip, + children, + onClickFocus, + header, +}: WorkInProgressOverviewProps): React.ReactElement { const classes = useStyles(); - if (!player.isWorking || player.focus) return <>; - - if (player.className !== "") { - return ( - <> - - - - Work in progress: - - - - - - {convertTimeMsToTimeElapsedString(player.timeWorked)} - - - - - - - - - ); - } - - if (player.createProgramName !== "") { - return ( - <> - - - - Work in progress: - - - - - - - {player.createProgramName}{" "} - {((player.timeWorkedCreateProgram / player.timeNeededToCompleteWork) * 100).toFixed(2)}% - - - - - - - - - - ); - } - return ( <> - - - Work in progress: + + {tooltip}}> + + {header} + - - - + rep - + + {children} - @@ -183,8 +122,91 @@ function Work(): React.ReactElement { ); } +function Work(): React.ReactElement { + const player = use.Player(); + const router = use.Router(); + const onClickFocus = (): void => { + player.startFocusing(); + router.toWork(); + }; + + if (!player.isWorking || player.focus) return <>; + + let details = <>; + let header = <>; + let innerText = <>; + if (player.workType === CONSTANTS.WorkTypeCompanyPartTime || player.workType === CONSTANTS.WorkTypeCompany) { + details = ( + <> + {player.jobs[player.companyName]} at {player.companyName} + + ); + header = ( + <> + Working at {player.companyName} + + ); + innerText = ( + <> + + rep + + ); + } else if (player.workType === CONSTANTS.WorkTypeFaction) { + details = ( + <> + {player.factionWorkType} for {player.currentWorkFactionName} + + ); + header = ( + <> + Working for {player.currentWorkFactionName} + + ); + innerText = ( + <> + + rep + + ); + } else if (player.workType === CONSTANTS.WorkTypeStudyClass) { + details = <>{player.workType}; + header = <>You are {player.className}; + innerText = <>{convertTimeMsToTimeElapsedString(player.timeWorked)}; + } else if (player.workType === CONSTANTS.WorkTypeCreateProgram) { + details = <>Coding {player.createProgramName}; + header = <>Creating a program; + innerText = ( + <> + {player.createProgramName}{" "} + {((player.timeWorkedCreateProgram / player.timeNeededToCompleteWork) * 100).toFixed(2)}% + + ); + } + + return ( + + {innerText} + + ); +} + const useStyles = makeStyles((theme: Theme) => createStyles({ + workCell: { + textAlign: "center", + maxWidth: "200px", + borderBottom: "none", + padding: 0, + margin: 0, + }, + + workHeader: { + fontSize: "0.9rem", + }, + + workSubtitles: { + fontSize: "0.8rem", + }, + cellNone: { borderBottom: "none", padding: 0, @@ -256,8 +278,8 @@ export function CharacterOverview({ save, killScripts, router, allowBackButton } player.charisma_mult * BitNodeMultipliers.CharismaLevelMultiplier, ); - const previousPageName = router.previousPage() < 0 - ? '' : Page[router.previousPage() ?? 0].replace(/([a-z])([A-Z])/g, '$1 $2'); + const previousPageName = + router.previousPage() < 0 ? "" : Page[router.previousPage() ?? 0].replace(/([a-z])([A-Z])/g, "$1 $2"); return ( <> @@ -435,24 +457,22 @@ export function CharacterOverview({ save, killScripts, router, allowBackButton } - - + + {allowBackButton && ( - router.toPreviousPage()}> - + router.toPreviousPage()}> + )} - + setKillOpen(true)}>