bitburner-src/src/Locations/ui/TechVendorLocation.tsx

113 lines
3.7 KiB
TypeScript
Raw Normal View History

/**
* React Subcomponent for displaying a location's UI, when that location is a tech vendor
*
* This subcomponent renders all of the buttons for purchasing things from tech vendors
*/
import * as React from "react";
import { Location } from "../Location";
import { createPurchaseServerPopup,
createUpgradeHomeCoresPopup,
createUpgradeHomeRamPopup,
purchaseTorRouter } from "../LocationsHelpers";
import { CONSTANTS } from "../../Constants";
import { IPlayer } from "../../PersonObjects/IPlayer";
import { getPurchaseServerCost } from "../../Server/ServerPurchases";
import { StdButtonPurchased } from "../../ui/React/StdButtonPurchased";
import { StdButton } from "../../ui/React/StdButton";
import { Money } from "../../ui/React/Money";
type IProps = {
loc: Location;
p: IPlayer;
}
export class TechVendorLocation extends React.Component<IProps, any> {
2019-04-04 02:08:11 +02:00
/**
* Stores button styling that sets them all to block display
*/
2021-05-01 09:17:31 +02:00
btnStyle: any;
2019-04-04 02:08:11 +02:00
constructor(props: IProps) {
super(props);
2019-04-04 02:08:11 +02:00
this.btnStyle = { display: "block" };
this.state = {
torPurchased: props.p.hasTorRouter(),
}
this.createUpgradeHomeCoresPopup = this.createUpgradeHomeCoresPopup.bind(this);
this.createUpgradeHomeRamPopup = this.createUpgradeHomeRamPopup.bind(this);
this.purchaseTorRouter = this.purchaseTorRouter.bind(this);
}
2021-05-01 09:17:31 +02:00
createUpgradeHomeCoresPopup(): void {
createUpgradeHomeCoresPopup(this.props.p);
}
2021-05-01 09:17:31 +02:00
createUpgradeHomeRamPopup(): void {
createUpgradeHomeRamPopup(this.props.p);
}
2021-05-01 09:17:31 +02:00
purchaseTorRouter(): void {
purchaseTorRouter(this.props.p);
this.setState({
torPurchased: this.props.p.hasTorRouter(),
});
}
2021-05-01 09:17:31 +02:00
render(): React.ReactNode {
const loc: Location = this.props.loc;
const purchaseServerButtons: React.ReactNode[] = [];
for (let i = loc.techVendorMinRam; i <= loc.techVendorMaxRam; i *= 2) {
const cost = getPurchaseServerCost(i);
purchaseServerButtons.push(
<StdButton
key={i}
onClick={() => createPurchaseServerPopup(i, this.props.p)}
2019-04-04 02:08:11 +02:00
style={this.btnStyle}
text={<>Purchase {i}GB Server - {Money(cost)}</>}
2021-04-30 05:52:56 +02:00
/>,
)
}
return (
<div>
{purchaseServerButtons}
<br />
<p><i>"You can order bigger servers via scripts. We don't take custom order in person."</i></p>
<br />
{
this.state.torPurchased ? (
<StdButtonPurchased
2019-04-04 02:08:11 +02:00
style={this.btnStyle}
text={"TOR Router - Purchased"}
/>
) : (
<StdButton
onClick={this.purchaseTorRouter}
2019-04-04 02:08:11 +02:00
style={this.btnStyle}
text={<>Purchase TOR Router - {Money(CONSTANTS.TorRouterCost)}</>}
/>
)
}
<StdButton
onClick={this.createUpgradeHomeRamPopup}
2019-04-04 02:08:11 +02:00
style={this.btnStyle}
text={`Purchase additional RAM for Home computer`}
/>
<StdButton
onClick={this.createUpgradeHomeCoresPopup}
2019-04-04 02:08:11 +02:00
style={this.btnStyle}
text={`Purchase additional Core for Home computer`}
/>
</div>
)
}
}