Skip to content

Commit

Permalink
CORPORATION: remove TA modals and integrate into sell modal (#796)
Browse files Browse the repository at this point in the history
  • Loading branch information
Caldwell-74 authored Sep 12, 2023
1 parent 99e5c5e commit b6eafce
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 197 deletions.
20 changes: 6 additions & 14 deletions src/Corporation/ui/MaterialElem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { CityName, CorpUnlockName } from "@enums";
import { Material } from "../Material";
import { Warehouse } from "../Warehouse";
import { ExportModal } from "./modals/ExportModal";
import { MaterialMarketTaModal } from "./modals/MaterialMarketTaModal";
import { SellMaterialModal } from "./modals/SellMaterialModal";
import { PurchaseMaterialModal } from "./modals/PurchaseMaterialModal";
import { formatBigNumber, formatCorpStat, formatMoney, formatQuality } from "../../ui/formatNumber";
Expand All @@ -29,7 +28,6 @@ export function MaterialElem(props: IMaterialProps): React.ReactElement {
const [purchaseMaterialOpen, setPurchaseMaterialOpen] = useState(false);
const [exportOpen, setExportOpen] = useState(false);
const [sellMaterialOpen, setSellMaterialOpen] = useState(false);
const [materialMarketTaOpen, setMaterialMarketTaOpen] = useState(false);
const [limitProductionOpen, setLimitProductionOpen] = useState(false);

const warehouse = props.warehouse;
Expand Down Expand Up @@ -159,18 +157,12 @@ export function MaterialElem(props: IMaterialProps): React.ReactElement {
>
{sellButtonText}
</Button>
<SellMaterialModal mat={mat} open={sellMaterialOpen} onClose={() => setSellMaterialOpen(false)} />
{division.hasResearch("Market-TA.I") && (
<>
<Button onClick={() => setMaterialMarketTaOpen(true)}>Market-TA</Button>

<MaterialMarketTaModal
mat={mat}
open={materialMarketTaOpen}
onClose={() => setMaterialMarketTaOpen(false)}
/>
</>
)}
<SellMaterialModal
mat={mat}
div={division}
open={sellMaterialOpen}
onClose={() => setSellMaterialOpen(false)}
/>
<Button color={tutorial ? "error" : "primary"} onClick={() => setLimitProductionOpen(true)}>
{limitMaterialButtonText}
</Button>
Expand Down
16 changes: 7 additions & 9 deletions src/Corporation/ui/ProductElem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Product } from "../Product";
import { DiscontinueProductModal } from "./modals/DiscontinueProductModal";
import { LimitProductProductionModal } from "./modals/LimitProductProductionModal";
import { SellProductModal } from "./modals/SellProductModal";
import { ProductMarketTaModal } from "./modals/ProductMarketTaModal";
import { CancelProductModal } from "./modals/CancelProductModal";

import { formatBigNumber, formatMoney, formatPercent } from "../../ui/formatNumber";
Expand All @@ -29,7 +28,6 @@ export function ProductElem(props: IProductProps): React.ReactElement {
const [limitOpen, setLimitOpen] = useState(false);
const [discontinueOpen, setDiscontinueOpen] = useState(false);
const [cancelOpen, setCancelOpen] = useState(false);
const [marketTaOpen, setMarketTaOpen] = useState(false);
const city = props.city;
const product = props.product;

Expand Down Expand Up @@ -166,7 +164,13 @@ export function ProductElem(props: IProductProps): React.ReactElement {
{(hasUpgradeDashboard || product.finished) && (
<>
<Button onClick={() => setSellOpen(true)}>{sellButtonText}</Button>
<SellProductModal product={product} city={city} open={sellOpen} onClose={() => setSellOpen(false)} />
<SellProductModal
product={product}
div={division}
city={city}
open={sellOpen}
onClose={() => setSellOpen(false)}
/>
<br />
<Button onClick={() => setLimitOpen(true)}>{limitProductionButtonText}</Button>
<LimitProductProductionModal
Expand All @@ -175,12 +179,6 @@ export function ProductElem(props: IProductProps): React.ReactElement {
open={limitOpen}
onClose={() => setLimitOpen(false)}
/>
{division.hasResearch("Market-TA.I") && (
<>
<Button onClick={() => setMarketTaOpen(true)}>Market-TA</Button>
<ProductMarketTaModal product={product} open={marketTaOpen} onClose={() => setMarketTaOpen(false)} />
</>
)}
</>
)}
</Paper>
Expand Down
84 changes: 0 additions & 84 deletions src/Corporation/ui/modals/MaterialMarketTaModal.tsx

This file was deleted.

86 changes: 0 additions & 86 deletions src/Corporation/ui/modals/ProductMarketTaModal.tsx

This file was deleted.

51 changes: 48 additions & 3 deletions src/Corporation/ui/modals/SellMaterialModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { dialogBoxCreate } from "../../../ui/React/DialogBox";
import { Material } from "../../Material";
import { SellMaterial } from "../../Actions";
import { Modal } from "../../../ui/React/Modal";
import Typography from "@mui/material/Typography";
import TextField from "@mui/material/TextField";
import Button from "@mui/material/Button";
import { KEY } from "../../../utils/helpers/keyCodes";

import { Typography, FormControlLabel, Switch, Tooltip } from "@mui/material";
import { Division } from "src/Corporation/Division";
function initialPrice(mat: Material): string {
let val = mat.desiredSellPrice ? mat.desiredSellPrice + "" : "";
if (mat.marketTa2) {
Expand All @@ -22,6 +22,7 @@ interface IProps {
open: boolean;
onClose: () => void;
mat: Material;
div: Division;
}

// Create a popup that let the player manage sales of a material
Expand Down Expand Up @@ -83,7 +84,51 @@ export function SellMaterialModal(props: IProps): React.ReactElement {
onKeyDown={onKeyDown}
/>
<TextField value={price} type="text" placeholder="Sell price" onChange={onPriceChange} onKeyDown={onKeyDown} />
<Button onClick={sellMaterial}>Confirm</Button>
<Button onClick={sellMaterial} style={{ marginLeft: ".5rem", marginRight: ".5rem" }}>
Confirm
</Button>
{props.div.hasResearch("Market-TA.I") && (
<FormControlLabel
style={{ marginRight: "1rem" }}
control={
<Switch checked={props.mat.marketTa1} onChange={(event) => (props.mat.marketTa1 = event.target.checked)} />
}
label={
<Tooltip
title={
<Typography>
If this is enabled, then this Material will automatically be sold at market price + markup.
<br />
This overrides player set pricing and gets overriden by an active TA2.
</Typography>
}
>
<Typography>Market-TA.I</Typography>
</Tooltip>
}
/>
)}
{props.div.hasResearch("Market-TA.II") && (
<FormControlLabel
control={
<Switch checked={props.mat.marketTa2} onChange={(event) => (props.mat.marketTa2 = event.target.checked)} />
}
label={
<Tooltip
title={
<Typography>
If this is enabled, then this Material will automatically be sold at the optimal price such that the
amount sold matches the amount specified.
<br />
This overrides player set pricing and TA1.
</Typography>
}
>
<Typography>Market-TA.II</Typography>
</Tooltip>
}
/>
)}
</Modal>
);
}
Loading

0 comments on commit b6eafce

Please sign in to comment.