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

47 lines
1.9 KiB
TypeScript
Raw Normal View History

2021-06-18 09:38:17 +02:00
import React, { useState } from "react";
import { ActionTypes } from "../data/ActionTypes";
import { createProgressBarText } from "../../../utils/helpers/createProgressBarText";
2021-08-19 07:45:26 +02:00
import { formatNumber } from "../../../utils/StringHelperFunctions";
import { IBladeburner } from "../IBladeburner";
2021-08-16 07:35:05 +02:00
import { IPlayer } from "../../PersonObjects/IPlayer";
2021-06-18 09:38:17 +02:00
interface IProps {
bladeburner: IBladeburner;
2021-08-16 07:35:05 +02:00
player: IPlayer;
2021-06-18 09:38:17 +02:00
action: any;
}
export function GeneralActionElem(props: IProps): React.ReactElement {
const setRerender = useState(false)[1];
const isActive = props.action.name === props.bladeburner.action.name;
const computedActionTimeCurrent = Math.min(props.bladeburner.actionTimeCurrent+props.bladeburner.actionTimeOverflow, props.bladeburner.actionTimeToComplete);
2021-08-19 07:45:26 +02:00
function onStart(): void {
2021-06-18 09:38:17 +02:00
props.bladeburner.action.type = ActionTypes[(props.action.name as string)];
props.bladeburner.action.name = props.action.name;
props.bladeburner.startAction(props.player, props.bladeburner.action);
2021-06-18 09:38:17 +02:00
setRerender(old => !old);
}
return (<>
<h2 style={{display: 'inline-block'}}>
{isActive ?
<>{props.action.name} (IN PROGRESS - {formatNumber(computedActionTimeCurrent, 0)} / {formatNumber(props.bladeburner.actionTimeToComplete, 0)})</> :
<>{props.action.name}</>
}
</h2>
{isActive ?
<p style={{display: 'block'}}>{createProgressBarText({progress:computedActionTimeCurrent / props.bladeburner.actionTimeToComplete})}</p> :
<>
<a
onClick={onStart}
className="a-link-button"
style={{margin:"3px", padding:"3px"}}>
Start
</a>
</>}
<br />
<br />
<pre style={{display: 'inline-block'}} dangerouslySetInnerHTML={{__html: props.action.desc}}></pre>
</>);
}